Skip to content

Commit

Permalink
[NO CHANGELOG] [Add Tokens Widget] Fetch chains from squid sdk (#2384)
Browse files Browse the repository at this point in the history
  • Loading branch information
mimi-imtbl authored Nov 12, 2024
1 parent 230f601 commit 266257d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,15 @@ export default function AddTokensWidget({
}, [toTokenAddress, toAmount]);

useEffect(() => {
(async () => {
const chainsResponse = await fetchChains();
if (!squid) return;

addTokensDispatch({
payload: {
type: AddTokensActions.SET_CHAINS,
chains: chainsResponse,
},
});
})();
}, []);
addTokensDispatch({
payload: {
type: AddTokensActions.SET_CHAINS,
chains: fetchChains(squid),
},
});
}, [squid]);

useEffect(() => {
if (!squid || !chains || !fromProvider || fetchingBalances.current) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Squid } from '@0xsquid/sdk';
import { Chain } from '../types';
import { SQUID_API_BASE_URL } from '../utils/config';

type SquidChain = {
chainId: string;
Expand All @@ -9,31 +9,17 @@ type SquidChain = {
nativeCurrency: SquidNativeCurrency;
};

type SquidChains = {
chains: SquidChain[];
};

export type SquidNativeCurrency = {
name: string;
symbol: string;
decimals: number;
icon: string;
};

export const fetchChains = async (): Promise<Chain[]> => {
const url = `${SQUID_API_BASE_URL}/chains`;

const response = await fetch(url, {
method: 'GET',
headers: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'Content-Type': 'application/json',
},
});

const data: SquidChains = await response.json();
export const fetchChains = (squid: Squid): Chain[] => {
const { chains } = squid;

return data.chains.map((chain: SquidChain) => ({
return chains.map((chain: SquidChain) => ({
id: chain.chainId.toString(),
name: chain.networkName,
iconUrl: chain.chainIconURI,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export const SQUID_SDK_BASE_URL = 'https://apiplus.squidrouter.com';

export const SQUID_API_BASE_URL = 'https://api.squidrouter.com/v1';

export const SQUID_NATIVE_TOKEN = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';

export const FIXED_HANDOVER_DURATION = 2000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,6 @@ export function Review({
<Sticker.FramedImage
use={<img src={fromChain?.iconUrl} alt={fromChain?.name} />}
emphasized
sx={{
bottom: 'base.spacing.x2',
right: 'base.spacing.x2',
}}
/>
</Sticker>
<Stack sx={{ flex: 1 }} gap="0px">
Expand Down Expand Up @@ -596,10 +592,6 @@ export function Review({
<Sticker.FramedImage
use={<img src={toChain?.iconUrl} alt={toChain?.name} />}
emphasized
sx={{
bottom: 'base.spacing.x2',
right: 'base.spacing.x2',
}}
/>
</Sticker>
<Stack sx={{ flex: 1 }} gap="0px">
Expand Down

0 comments on commit 266257d

Please sign in to comment.