Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
fix: update icons url (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
luizstacio authored May 19, 2022
1 parent 0cc73e5 commit 1db591e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
9 changes: 3 additions & 6 deletions client/src/hooks/useAssets.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { useWallet } from 'src/context/AppContext';
import { CoinQuantity, toBigInt } from 'fuels';
import { Coin } from 'src/types';
import CoinsMetadata from 'src/lib/CoinsMetadata';
import CoinsMetadata, { ASSET_404 } from 'src/lib/CoinsMetadata';
import { useQuery } from 'react-query';
import urljoin from 'url-join';

const { PUBLIC_URL } = process.env;

type Asset = Coin & { amount: bigint };
const mergeCoinsWithMetadata = (coins: CoinQuantity[] = []): Array<Asset> => {
Expand All @@ -15,8 +12,8 @@ const mergeCoinsWithMetadata = (coins: CoinQuantity[] = []): Array<Asset> => {
// TODO: Create default Coin Metadata when token didn't have registered data
// Another options could be querying from the contract
// https://github.com/FuelLabs/swayswap-demo/issues/33
name: coinMetadata?.name || '404',
img: urljoin(PUBLIC_URL, coinMetadata?.img || '/icons/other.svg'),
name: coinMetadata?.name || ASSET_404.name,
img: coinMetadata?.img || ASSET_404.img,
assetId: coin.assetId,
amount: toBigInt(coin.amount || 0),
};
Expand Down
12 changes: 9 additions & 3 deletions client/src/lib/CoinsMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { Coin } from 'src/types';
import { CONTRACT_ID, TOKEN_ID } from 'src/config';
import { relativeUrl } from './utils';

export const ASSET_404 = {
name: '404',
img: relativeUrl('/icons/other.svg'),
};

const CoinsMetadata: Array<Coin> = [
{
name: 'Ether',
symbol: 'ETH',
assetId: '0x0000000000000000000000000000000000000000000000000000000000000000',
img: '/icons/eth.svg',
img: relativeUrl('/icons/eth.svg'),
},
{
name: 'DAI',
Expand All @@ -15,7 +21,7 @@ const CoinsMetadata: Array<Coin> = [
// Make temporarily easy to change token contract id
// https://github.com/FuelLabs/swayswap-demo/issues/33
assetId: TOKEN_ID,
img: '/icons/dai.svg',
img: relativeUrl('/icons/dai.svg'),
},
{
name: 'Sway',
Expand All @@ -24,7 +30,7 @@ const CoinsMetadata: Array<Coin> = [
// Make temporarily easy to change token contract id
// https://github.com/FuelLabs/swayswap-demo/issues/33
assetId: CONTRACT_ID,
img: '/icons/sway.svg',
img: relativeUrl('/icons/sway.svg'),
},
];

Expand Down
6 changes: 6 additions & 0 deletions client/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import urljoin from 'url-join';

const { PUBLIC_URL } = process.env;

export const objectId = (value: string) => ({
value,
});

export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

export const relativeUrl = (path: string) => urljoin(PUBLIC_URL, path);

0 comments on commit 1db591e

Please sign in to comment.