Skip to content

Commit 28d09a0

Browse files
committed
feat: add brc2.0
fix fix fix fix
1 parent 5765afc commit 28d09a0

File tree

8 files changed

+194
-31
lines changed

8 files changed

+194
-31
lines changed

src/background/controller/wallet.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2867,5 +2867,18 @@ export class WalletController extends BaseController {
28672867
getBRC20RecentHistory(address: string, ticker: string): Promise<BRC20HistoryItem[]> {
28682868
return openapiService.getBRC20RecentHistory(address, ticker);
28692869
}
2870+
2871+
getBRC20ProgList = async (address: string, currentPage: number, pageSize: number) => {
2872+
const cursor = (currentPage - 1) * pageSize;
2873+
const size = pageSize;
2874+
const { total, list } = await openapiService.getBRC20ProgList(address, cursor, size);
2875+
2876+
return {
2877+
currentPage,
2878+
pageSize,
2879+
total,
2880+
list
2881+
};
2882+
};
28702883
}
28712884
export default new WalletController();

src/background/service/openapi.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,14 @@ export class OpenApiService {
967967
feeRate
968968
});
969969
}
970+
971+
async getBRC20ProgList(
972+
address: string,
973+
cursor: number,
974+
size: number
975+
): Promise<{ list: TokenBalance[]; total: number }> {
976+
return this.httpGet('/v5/brc20-prog/list', { address, cursor, size, type: 5 });
977+
}
970978
}
971979

972980
export default new OpenApiService();

src/shared/constant/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ export type TypeChain = {
247247
showPrice: boolean;
248248
defaultExplorer: 'mempool-space' | 'unisat-explorer';
249249
enableBrc20SingleStep?: boolean;
250+
enableBrc20Prog?: boolean;
250251
};
251252

252253
export const CHAINS_MAP: { [key: string]: TypeChain } = {
@@ -264,7 +265,8 @@ export const CHAINS_MAP: { [key: string]: TypeChain } = {
264265
unisatExplorerUrl: 'https://uniscan.cc',
265266
okxExplorerUrl: '',
266267
showPrice: true,
267-
defaultExplorer: 'unisat-explorer'
268+
defaultExplorer: 'unisat-explorer',
269+
enableBrc20Prog: true
268270
},
269271
[ChainType.BITCOIN_TESTNET]: {
270272
enum: ChainType.BITCOIN_TESTNET,
@@ -312,7 +314,8 @@ export const CHAINS_MAP: { [key: string]: TypeChain } = {
312314
unisatExplorerUrl: 'https://uniscan.cc/signet',
313315
okxExplorerUrl: '',
314316
showPrice: false,
315-
defaultExplorer: 'unisat-explorer'
317+
defaultExplorer: 'unisat-explorer',
318+
enableBrc20Prog: true
316319
},
317320
[ChainType.FRACTAL_BITCOIN_MAINNET]: {
318321
enum: ChainType.FRACTAL_BITCOIN_MAINNET,

src/shared/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ export interface AddressSummary {
442442
atomicalsCount: number;
443443
brc20Count: number;
444444
brc20Count5Byte: number;
445+
brc20Count6Byte: number;
445446
arc20Count: number;
446447
runesCount: number;
447448
loading?: boolean;

src/ui/pages/BRC20/BRC20TokenScreen.tsx

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -292,36 +292,66 @@ export default function BRC20TokenScreen() {
292292
const chainType = useChainType();
293293
const chain = useChain();
294294

295+
const isBrc20Prog = useMemo(() => {
296+
if (chainType === ChainType.BITCOIN_MAINNET || chainType === ChainType.BITCOIN_SIGNET) {
297+
if (ticker.length == 6) {
298+
return true;
299+
}
300+
}
301+
return false;
302+
}, [ticker, chainType]);
303+
295304
const enableTrade = useMemo(() => {
305+
if (isBrc20Prog) {
306+
return false;
307+
}
296308
if (chainType === ChainType.BITCOIN_MAINNET || chainType === ChainType.FRACTAL_BITCOIN_MAINNET) {
297309
return true;
298310
} else {
299311
return false;
300312
}
301-
}, [chainType]);
313+
}, [chainType, isBrc20Prog]);
314+
315+
const enableHistory = isBrc20Prog ? false : true;
302316

303317
const shouldUseTwoRowLayout = useMemo(() => {
304318
return enableTrade && chain.enableBrc20SingleStep;
305319
}, [enableTrade, chain.enableBrc20SingleStep]);
306320

307321
const marketPlaceUrl = useBRC20MarketPlaceWebsite(ticker);
308322

323+
const inscribePlaceUrl = useMemo(() => {
324+
if (isBrc20Prog) {
325+
return `${unisatWebsite}/inscribe?tab=brc20-prog&tick=${encodeURIComponent(ticker)}`;
326+
}
327+
return `${unisatWebsite}/inscribe?tick=${encodeURIComponent(ticker)}`;
328+
}, [isBrc20Prog, ticker, unisatWebsite]);
329+
309330
const tabItems = useMemo(() => {
310-
const items = [
311-
{
312-
key: TabKey.HISTORY,
313-
label: t('history')
314-
},
315-
{
316-
key: TabKey.DETAILS,
317-
label: t('details')
318-
}
319-
];
320-
return items;
321-
}, [t]);
331+
if (enableHistory) {
332+
const items = [
333+
{
334+
key: TabKey.HISTORY,
335+
label: t('history')
336+
},
337+
{
338+
key: TabKey.DETAILS,
339+
label: t('details')
340+
}
341+
];
342+
return items;
343+
} else {
344+
return [
345+
{
346+
key: TabKey.DETAILS,
347+
label: t('details')
348+
}
349+
];
350+
}
351+
}, [t, enableHistory]);
322352

323353
const renderTabChildren = useMemo(() => {
324-
if (activeTab === TabKey.HISTORY) {
354+
if (activeTab === TabKey.HISTORY && enableHistory) {
325355
return <BRC20TokenHistory ticker={ticker} />;
326356
}
327357

@@ -375,7 +405,7 @@ export default function BRC20TokenScreen() {
375405
</Column>
376406
);
377407
}
378-
}, [activeTab, deployInscription]);
408+
}, [activeTab, deployInscription, enableHistory, tokenSummary]);
379409

