From 28d09a0b36b19929adff9386be7606a6a4de3ee2 Mon Sep 17 00:00:00 2001 From: slient-coder Date: Fri, 15 Aug 2025 18:59:11 +0800 Subject: [PATCH 1/2] feat: add brc2.0 fix fix fix fix --- src/background/controller/wallet.ts | 13 +++ src/background/service/openapi.ts | 8 ++ src/shared/constant/index.ts | 7 +- src/shared/types.ts | 1 + src/ui/pages/BRC20/BRC20TokenScreen.tsx | 79 ++++++++++----- .../Main/WalletTabScreen/BRC20ProgList.tsx | 96 +++++++++++++++++++ .../Main/WalletTabScreen/OrdinalsTab.tsx | 15 +-- src/ui/utils/WalletContext.tsx | 6 ++ 8 files changed, 194 insertions(+), 31 deletions(-) create mode 100644 src/ui/pages/Main/WalletTabScreen/BRC20ProgList.tsx diff --git a/src/background/controller/wallet.ts b/src/background/controller/wallet.ts index b48bb999..96e59b79 100644 --- a/src/background/controller/wallet.ts +++ b/src/background/controller/wallet.ts @@ -2867,5 +2867,18 @@ export class WalletController extends BaseController { getBRC20RecentHistory(address: string, ticker: string): Promise { return openapiService.getBRC20RecentHistory(address, ticker); } + + getBRC20ProgList = async (address: string, currentPage: number, pageSize: number) => { + const cursor = (currentPage - 1) * pageSize; + const size = pageSize; + const { total, list } = await openapiService.getBRC20ProgList(address, cursor, size); + + return { + currentPage, + pageSize, + total, + list + }; + }; } export default new WalletController(); diff --git a/src/background/service/openapi.ts b/src/background/service/openapi.ts index 6aee676b..6ff8cb9b 100644 --- a/src/background/service/openapi.ts +++ b/src/background/service/openapi.ts @@ -967,6 +967,14 @@ export class OpenApiService { feeRate }); } + + async getBRC20ProgList( + address: string, + cursor: number, + size: number + ): Promise<{ list: TokenBalance[]; total: number }> { + return this.httpGet('/v5/brc20-prog/list', { address, cursor, size, type: 5 }); + } } export default new OpenApiService(); diff --git a/src/shared/constant/index.ts b/src/shared/constant/index.ts index e5bb7cdf..20cf6895 100644 --- a/src/shared/constant/index.ts +++ b/src/shared/constant/index.ts @@ -247,6 +247,7 @@ export type TypeChain = { showPrice: boolean; defaultExplorer: 'mempool-space' | 'unisat-explorer'; enableBrc20SingleStep?: boolean; + enableBrc20Prog?: boolean; }; export const CHAINS_MAP: { [key: string]: TypeChain } = { @@ -264,7 +265,8 @@ export const CHAINS_MAP: { [key: string]: TypeChain } = { unisatExplorerUrl: 'https://uniscan.cc', okxExplorerUrl: '', showPrice: true, - defaultExplorer: 'unisat-explorer' + defaultExplorer: 'unisat-explorer', + enableBrc20Prog: true }, [ChainType.BITCOIN_TESTNET]: { enum: ChainType.BITCOIN_TESTNET, @@ -312,7 +314,8 @@ export const CHAINS_MAP: { [key: string]: TypeChain } = { unisatExplorerUrl: 'https://uniscan.cc/signet', okxExplorerUrl: '', showPrice: false, - defaultExplorer: 'unisat-explorer' + defaultExplorer: 'unisat-explorer', + enableBrc20Prog: true }, [ChainType.FRACTAL_BITCOIN_MAINNET]: { enum: ChainType.FRACTAL_BITCOIN_MAINNET, diff --git a/src/shared/types.ts b/src/shared/types.ts index 41299458..641054cf 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -442,6 +442,7 @@ export interface AddressSummary { atomicalsCount: number; brc20Count: number; brc20Count5Byte: number; + brc20Count6Byte: number; arc20Count: number; runesCount: number; loading?: boolean; diff --git a/src/ui/pages/BRC20/BRC20TokenScreen.tsx b/src/ui/pages/BRC20/BRC20TokenScreen.tsx index dd4930c2..ecd50a4c 100644 --- a/src/ui/pages/BRC20/BRC20TokenScreen.tsx +++ b/src/ui/pages/BRC20/BRC20TokenScreen.tsx @@ -292,13 +292,27 @@ export default function BRC20TokenScreen() { const chainType = useChainType(); const chain = useChain(); + const isBrc20Prog = useMemo(() => { + if (chainType === ChainType.BITCOIN_MAINNET || chainType === ChainType.BITCOIN_SIGNET) { + if (ticker.length == 6) { + return true; + } + } + return false; + }, [ticker, chainType]); + const enableTrade = useMemo(() => { + if (isBrc20Prog) { + return false; + } if (chainType === ChainType.BITCOIN_MAINNET || chainType === ChainType.FRACTAL_BITCOIN_MAINNET) { return true; } else { return false; } - }, [chainType]); + }, [chainType, isBrc20Prog]); + + const enableHistory = isBrc20Prog ? false : true; const shouldUseTwoRowLayout = useMemo(() => { return enableTrade && chain.enableBrc20SingleStep; @@ -306,22 +320,38 @@ export default function BRC20TokenScreen() { const marketPlaceUrl = useBRC20MarketPlaceWebsite(ticker); + const inscribePlaceUrl = useMemo(() => { + if (isBrc20Prog) { + return `${unisatWebsite}/inscribe?tab=brc20-prog&tick=${encodeURIComponent(ticker)}`; + } + return `${unisatWebsite}/inscribe?tick=${encodeURIComponent(ticker)}`; + }, [isBrc20Prog, ticker, unisatWebsite]); + const tabItems = useMemo(() => { - const items = [ - { - key: TabKey.HISTORY, - label: t('history') - }, - { - key: TabKey.DETAILS, - label: t('details') - } - ]; - return items; - }, [t]); + if (enableHistory) { + const items = [ + { + key: TabKey.HISTORY, + label: t('history') + }, + { + key: TabKey.DETAILS, + label: t('details') + } + ]; + return items; + } else { + return [ + { + key: TabKey.DETAILS, + label: t('details') + } + ]; + } + }, [t, enableHistory]); const renderTabChildren = useMemo(() => { - if (activeTab === TabKey.HISTORY) { + if (activeTab === TabKey.HISTORY && enableHistory) { return ; } @@ -375,7 +405,7 @@ export default function BRC20TokenScreen() { ); } - }, [activeTab, deployInscription]); + }, [activeTab, deployInscription, enableHistory, tokenSummary]); return ( @@ -399,7 +429,11 @@ export default function BRC20TokenScreen() { color={'ticker_color2'} /> - + {isBrc20Prog ? ( + + ) : ( + + )} @@ -420,7 +454,7 @@ export default function BRC20TokenScreen() { disabled={!enableMint} icon="pencil" onClick={(e) => { - window.open(`${unisatWebsite}/inscribe?tick=${encodeURIComponent(ticker)}`); + window.open(inscribePlaceUrl); }} full /> @@ -489,7 +523,7 @@ export default function BRC20TokenScreen() { disabled={!enableMint} icon="pencil" onClick={(e) => { - window.open(`${unisatWebsite}/brc20/${encodeURIComponent(ticker)}`); + window.open(inscribePlaceUrl); }} style={{ ...(!enableMint ? { backgroundColor: 'rgba(255,255,255,0.15)' } : {}), @@ -536,11 +570,12 @@ export default function BRC20TokenScreen() { }); }} /> - ) : enableTrade ? ( + ) : (