Skip to content

Commit

Permalink
fix asset selection bug
Browse files Browse the repository at this point in the history
  • Loading branch information
qrtp committed Dec 21, 2024
1 parent 2d5fe27 commit 813ed7c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
2 changes: 1 addition & 1 deletion packages/ui-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@unstoppabledomains/ui-components",
"version": "0.0.52-browser-extension.12",
"version": "0.0.52-browser-extension.13",
"private": true,
"description": "An open and reusable suite of Unstoppable Domains management components",
"keywords": [
Expand Down
43 changes: 21 additions & 22 deletions packages/ui-components/src/lib/wallet/asset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ import {getAsset} from './asset';

describe('selecting asset', () => {
const mockAssets: AccountAsset[] = [
{
'@type': 'unstoppabledomains.com/wallets.v1.WalletAccountAssetMinimal',
id: 'wa-aa-6c2a38cd-c12f-4bb1-97fb-da2cf5398ec5',
address: '0x8ee1E1d88EBE2B44eAD162777DE787Ef6A2dC2F2',
blockchainAsset: {
'@type': 'unstoppabledomains.com/wallets.v1.BlockchainAsset',
id: 'wa-ba-a8d05b8b-9201-41b8-8401-069dc3909a48',
name: 'Ethereum',
symbol: 'ETH',
blockchain: {
id: 'ETHEREUM',
name: 'Ethereum',
networkId: 11155111,
},
},
accountId: 'wa-ac-4458235d-cac9-4695-bed9-5458adb093d3',
},
{
'@type': 'unstoppabledomains.com/wallets.v1.WalletAccountAssetMinimal',
id: 'wa-aa-92498f05-ecdb-4932-99a8-69dde0c67219',
Expand Down Expand Up @@ -87,23 +104,6 @@ describe('selecting asset', () => {
},
accountId: 'wa-ac-4458235d-cac9-4695-bed9-5458adb093d3',
},
{
'@type': 'unstoppabledomains.com/wallets.v1.WalletAccountAssetMinimal',
id: 'wa-aa-6c2a38cd-c12f-4bb1-97fb-da2cf5398ec5',
address: '0x8ee1E1d88EBE2B44eAD162777DE787Ef6A2dC2F2',
blockchainAsset: {
'@type': 'unstoppabledomains.com/wallets.v1.BlockchainAsset',
id: 'wa-ba-a8d05b8b-9201-41b8-8401-069dc3909a48',
name: 'Ethereum',
symbol: 'ETH',
blockchain: {
id: 'ETHEREUM',
name: 'Ethereum',
networkId: 11155111,
},
},
accountId: 'wa-ac-4458235d-cac9-4695-bed9-5458adb093d3',
},
];

it('should select default Ethereum asset by address', () => {
Expand Down Expand Up @@ -141,13 +141,12 @@ describe('selecting asset', () => {
expect(asset?.blockchainAsset.blockchain.id).toBe('POLYGON');
});

it('should ignore an invalid chain ID', () => {
it('should not return an asset for invalid chain ID', () => {
const asset = getAsset(mockAssets, {
chainId: 9999999999,
address: '0x8ee1E1d88EBE2B44eAD162777DE787Ef6A2dC2F2',
});
expect(asset).toBeDefined();
expect(asset?.blockchainAsset.blockchain.id).toBe('ETHEREUM');
expect(asset).not.toBeDefined();
});

it('should select Solana asset by address', () => {
Expand Down Expand Up @@ -226,8 +225,8 @@ describe('selecting asset', () => {

it('should select the first element if no parameters provided', () => {
const asset = getAsset(mockAssets);
expect(asset?.blockchainAsset.blockchain.id).toBe('POLYGON');
expect(asset?.blockchainAsset.name).toBe('USD Coin');
expect(asset?.blockchainAsset.blockchain.id).toBe('ETHEREUM');
expect(asset?.blockchainAsset.name).toBe('Ethereum');
});

it('should not select an asset if address is not found', () => {
Expand Down
8 changes: 3 additions & 5 deletions packages/ui-components/src/lib/wallet/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ export const getAsset = (
const asset = assets.find(a => {
// use chain ID if provided
if (opts?.chainId) {
const chainAsset =
return (
SUPPORTED_SIGNING_SYMBOLS.includes(
a.blockchainAsset.symbol.toUpperCase(),
) && a.blockchainAsset.blockchain.networkId === opts.chainId;
if (chainAsset) {
return chainAsset;
}
) && a.blockchainAsset.blockchain.networkId === opts.chainId
);
}

// use token if provided
Expand Down

0 comments on commit 813ed7c

Please sign in to comment.