Skip to content

Commit

Permalink
Merge pull request #248 from skip-mev/kiki/fre-647-destination-chain-…
Browse files Browse the repository at this point in the history
…auto-selects-random-assets-for-evm-chains

FRE-647 native asset select on chain select or usdc
  • Loading branch information
codingki authored Apr 16, 2024
2 parents 727d745 + 39f5bdc commit 1fd72a7
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/components/SwapWidget/useSwapWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,12 @@ export function useSwapWidget() {
if (!asset) {
const assets = assetsByChainID(chain.chainID);
if (chain.chainType === "evm") {
asset = assets.find((asset) => asset.denom.endsWith("-native"));
asset = assets.find(
(asset) =>
asset.denom.endsWith("-native") ||
asset.name?.toLowerCase() === chain.chainName.toLowerCase() ||
asset.symbol?.toLowerCase().includes("usdc"),
);
}
asset ??= assets[0];
}
Expand Down Expand Up @@ -297,9 +302,23 @@ export function useSwapWidget() {
const { destinationAsset: currentDstAsset } = useSwapWidgetStore.getState();
const assets = assetsByChainID(chain.chainID);

let asset = await getFeeAsset(chain.chainID);
let feeAsset: Asset | undefined = undefined;
if (chain.chainType === "cosmos") {
feeAsset = await getFeeAsset(chain.chainID);
}

let asset = feeAsset;
if (!asset) {
[asset] = assets;
const assets = assetsByChainID(chain.chainID);
if (chain.chainType === "evm") {
asset = assets.find(
(asset) =>
asset.denom.endsWith("-native") ||
asset.name?.toLowerCase() === chain.chainName.toLowerCase() ||
asset.symbol?.toLowerCase().includes("usdc"),
);
}
asset ??= assets[0];
}
if (currentDstAsset && userTouchedDstAsset) {
const equivalentAsset = findEquivalentAsset(currentDstAsset, assets);
Expand Down

0 comments on commit 1fd72a7

Please sign in to comment.