Skip to content

Commit a2bdc58

Browse files
committed
fix: wp
1 parent 66bc311 commit a2bdc58

19 files changed

Lines changed: 238 additions & 100 deletions

File tree

src/app/_components/NewNavBar/PagesSlidingMenu.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import {
2+
SBTC_TOKEN_CONTRACT_ID_MAINNNET,
3+
SBTC_TOKEN_CONTRACT_ID_TESTNET,
4+
} from '@/app/token/[tokenId]/consts';
5+
import { usePrimaryPages } from '@/common/utils/navbar-utils';
16
import { Text } from '@/ui/Text';
27
import { Flex, Icon, Separator, Stack } from '@chakra-ui/react';
38
import { CaretUpDown, List } from '@phosphor-icons/react';
@@ -6,12 +11,13 @@ import { useMemo, useState } from 'react';
611

712
import { SlidingMenu } from '../../../common/components/SlidingMenu';
813
import { PrimaryPageLink, SecondaryPageLink } from './PagesLinks';
9-
import { PrimaryPageLabel, primaryPages, secondaryPages } from './consts';
14+
import { PrimaryPageLabel, secondaryPages } from './consts';
1015

1116
const getPageLabelFromPath = (path: string): PrimaryPageLabel => {
1217
if (path === '/transactions') return 'Transactions';
1318
if (path === '/tokens') return 'Tokens';
14-
if (path === '/token/SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token') return 'sBTC';
19+
if (path === `/token/${SBTC_TOKEN_CONTRACT_ID_MAINNNET}`) return 'sBTC';
20+
if (path === `/token/${SBTC_TOKEN_CONTRACT_ID_TESTNET}`) return 'sBTC';
1521
if (path === '/signers') return 'Signers';
1622
if (path === '/blocks') return 'Blocks';
1723
if (path === '/mempool') return 'Mempool';
@@ -29,6 +35,7 @@ export const PagesSlidingMenu = () => {
2935
const [isOpen, setIsOpen] = useState(false);
3036
const path = usePathname();
3137
const pageLabel = getPageLabelFromPath(path);
38+
const primaryPages = usePrimaryPages();
3239

3340
const menuContent = useMemo(() => {
3441
return (
@@ -48,7 +55,7 @@ export const PagesSlidingMenu = () => {
4855
</Stack>
4956
</Stack>
5057
);
51-
}, [pageLabel]);
58+
}, [pageLabel, primaryPages]);
5259

5360
return (
5461
<SlidingMenu

src/app/_components/NewNavBar/consts.ts

Lines changed: 70 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import {
2+
SBTC_TOKEN_CONTRACT_ID_MAINNNET,
3+
SBTC_TOKEN_CONTRACT_ID_TESTNET,
4+
} from '@/app/token/[tokenId]/consts';
5+
16
export type PrimaryPage = {
27
id: PrimaryPageId;
38
label: PrimaryPageLabel;
@@ -30,58 +35,71 @@ export type PrimaryPageId =
3035
| 'nfts'
3136
| 'analytics';
3237

33-
export const primaryPages: PrimaryPage[] = [
34-
{
35-
id: 'home',
36-
label: 'Home',
37-
href: '/',
38-
},
39-
{
40-
id: 'blocks',
41-
label: 'Blocks',
42-
href: '/blocks',
43-
},
44-
{
45-
id: 'transactions',
46-
label: 'Transactions',
47-
href: '/transactions',
48-
},
49-
{
50-
id: 'mempool',
51-
label: 'Mempool',
52-
href: '/mempool',
53-
},
54-
{
55-
id: 'sbtc',
56-
label: 'sBTC',
57-
href: '/token/SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token',
58-
},
59-
// {
60-
// id: 'stacking',
61-
// label: 'Stacking',
62-
// href: '/stacking',
63-
// },
64-
{
65-
id: 'signers',
66-
label: 'Signers',
67-
href: '/signers',
68-
},
69-
{
70-
id: 'tokens',
71-
label: 'Tokens',
72-
href: '/tokens',
73-
},
74-
// {
75-
// id: 'nfts',
76-
// label: 'NFTs',
77-
// href: '/nfts',
78-
// },
79-
// {
80-
// id: 'analytics',
81-
// label: 'Analytics',
82-
// href: '/analytics',
83-
// },
84-
];
38+
export const homePage: PrimaryPage = {
39+
id: 'home',
40+
label: 'Home',
41+
href: '/',
42+
};
43+
44+
export const blocksPage: PrimaryPage = {
45+
id: 'blocks',
46+
label: 'Blocks',
47+
href: '/blocks',
48+
};
49+
50+
export const transactionsPage: PrimaryPage = {
51+
id: 'transactions',
52+
label: 'Transactions',
53+
href: '/transactions',
54+
};
55+
56+
export const mempoolPage: PrimaryPage = {
57+
id: 'mempool',
58+
label: 'Mempool',
59+
href: '/mempool',
60+
};
61+
62+
export const sbtcMainnetPage: PrimaryPage = {
63+
id: 'sbtc',
64+
label: 'sBTC',
65+
href: `/token/${SBTC_TOKEN_CONTRACT_ID_MAINNNET}`,
66+
};
67+
68+
export const sbtcTestnetPage: PrimaryPage = {
69+
id: 'sbtc',
70+
label: 'sBTC',
71+
href: `/token/${SBTC_TOKEN_CONTRACT_ID_TESTNET}`,
72+
};
73+
74+
export const stackingPage: PrimaryPage = {
75+
id: 'stacking',
76+
label: 'Stacking',
77+
href: '/stacking',
78+
};
79+
80+
export const signersPage: PrimaryPage = {
81+
id: 'signers',
82+
label: 'Signers',
83+
href: '/signers',
84+
};
85+
86+
export const tokensPage: PrimaryPage = {
87+
id: 'tokens',
88+
label: 'Tokens',
89+
href: '/tokens',
90+
};
91+
92+
export const nftsPage: PrimaryPage = {
93+
id: 'nfts',
94+
label: 'NFTs',
95+
href: '/nfts',
96+
};
97+
98+
export const analyticsPage: PrimaryPage = {
99+
id: 'analytics',
100+
label: 'Analytics',
101+
href: '/analytics',
102+
};
85103

86104
export type SecondaryPageLabel = 'Sandbox' | 'Status Center' | 'Support';
87105
export type SecondaryPageId = 'sandbox' | 'status-center' | 'support';

src/app/address/[principal]/redesign/AddressOverview.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SBTC_ASSET_ID, SBTC_DECIMALS } from '@/app/token/[tokenId]/consts';
1+
import { SBTC_DECIMALS } from '@/app/token/[tokenId]/consts';
22
import { TabsContentContainer } from '@/app/txid/[txId]/redesign/TxTabs';
33
import {
44
PriceSummaryItemValue,
@@ -8,6 +8,7 @@ import {
88
import { Circle } from '@/common/components/Circle';
99
import { AddressTxsTable } from '@/common/components/table/table-examples/AddressTxsTable';
1010
import { ADDRESS_ID_PAGE_RECENT_ADDRESS_TXS_LIMIT } from '@/common/components/table/table-examples/consts';
11+
import { useSbtcTokenAssetId } from '@/common/utils/fungible-token-utils';
1112
import { getFtDecimalAdjustedBalance, microToStacks } from '@/common/utils/utils';
1213
import { SimpleTag } from '@/ui/Badge';
1314
import { NextLink } from '@/ui/NextLink';
@@ -106,6 +107,7 @@ const BalanceItem = ({
106107

107108
const BalanceCard = () => {
108109
const { initialAddressBalancesData, stxPrice, btcPrice } = useAddressIdPageData();
110+
const sbtcTokenAssetId = useSbtcTokenAssetId();
109111

110112
const totalBalanceMicroStacks = initialAddressBalancesData?.stx.balance;
111113
const isStxBalanceDefined =
@@ -114,7 +116,7 @@ const BalanceCard = () => {
114116
const totalBalanceUsdValue = isStxBalanceDefined ? totalBalanceStacks * stxPrice : 0;
115117

116118
const fungibleTokenBalances = initialAddressBalancesData?.fungible_tokens;
117-
const sbtcBalance = fungibleTokenBalances?.[SBTC_ASSET_ID]?.balance;
119+
const sbtcBalance = fungibleTokenBalances?.[sbtcTokenAssetId]?.balance;
118120
const isSbtcBalanceDefined = sbtcBalance !== undefined && !isNaN(parseFloat(sbtcBalance));
119121
const sbtcBalanceNumber = isSbtcBalanceDefined
120122
? getFtDecimalAdjustedBalance(sbtcBalance, SBTC_DECIMALS)

src/app/token/[tokenId]/PageClient.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client';
22

3-
import { getHasSBTCInName, getIsSBTC } from '@/app/tokens/utils';
3+
import { getHasSBTCInName } from '@/app/tokens/utils';
4+
import { useIsSBTC } from '@/common/utils/fungible-token-utils';
45
import { useIsRedesignUrl } from '@/common/utils/url-utils';
56
import { Link } from '@/ui/Link';
67
import { Box, Flex, Icon, Image, Stack } from '@chakra-ui/react';
@@ -46,13 +47,13 @@ export default function TokenIdPage({
4647
tokenInfo: TokenInfoProps;
4748
}) {
4849
const isRedesignUrl = useIsRedesignUrl();
50+
const isSBTC = useIsSBTC(tokenId);
4951

5052
if (!tokenInfo?.basic) throw new Error('Could not find token info');
5153

5254
const { name, symbol, imageUri } = tokenInfo.basic || {};
5355
const categories = tokenInfo?.extended?.categories || [];
5456
const hasSBTCInName = getHasSBTCInName(name ?? '', symbol ?? '');
55-
const isSBTC = getIsSBTC(tokenId);
5657
const isRisky = RISKY_TOKENS.includes(tokenId);
5758

5859
const warningMessage = useMemo(() => {

src/app/token/[tokenId]/Tabs/index.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { getIsSBTC } from '@/app/tokens/utils';
1+
import {
2+
useIsSBTC,
3+
useSbtcDepositContractId,
4+
useSbtcWithdrawlContractId,
5+
} from '@/common/utils/fungible-token-utils';
26

37
import { ContractAvailableFunctions } from '../../../../common/components/ContractAvailableFunctions';
48
import { TabsContainer } from '../../../../common/components/TabsContainer';
@@ -11,7 +15,6 @@ import { AddressMempoolTxsList } from '../../../../features/txs-list/AddressMemp
1115
import { CodeEditor } from '../../../../ui/CodeEditor';
1216
import { TabsRootProps } from '../../../../ui/Tabs';
1317
import { ExplorerErrorBoundary } from '../../../_components/ErrorBoundary';
14-
import { sbtcDepositAddress, sbtcWidthdrawlContractAddress } from '../consts';
1518
import { DeveloperData, TokenInfoProps } from '../types';
1619
import { Developers } from './Developers';
1720
import HoldersTable from './holders/Holders';
@@ -25,10 +28,12 @@ interface TokenTabsProps extends Partial<TabsRootProps> {
2528
export function TokenTabsBase({ tokenId, tokenInfo, developerData }: TokenTabsProps) {
2629
const { data: contract } = useSuspenseContractById(tokenId);
2730
const source = contract?.source_code;
28-
const isSBTC = getIsSBTC(tokenId);
29-
const { data: sbtcWithdrawalContract } = useContractById(
30-
isSBTC ? sbtcWidthdrawlContractAddress : undefined
31-
);
31+
const isSBTC = useIsSBTC(tokenId);
32+
const sbtcWithdrawlContractId = useSbtcWithdrawlContractId();
33+
const sbtcDepositContractId = useSbtcDepositContractId();
34+
const { data: sbtcWithdrawalContract } = useContractById(sbtcWithdrawlContractId, {
35+
enabled: isSBTC,
36+
});
3237

3338
return (
3439
<TabsContainer
@@ -48,7 +53,7 @@ export function TokenTabsBase({ tokenId, tokenInfo, developerData }: TokenTabsPr
4853
{
4954
title: 'Confirmed Deposits',
5055
id: 'confirmed-deposits',
51-
content: <AddressConfirmedTxsList address={sbtcDepositAddress} />,
56+
content: <AddressConfirmedTxsList address={sbtcDepositContractId} />,
5257
},
5358
]
5459
: []),
@@ -57,7 +62,7 @@ export function TokenTabsBase({ tokenId, tokenInfo, developerData }: TokenTabsPr
5762
{
5863
title: 'Pending Deposits',
5964
id: 'pending-deposits',
60-
content: <AddressMempoolTxsList address={sbtcDepositAddress} />,
65+
content: <AddressMempoolTxsList address={sbtcDepositContractId} />,
6166
},
6267
]
6368
: []),
@@ -68,7 +73,7 @@ export function TokenTabsBase({ tokenId, tokenInfo, developerData }: TokenTabsPr
6873
id: 'withdraw-deposits',
6974
content: (
7075
<ContractAvailableFunctions
71-
contractId={sbtcWidthdrawlContractAddress}
76+
contractId={sbtcWithdrawlContractId}
7277
contract={sbtcWithdrawalContract}
7378
/>
7479
),

src/app/token/[tokenId]/TokenInfo/Price.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getIsSBTC } from '@/app/tokens/utils';
1+
import { useIsSBTC } from '@/common/utils/fungible-token-utils';
22
import { Flex, StackProps } from '@chakra-ui/react';
33
import { FC } from 'react';
44

@@ -13,7 +13,8 @@ export const Price: FC<
1313
tokenId: string;
1414
}
1515
> = ({ currentPrice, priceChangePercentage24h, currentPriceInBtc, tokenId, ...stackProps }) => {
16-
const isSBTC = getIsSBTC(tokenId);
16+
const isSBTC = useIsSBTC(tokenId);
17+
1718
return (
1819
<StatSection
1920
title="Price"

src/app/token/[tokenId]/consts.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1-
export const sbtcDepositAddress = 'SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4';
2-
export const sbtcContractAddress = 'SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token';
3-
export const sbtcWidthdrawlContractAddress =
1+
export const SBTC_TOKEN_CONTRACT_ID_MAINNNET =
2+
'SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token';
3+
export const SBTC_TOKEN_CONTRACT_ID_TESTNET =
4+
'ST1F7QA2MDF17S807EPA36TSS8AMEFY4KA9TVGWXT.sbtc-token';
5+
6+
export const SBTC_TOKEN_ASSET_ID_MAINNET =
7+
'SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token::sbtc-token';
8+
export const SBTC_TOKEN_ASSET_ID_TESTNET =
9+
'ST1F7QA2MDF17S807EPA36TSS8AMEFY4KA9TVGWXT.sbtc-token::sbtc-token';
10+
11+
export const SBTC_DEPOSIT_CONTRACT_ID_MAINNET = 'SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4';
12+
export const SBTC_DEPOSIT_CONTRACT_ADDRESS_TESTNET = 'ST1F7QA2MDF17S807EPA36TSS8AMEFY4KA9TVGWXT';
13+
export const SBTC_DEPOSIT_CONTRACT_ID_TESTNET =
14+
'ST1F7QA2MDF17S807EPA36TSS8AMEFY4KA9TVGWXT.sbtc-deposit';
15+
16+
export const SBTC_WITHDRAWAL_CONTRACT_ID_MAINNET =
417
'SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-withdrawal';
5-
export const SBTC_ASSET_ID = 'SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token::sbtc-token';
18+
export const SBTC_WITHDRAWAL_CONTRACT_ID_TESTNET =
19+
'ST1F7QA2MDF17S807EPA36TSS8AMEFY4KA9TVGWXT.sbtc-withdrawal';
20+
621
export const SBTC_DECIMALS = 8;
22+
723
export const DROID_CONTRACT_ADDRESS = 'SP2EEV5QBZA454MSMW9W3WJNRXVJF36VPV17FFKYH.DROID';
824
const zsbtcContractAddress = 'SP2VCQJGH7PHP2DJK7Z0V48AGBHQAW3R3ZW1QF4N.zsbtc-token';
925
export const RISKY_TOKENS = [
@@ -22,4 +38,8 @@ export const RISKY_NFT_RULES = [
2238
/\.StacksDao$/, // Exact match for contract names ending with .StacksDao (case sensitive)
2339
];
2440
export const legitsBTCDerivatives = [zsbtcContractAddress];
25-
export const VERIFIED_TOKENS = [DROID_CONTRACT_ADDRESS, zsbtcContractAddress, sbtcContractAddress];
41+
export const VERIFIED_TOKENS = [
42+
DROID_CONTRACT_ADDRESS,
43+
zsbtcContractAddress,
44+
SBTC_TOKEN_CONTRACT_ID_MAINNNET,
45+
];

src/app/token/[tokenId]/page-data.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { fetchTokenDataFromLunarCrush, fetchTokenMetadata } from '@/api/data-fetchers';
2+
import { NetworkModes } from '@/common/types/network';
23
import { logError } from '@/common/utils/error-utils';
4+
import { getIsSBTC } from '@/common/utils/fungible-token-utils';
35

46
import { getFtDecimalAdjustedBalance } from '../../../common/utils/utils';
5-
import { getIsSBTC } from '../../tokens/utils';
67
import {
78
DeveloperDataRedesign,
89
MergedTokenData,
@@ -117,7 +118,8 @@ async function getTokenDataFromLunarCrush(
117118
export async function getTokenDataRedesign(
118119
tokenId: string,
119120
apiUrl: string,
120-
isCustomApi: boolean
121+
isCustomApi: boolean,
122+
chain: NetworkModes
121123
): Promise<MergedTokenData> {
122124
let tokenDataFromStacksApi: TokenDataFromStacksApi | undefined;
123125
let tokenDataFromLunarCrush: TokenDataFromLunarCrush | undefined;
@@ -130,7 +132,7 @@ export async function getTokenDataRedesign(
130132

131133
const mergedTokenData =
132134
tokenDataFromStacksApi && tokenDataFromLunarCrush
133-
? redesignMergeTokenData(tokenDataFromStacksApi, tokenDataFromLunarCrush, tokenId)
135+
? redesignMergeTokenData(tokenDataFromStacksApi, tokenDataFromLunarCrush, tokenId, chain)
134136
: {};
135137
return mergedTokenData;
136138
} catch (error) {
@@ -152,10 +154,11 @@ const safeGet = <T>(primary: T | undefined, fallback?: T | undefined): T | undef
152154
function redesignMergeTokenData(
153155
tokenDataFromStacksApi: TokenDataFromStacksApi | undefined,
154156
tokenDataFromLunarCrush: TokenDataFromLunarCrush | undefined,
155-
tokenId: string
157+
tokenId: string,
158+
chain: NetworkModes
156159
): MergedTokenData {
157160
// Determine if this is SBTC token for special handling
158-
const isSBTC = getIsSBTC(tokenId);
161+
const isSBTC = getIsSBTC(tokenId, chain);
159162

160163
// Basic token information
161164
const name = safeGet(tokenDataFromLunarCrush?.name, tokenDataFromStacksApi?.name);

0 commit comments

Comments
 (0)