380410
return (
381411
<Layout>
@@ -399,7 +429,11 @@ export default function BRC20TokenScreen() {
399429
color={'ticker_color2'}
400430
/>
401431
<Row style={{ backgroundColor: 'rgba(244, 182, 44, 0.15)', borderRadius: 4 }} px="md" py="sm">
402-
<Text text={'brc-20'} style={{ color: 'rgba(244, 182, 44, 0.85)' }} />
432+
{isBrc20Prog ? (
433+
<Text text={'brc2.0'} style={{ color: 'rgba(244, 182, 44, 0.85)' }} />
434+
) : (
435+
<Text text={'brc-20'} style={{ color: 'rgba(244, 182, 44, 0.85)' }} />
436+
)}
403437
</Row>
404438
</Row>
405439
<Column itemsCenter fullX justifyCenter>
@@ -420,7 +454,7 @@ export default function BRC20TokenScreen() {
420454
disabled={!enableMint}
421455
icon="pencil"
422456
onClick={(e) => {
423-
window.open(`${unisatWebsite}/inscribe?tick=${encodeURIComponent(ticker)}`);
457+
window.open(inscribePlaceUrl);
424458
}}
425459
full
426460
/>
@@ -489,7 +523,7 @@ export default function BRC20TokenScreen() {
489523
disabled={!enableMint}
490524
icon="pencil"
491525
onClick={(e) => {
492-
window.open(`${unisatWebsite}/brc20/${encodeURIComponent(ticker)}`);
526+
window.open(inscribePlaceUrl);
493527
}}
494528
style={{
495529
...(!enableMint ? { backgroundColor: 'rgba(255,255,255,0.15)' } : {}),
@@ -536,26 +570,27 @@ export default function BRC20TokenScreen() {
536570
});
537571
}}
538572
/>
539-
) : enableTrade ? (
573+
) : (
540574
<Button
541575
text={t('trade')}
542576
preset="home"
543577
icon="trade"
578+
disabled={!enableTrade}
544579
onClick={(e) => {
545580
window.open(marketPlaceUrl);
546581
}}
547582
style={{
548583
width: '101px'
549584
}}
550585
/>
551-
) : null}
586+
)}
552587
</Row>
553588
)}
554589
</Column>
555590

