Skip to content

Commit

Permalink
[WEB-2045] Update Squid Swap(support Cosmos -> EVM swap) (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Gamja authored Nov 28, 2023
1 parent 1159660 commit e5cbc38
Show file tree
Hide file tree
Showing 17 changed files with 1,098 additions and 440 deletions.
7 changes: 5 additions & 2 deletions src/Popup/hooks/SWR/ethereum/useTokensSWR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { KAVA } from '~/constants/chain/ethereum/network/kava';
import { SMART_CHAIN } from '~/constants/chain/ethereum/network/smartChain';
import { get } from '~/Popup/utils/axios';
import { toHex } from '~/Popup/utils/string';
import type { EthereumNetwork } from '~/types/chain';
import type { AssetPayload, ModifiedAsset } from '~/types/ethereum/asset';

import { useCurrentEthereumNetwork } from '../../useCurrent/useCurrentEthereumNetwork';
Expand All @@ -17,10 +18,12 @@ const nameMap = {
[KAVA.id]: 'kava',
};

export function useTokensSWR(config?: SWRConfiguration) {
export function useTokensSWR(chain?: EthereumNetwork, config?: SWRConfiguration) {
const { currentEthereumNetwork } = useCurrentEthereumNetwork();

const mappingName = nameMap[currentEthereumNetwork.id] || currentEthereumNetwork.networkName.toLowerCase();
const currentChain = chain || currentEthereumNetwork;

const mappingName = nameMap[currentChain.id] || currentChain.networkName.toLowerCase();

const requestURL = `https://front.api.mintscan.io/v3/assets/${mappingName}/erc20`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type UseSkipRouteSWRProps = {
};

export function useSkipRouteSWR({ routeParam }: UseSkipRouteSWRProps, config?: SWRConfiguration) {
const requestURL = `${SKIP_BASE_URL}/v1/fungible/route`;
const requestURL = `${SKIP_BASE_URL}/v1/fungible/route?client_id=cosmostation_extension`;

const fetcher = async ({ fetchUrl, skipRouteParam }: FetchProps) =>
post<SkipRoutePayload>(fetchUrl, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { get } from '~/Popup/utils/axios';
import type { SupportedSkipChain } from '~/types/swap/asset';

export function useSkipSupportChainsSWR(config?: SWRConfiguration) {
const requestURL = `${SKIP_BASE_URL}/v1/info/chains`;
const requestURL = `${SKIP_BASE_URL}/v1/info/chains?client_id=cosmostation_extension`;

const fetcher = (fetchUrl: string) => get<SupportedSkipChain>(fetchUrl);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { AxiosError } from 'axios';
import type { SWRConfiguration } from 'swr';
import useSWR from 'swr';

import { SKIP_BASE_URL } from '~/constants/skip';
import { get } from '~/Popup/utils/axios';
import type { SupportedSkipToken } from '~/types/swap/asset';

export function useSkipSupportTokensSWR(chainId?: string, config?: SWRConfiguration) {
const requestURL = `${SKIP_BASE_URL}/v1/fungible/assets?chain_id=${
chainId || ''
}&native_only=false&include_no_metadata_assets=true&include_cw20_assets=true&include_evm_assets=true&client_id=cosmostation_extension`;

const fetcher = (fetchUrl: string) => get<SupportedSkipToken>(fetchUrl);

const { data, error, mutate } = useSWR<SupportedSkipToken, AxiosError>(requestURL, fetcher, {
revalidateOnFocus: false,
revalidateIfStale: false,
revalidateOnReconnect: false,
isPaused: () => !chainId || !requestURL,
...config,
});

return { data, error, mutate };
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type UseSkipSwapTxSWRProps = {
};

export function useSkipSwapTxSWR({ skipSwapTxParam: swapTxParam }: UseSkipSwapTxSWRProps, config?: SWRConfiguration) {
const requestURL = `${SKIP_BASE_URL}/v1/fungible/msgs`;
const requestURL = `${SKIP_BASE_URL}/v1/fungible/msgs?client_id=cosmostation_extension`;

const fetcher = async ({ fetchUrl, skipSwapTxParam }: FetchProps) =>
post<SkipSwapTxPayload>(fetchUrl, {
Expand Down
Loading

0 comments on commit e5cbc38

Please sign in to comment.