Skip to content

Commit

Permalink
infer protocol from list instead of ft.principle (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
terencehh authored Jun 20, 2024
1 parent 46faf48 commit abff3ef
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/app/components/tokenTile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ interface Props {
title: string;
loading: boolean;
currency: CurrencyTypes;
onPress: (coin: CurrencyTypes, ftKey: string | undefined) => void;
onPress: (coin: CurrencyTypes, fungibleToken: FungibleToken | undefined) => void;
fungibleToken?: FungibleToken;
enlargeTicker?: boolean;
className?: string;
Expand Down Expand Up @@ -162,7 +162,7 @@ function TokenTile({
}
};

const handleTokenPressed = () => onPress(currency, fungibleToken?.principal);
const handleTokenPressed = () => onPress(currency, fungibleToken);

return (
<TileContainer onClick={handleTokenPressed} className={className}>
Expand Down
40 changes: 22 additions & 18 deletions src/app/screens/coinDashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import useBtcWalletData from '@hooks/queries/useBtcWalletData';
import useSpamTokens from '@hooks/queries/useSpamTokens';
import useTrackMixPanelPageViewed from '@hooks/useTrackMixPanelPageViewed';
import { Flag } from '@phosphor-icons/react';
import { FungibleToken } from '@secretkeylabs/xverse-core';
import {
setBrc20ManageTokensAction,
setRunesManageTokensAction,
Expand Down Expand Up @@ -155,28 +156,33 @@ export default function CoinDashboard() {
const { visible: runesCoinsList } = useVisibleRuneFungibleTokens();
const { visible: sip10CoinsList } = useVisibleSip10FungibleTokens();
const { visible: brc20CoinsList } = useVisibleBrc20FungibleTokens();

const ftKey = searchParams.get('ftKey');
const protocol = searchParams.get('protocol');
let selectedFt: FungibleToken | undefined;

if (ftKey && protocol) {
switch (protocol) {
case 'stacks':
selectedFt = sip10CoinsList.find((ft) => ft.principal === ftKey);
break;
case 'brc-20':
selectedFt = brc20CoinsList.find((ft) => ft.principal === ftKey);
break;
case 'runes':
selectedFt = runesCoinsList.find((ft) => ft.principal === ftKey);
break;
default:
selectedFt = undefined;
}
}

useBtcWalletData();

const handleGoBack = () => {
navigate(-1);
};

let selectedFt = sip10CoinsList.find((ft) => ft.principal === ftKey);
let selectedProtocol = 'stacks';

if (!selectedFt) {
selectedFt = brc20CoinsList.find((ft) => ft.principal === ftKey);
selectedProtocol = 'brc-20';
}

if (!selectedFt) {
selectedFt = runesCoinsList.find((ft) => ft.principal === ftKey);
selectedProtocol = 'runes';
}

const protocol = selectedProtocol || selectedFt?.protocol;
useTrackMixPanelPageViewed(
protocol
? {
Expand Down Expand Up @@ -229,13 +235,11 @@ export default function CoinDashboard() {
handleGoBack();
return;
}

// set the visibility to false
const payload = {
principal: selectedFt.principal,
isEnabled: false,
};

if (protocol === 'runes') {
dispatch(setRunesManageTokensAction(payload));
} else if (protocol === 'stacks') {
Expand Down Expand Up @@ -278,7 +282,7 @@ export default function CoinDashboard() {
</Button>
</FtInfoContainer>
)}
{protocol === 'stacks' && showFtContractDetails && (
{selectedFt && protocol === 'stacks' && showFtContractDetails && (
<TokenContractContainer data-testid="coin-contract-container">
<h1>{t('FT_CONTRACT_PREFIX')}</h1>
<ContractAddressCopyButton onClick={handleCopyContractAddress}>
Expand All @@ -300,7 +304,7 @@ export default function CoinDashboard() {
coin={currency as CurrencyTypes}
stxTxFilter={
selectedFt?.protocol === 'runes'
? selectedFt.name
? selectedFt?.name
: `${selectedFt?.principal}::${selectedFt?.assetName}`
}
brc20Token={protocol === 'brc-20' ? selectedFt?.principal || null : null}
Expand Down
8 changes: 5 additions & 3 deletions src/app/screens/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,11 @@ function Home() {
if (showBtcReceiveAlert) setIsBtcReceiveAlertVisible(true);
};

const handleTokenPressed = (currency: CurrencyTypes, ftKey?: string) => {
if (ftKey) {
navigate(`/coinDashboard/${currency}?ftKey=${ftKey}`);
const handleTokenPressed = (currency: CurrencyTypes, fungibleToken?: FungibleToken) => {
if (fungibleToken) {
navigate(
`/coinDashboard/${currency}?ftKey=${fungibleToken.principal}&protocol=${fungibleToken.protocol}`,
);
} else {
navigate(`/coinDashboard/${currency}`);
}
Expand Down

0 comments on commit abff3ef

Please sign in to comment.