-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: replaced the token list source
- Loading branch information
1 parent
743f209
commit 573a422
Showing
29 changed files
with
610 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
{ | ||
"npmClient": "yarn", | ||
"version": "independent" | ||
"version": "independent", | ||
"command": { | ||
"run": { | ||
"ignore": ["e2e/*"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import {expect, describe, it, vi, Mocked} from 'vitest' | ||
import {getTokenPairs} from './token-pairs' | ||
import {axiosClient} from './config' | ||
|
||
vi.mock('./config.ts') | ||
|
||
describe('SwapTokenPairsApi', () => { | ||
it('should get all tokens based pairs', async () => { | ||
const mockAxios = axiosClient as Mocked<typeof axiosClient> | ||
mockAxios.get.mockImplementationOnce(() => | ||
Promise.resolve({status: 200, data: mockedGetTokenPairsResponse}), | ||
) | ||
|
||
const result = await getTokenPairs({network: 'mainnet', client: mockAxios}) | ||
|
||
expect(result).to.be.lengthOf(1) | ||
}) | ||
|
||
it('should return empty list on preprod network', async () => { | ||
const mockAxios = axiosClient as Mocked<typeof axiosClient> | ||
|
||
const result = await getTokenPairs({network: 'preprod', client: mockAxios}) | ||
|
||
expect(result).to.be.empty | ||
}) | ||
|
||
it('should throw error for invalid response', async () => { | ||
const mockAxios = axiosClient as Mocked<typeof axiosClient> | ||
mockAxios.get.mockImplementationOnce(() => Promise.resolve({status: 500})) | ||
expect(() => | ||
getTokenPairs({network: 'mainnet', client: mockAxios}), | ||
).rejects.toThrow('Failed to fetch token pairs') | ||
}) | ||
}) | ||
|
||
const mockedGetTokenPairsResponse = [ | ||
{ | ||
info: { | ||
supply: {total: '1000000000000', circulating: null}, | ||
status: 'unverified', | ||
image: 'ipfs://QmPzaykTy4yfutCtwv7nRUmgbQbA7euiThyy2i9fiFuDHX', | ||
imageIpfsHash: 'QmPzaykTy4yfutCtwv7nRUmgbQbA7euiThyy2i9fiFuDHX', | ||
symbol: 'ARGENT', | ||
minting: { | ||
type: 'time-lock-policy', | ||
blockchain: 'cardano', | ||
mintedBeforeSlotNumber: 91850718, | ||
}, | ||
mediatype: 'image/png', | ||
tokentype: 'token', | ||
description: 'ARGENT Token', | ||
totalsupply: 1000000000000, | ||
address: { | ||
policyId: 'c04f4200502a998e9eebafac0291a1f38008de3fe146d136946d8f4b', | ||
name: '415247454e54', | ||
}, | ||
decimalPlaces: 0, | ||
categories: [], | ||
}, | ||
price: { | ||
volume: {base: 0, quote: 0}, | ||
volumeChange: {base: 0, quote: 0}, | ||
volumeTotal: {base: 0, quote: 0}, | ||
volumeAggregator: {}, | ||
price: 0, | ||
askPrice: 0, | ||
bidPrice: 0, | ||
priceChange: {'24h': 0, '7d': 0}, | ||
quoteDecimalPlaces: 0, | ||
baseDecimalPlaces: 6, | ||
quoteAddress: { | ||
policyId: 'c04f4200502a998e9eebafac0291a1f38008de3fe146d136946d8f4b', | ||
name: '415247454e54', | ||
}, | ||
baseAddress: {policyId: '', name: ''}, | ||
price10d: [], | ||
}, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {SWAP_API_ENDPOINTS} from './config' | ||
import type {ApiDeps, TokenPairsResponse} from './types' | ||
|
||
export async function getTokenPairs( | ||
deps: ApiDeps, | ||
{policyId = '', assetName = ''} = {}, | ||
): Promise<TokenPairsResponse> { | ||
const {network, client} = deps | ||
if (network === 'preprod') return [] | ||
|
||
const apiUrl = SWAP_API_ENDPOINTS[network].getTokenPairs | ||
const response = await client.get<TokenPairsResponse>('', { | ||
baseURL: apiUrl, | ||
params: { | ||
'base-policy-id': policyId, | ||
'base-tokenname': assetName, | ||
}, | ||
}) | ||
|
||
if (response.status !== 200) { | ||
throw new Error('Failed to fetch token pairs', {cause: response.data}) | ||
} | ||
|
||
return response.data | ||
} |
Oops, something went wrong.