556591
<TabBar
557-
defaultActiveKey={activeTab}
558-
activeKey={activeTab}
592+
defaultActiveKey={enableHistory ? activeTab : TabKey.DETAILS}
593+
activeKey={enableHistory ? activeTab : TabKey.DETAILS}
559594
items={tabItems}
560595
preset="style3"
561596
onTabClick={(key) => {
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { useEffect, useState } from 'react';
2+
3+
import { TickPriceItem, TokenBalance } from '@/shared/types';
4+
import { Column, Row } from '@/ui/components';
5+
import { useTools } from '@/ui/components/ActionComponent';
6+
import BRC20BalanceCard2 from '@/ui/components/BRC20BalanceCard2';
7+
import { Empty } from '@/ui/components/Empty';
8+
import { Pagination } from '@/ui/components/Pagination';
9+
import { useI18n } from '@/ui/hooks/useI18n';
10+
import { useCurrentAccount } from '@/ui/state/accounts/hooks';
11+
import { useChainType } from '@/ui/state/settings/hooks';
12+
import { useWallet } from '@/ui/utils';
13+
import { LoadingOutlined } from '@ant-design/icons';
14+
15+
import { useNavigate } from '../../MainRoute';
16+
17+
export function BRC20ProgList() {
18+
const navigate = useNavigate();
19+
const wallet = useWallet();
20+
const currentAccount = useCurrentAccount();
21+
const chainType = useChainType();
22+
const { t } = useI18n();
23+
24+
const [tokens, setTokens] = useState<TokenBalance[]>([]);
25+
const [total, setTotal] = useState(-1);
26+
const [pagination, setPagination] = useState({ currentPage: 1, pageSize: 100 });
27+
const [priceMap, setPriceMap] = useState<{ [key: string]: TickPriceItem }>();
28+
29+
const tools = useTools();
30+
const fetchData = async () => {
31+
try {
32+
const { list, total } = await wallet.getBRC20ProgList(
33+
currentAccount.address,
34+
pagination.currentPage,
35+
pagination.pageSize
36+
);
37+
setTokens(list);
38+
setTotal(total);
39+
if (list.length > 0) {
40+
wallet.getBrc20sPrice(list.map((item) => item.ticker)).then(setPriceMap);
41+
}
42+
} catch (e) {
43+
tools.toastError((e as Error).message);
44+
} finally {
45+
// tools.showLoading(false);
46+
}
47+
};
48+
49+
useEffect(() => {
50+
fetchData();
51+
}, [pagination, currentAccount.address, chainType]);
52+
53+
if (total === -1) {
54+
return (
55+
<Column style={{ minHeight: 150 }} itemsCenter justifyCenter>
56+
<LoadingOutlined />
57+
</Column>
58+
);
59+
}
60+
61+
if (total === 0) {
62+
return (
63+
<Column style={{ minHeight: 150 }} itemsCenter justifyCenter>
64+
<Empty text={t('empty')} />
65+
</Column>
66+
);
67+
}
68+
69+
return (
70+
<Column>
71+
<Row style={{ flexWrap: 'wrap' }} gap="sm">
72+
{tokens.map((data, index) => (
73+
<BRC20BalanceCard2
74+
key={'brc20-' + index + data.ticker}
75+
tokenBalance={data}
76+
showPrice={priceMap !== undefined}
77+
price={priceMap?.[data.ticker]}
78+
onClick={() => {
79+
navigate('BRC20TokenScreen', { tokenBalance: data, ticker: data.ticker });
80+
}}
81+
/>
82+
))}
83+
</Row>
84+
85+
<Row justifyCenter mt="lg">
86+
<Pagination
87+
pagination={pagination}
88+
total={total}
89+
onChange={(pagination) => {
90+
setPagination(pagination);
91+
}}
92+
/>
93+
</Row>
94+
</Column>
95+
);
96+
}

src/ui/pages/Main/WalletTabScreen/OrdinalsTab.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useChain } from '@/ui/state/settings/hooks';
99
import { useOrdinalsAssetTabKey } from '@/ui/state/ui/hooks';
1010
import { OrdinalsAssetTabKey, uiActions } from '@/ui/state/ui/reducer';
1111

12+
import { BRC20ProgList } from './BRC20ProgList';
1213
import { BRC20List } from './Brc20List';
1314
import { InscriptionList } from './InscriptionList';
1415

@@ -39,13 +40,13 @@ export function OrdinalsTab() {
3940
}
4041
];
4142

42-
// if (!chain.isFractal) {
43-
// items.push({
44-
// key: OrdinalsAssetTabKey.BRC20_5BYTE,
45-
// label: `brc-20[5-byte] (${addressSummary.brc20Count5Byte || 0})`,
46-
// children: <BRC20List5Byte />
47-
// });
48-
// }
43+
if (chain.enableBrc20Prog) {
44+
items.push({
45+
key: OrdinalsAssetTabKey.BRC20_5BYTE,
46+
label: `brc2.0 (${addressSummary.brc20Count6Byte || 0})`,
47+
children: <BRC20ProgList />
48+
});
49+
}
4950
return items;
5051
}, [addressSummary, chain]);
5152

src/ui/utils/WalletContext.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ export interface WalletController {
299299
pageSize: number
300300
): Promise<{ currentPage: number; pageSize: number; total: number; list: TokenBalance[] }>;
301301

302+
getBRC20ProgList(
303+
address: string,
304+
currentPage: number,
305+
pageSize: number
306+
): Promise<{ currentPage: number; pageSize: number; total: number; list: TokenBalance[] }>;
307+
302308
getBRC20TransferableList(
303309
address: string,
304310
ticker: string,

0 commit comments

Comments
 (0)