Skip to content

Commit

Permalink
fix: get metis chain id from common pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff-CCH committed Oct 13, 2023
1 parent 4e11ee3 commit 0f3b32c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/logics/utility/logic.multi-send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ export class MultiSendLogic
static readonly supportedChainIds = common.networks.map(({ chainId }) => chainId);

async getTokenList(): Promise<MultiSendLogicTokenList> {
if (this.chainId === 1088) return getMetisTokens();
return get1InchTokens(this.chainId);
return this.chainId === common.ChainId.metis ? getMetisTokens() : get1InchTokens(this.chainId);
}

async build(fields: MultiSendLogicFields) {
Expand Down
3 changes: 1 addition & 2 deletions src/logics/utility/logic.send-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ export class SendTokenLogic extends core.Logic implements core.LogicTokenListInt
static readonly supportedChainIds = common.networks.map(({ chainId }) => chainId);

async getTokenList(): Promise<SendTokenLogicTokenList> {
if (this.chainId === 1088) return getMetisTokens();
return get1InchTokens(this.chainId);
return this.chainId === common.ChainId.metis ? getMetisTokens() : get1InchTokens(this.chainId);
}

async build(fields: SendTokenLogicFields) {
Expand Down
4 changes: 1 addition & 3 deletions src/utils/tokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { get1InchTokens, getMetisTokens } from './tokens';
describe('Test tokens', function () {
common.networks.forEach(({ chainId }) => {
it(`network: ${common.toNetworkId(chainId)}`, async function () {
let tokens;
if (chainId === 1088) tokens = await getMetisTokens();
else tokens = await get1InchTokens(chainId);
const tokens = chainId === common.ChainId.metis ? await getMetisTokens() : await get1InchTokens(chainId);
expect(tokens).to.have.lengthOf.above(0);
});
});
Expand Down
8 changes: 4 additions & 4 deletions src/utils/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ export async function get1InchTokens(chainId: number) {
}

export async function getMetisTokens() {
const chainId = 1088;
const chainId = common.ChainId.metis;
const { data } = await axios.get<
Record<string, { tokens: { symbol: string; name: string; decimals: number; address: string } }>
>(`https://tokens.coingecko.com/metis-andromeda/all.json`);

const nativeToken = common.getNativeToken(chainId);
const elasticAddress = common.ELASTIC_ADDRESS.toLowerCase();
const tokens = Object.values(data.tokens).map(({ address, decimals, symbol, name }) =>
address === elasticAddress ? nativeToken : new common.Token(chainId, address, decimals, symbol, name)
const tokens = Object.values(data.tokens).map(
({ address, decimals, symbol, name }) => new common.Token(chainId, address, decimals, symbol, name)
);
tokens.push(nativeToken);
return tokens;
}

0 comments on commit 0f3b32c

Please sign in to comment.