Skip to content

Commit

Permalink
fix showing symbol custom token
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTrunk committed Nov 15, 2024
1 parent f37db59 commit ee1fc5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/components/TransactionRequest/TransactionRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const TransactionRequest = (props: {
const [receiverAddress, setReceiverAddress] = useState('');
const [senderAddress, setSenderAddress] = useState('');
const [token, setToken] = useState('');
const [tokenSymbol, setTokenSymbol] = useState('');
const [fee, setFee] = useState('');
const [authenticationOpen, setAuthenticationOpen] = useState(false);
const blockchainConfig = blockchains[props.chain];
Expand Down Expand Up @@ -71,6 +72,7 @@ const TransactionRequest = (props: {
setReceiverAddress(txInfo.receiver);
setSenderAddress(txInfo.sender);
setToken(txInfo.token || '');
setTokenSymbol(txInfo.tokenSymbol);
if (
(props.utxos && props.utxos.length) ||
blockchains[props.chain].chainType === 'evm'
Expand Down Expand Up @@ -136,12 +138,7 @@ const TransactionRequest = (props: {
{' ' +
sendingAmount +
' ' +
(token
? blockchainConfig.tokens.find(
(ttt) =>
ttt.contract.toLocaleLowerCase() === token.toLowerCase(),
)?.symbol
: blockchainConfig.symbol) +
(token ? tokenSymbol : blockchainConfig.symbol) +
' '}
</Text>
<Text style={[Fonts.textSmall, Fonts.textCenter]}>
Expand Down
8 changes: 8 additions & 0 deletions src/lib/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface tokenInfo {
receiver: string;
amount: string;
fee: string;
tokenSymbol: string;
token?: string;
}

Expand Down Expand Up @@ -124,6 +125,7 @@ export async function decodeTransactionForApproval(
receiver: txReceiver,
amount,
fee,
tokenSymbol: blockchains[chain].symbol,
};
return txInfo;
} catch (error) {
Expand All @@ -133,6 +135,7 @@ export async function decodeTransactionForApproval(
receiver: 'decodingError',
amount: 'decodingError',
fee: 'decodingError',
tokenSymbol: 'decodingError',
};
return txInfo;
}
Expand Down Expand Up @@ -216,6 +219,7 @@ export async function decodeEVMTransactionForApproval(
amount,
fee: totalFeeWei.toFixed(),
token: '',
tokenSymbol: '',
};

if (amount === '0') {
Expand All @@ -239,6 +243,7 @@ export async function decodeEVMTransactionForApproval(

if (token) {
decimals = token.decimals;
txInfo.tokenSymbol = token.symbol;
}
const contractData: `0x${string}` = decodedData.args[2] as `0x${string}`;
// most likely we are dealing with a contract call, sending some erc20 token
Expand All @@ -259,6 +264,8 @@ export async function decodeEVMTransactionForApproval(
.dividedBy(new BigNumber(10 ** decimals))
.toFixed();
}
} else {
txInfo.tokenSymbol = blockchains[chain].symbol;
}

return txInfo;
Expand All @@ -270,6 +277,7 @@ export async function decodeEVMTransactionForApproval(
amount: 'decodingError',
fee: 'decodingError',
token: 'decodingError',
tokenSymbol: 'decodingError',
};
return txInfo;
}
Expand Down

0 comments on commit ee1fc5b

Please sign in to comment.