-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
38 changed files
with
1,382 additions
and
146 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import axios from 'axios'; | ||
import { getCleanApiAddress } from 'apiCalls/utils'; | ||
import { TIMEOUT } from 'constants/index'; | ||
import { ScamInfoType } from 'types/account.types'; | ||
import { ACCOUNTS_ENDPOINT } from '../endpoints'; | ||
|
||
export async function getScamAddressData(addressToVerify: string) { | ||
const apiAddress = getCleanApiAddress(); | ||
|
||
const { data } = await axios.get<{ | ||
scamInfo?: ScamInfoType; | ||
code?: string; | ||
}>(`${apiAddress}/${ACCOUNTS_ENDPOINT}/${addressToVerify}`, { | ||
timeout: TIMEOUT | ||
}); | ||
|
||
return data; | ||
} |
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,25 @@ | ||
import axios from 'axios'; | ||
import { ECONOMICS_ENDPOINT } from 'apiCalls/endpoints'; | ||
import { getCleanApiAddress } from 'apiCalls/utils/getCleanApiAddress'; | ||
|
||
export interface EconomicsInfoType { | ||
totalSupply: number; | ||
circulatingSupply: number; | ||
staked: number; | ||
price: number; | ||
marketCap: number; | ||
apr: number; | ||
topUpApr: number; | ||
} | ||
|
||
export async function getEconomics(url = ECONOMICS_ENDPOINT) { | ||
const apiAddress = getCleanApiAddress(); | ||
const configUrl = `${apiAddress}/${url}`; | ||
try { | ||
const { data } = await axios.get<EconomicsInfoType>(configUrl); | ||
return data; | ||
} catch (err) { | ||
console.error('err fetching economics info', err); | ||
return null; | ||
} | ||
} |
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 { getCleanApiAddress } from 'apiCalls/utils'; | ||
import { axiosInstance } from 'apiCalls/utils/axiosInstance'; | ||
import { TIMEOUT } from 'constants/network.constants'; | ||
import { tokenDataStorage } from './tokenDataStorage'; | ||
|
||
export async function getPersistedToken<T>(url: string): Promise<T> { | ||
const apiAddress = getCleanApiAddress(); | ||
|
||
const config = { | ||
baseURL: apiAddress, | ||
timeout: TIMEOUT | ||
}; | ||
|
||
const cachedToken: T | null = await tokenDataStorage.getItem(url); | ||
|
||
if (cachedToken) { | ||
return cachedToken; | ||
} | ||
|
||
const response = await axiosInstance.get<T>(url, config); | ||
|
||
await tokenDataStorage.setItem(url, response.data); | ||
|
||
return response.data; | ||
} |
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,104 @@ | ||
import { NFTS_ENDPOINT, TOKENS_ENDPOINT } from 'apiCalls/endpoints'; | ||
import { getPersistedToken } from 'apiCalls/tokens/getPersistedToken'; | ||
import { networkSelector } from 'store/selectors/networkSelectors'; | ||
import { getState } from 'store/store'; | ||
|
||
import { NftEnumType } from 'types/tokens.types'; | ||
import { getIdentifierType } from 'utils/validation/getIdentifierType'; | ||
|
||
export interface TokenAssets { | ||
description: string; | ||
status: string; | ||
svgUrl: string; | ||
website?: string; | ||
pngUrl?: string; | ||
social?: any; | ||
extraTokens?: string[]; | ||
lockedAccounts?: { [key: string]: string }; | ||
} | ||
|
||
export interface TokenMediaType { | ||
url?: string; | ||
originalUrl?: string; | ||
thumbnailUrl?: string; | ||
fileType?: string; | ||
fileSize?: number; | ||
} | ||
|
||
export interface TokenOptionType { | ||
tokenLabel: string; | ||
tokenDecimals: number; | ||
tokenImageUrl: string; | ||
assets?: TokenAssets; | ||
type?: NftEnumType; | ||
error?: string; | ||
esdtPrice?: number; | ||
ticker?: string; | ||
identifier?: string; | ||
name?: string; | ||
} | ||
|
||
interface TokenInfoResponse { | ||
identifier: string; | ||
name: string; | ||
ticker: string; | ||
decimals: number; | ||
type?: NftEnumType; | ||
assets: TokenAssets; | ||
media?: TokenMediaType[]; | ||
price: number; | ||
} | ||
|
||
export async function getPersistedTokenDetails({ | ||
tokenId | ||
}: { | ||
tokenId?: string; | ||
}): Promise<TokenOptionType> { | ||
const network = networkSelector(getState()); | ||
|
||
const noData = { | ||
tokenDecimals: Number(network.decimals), | ||
tokenLabel: '', | ||
tokenImageUrl: '' | ||
}; | ||
|
||
const { isNft } = getIdentifierType(tokenId); | ||
|
||
const tokenIdentifier = tokenId; | ||
const tokenEndpoint = isNft ? NFTS_ENDPOINT : TOKENS_ENDPOINT; | ||
|
||
if (!tokenIdentifier) { | ||
return noData; | ||
} | ||
|
||
try { | ||
const selectedToken = await getPersistedToken<TokenInfoResponse>( | ||
`${network.apiAddress}/${tokenEndpoint}/${tokenIdentifier}` | ||
); | ||
|
||
const tokenDecimals = selectedToken | ||
? selectedToken?.decimals | ||
: Number(network.decimals); | ||
const tokenLabel = selectedToken ? selectedToken?.name : ''; | ||
const tokenImageUrl = selectedToken | ||
? selectedToken?.assets?.svgUrl ?? selectedToken?.media?.[0]?.thumbnailUrl | ||
: ''; | ||
|
||
return { | ||
tokenDecimals: tokenDecimals, | ||
tokenLabel, | ||
type: selectedToken?.type, | ||
tokenImageUrl, | ||
identifier: selectedToken?.identifier, | ||
assets: selectedToken?.assets, | ||
esdtPrice: selectedToken?.price, | ||
ticker: selectedToken?.ticker, | ||
name: selectedToken?.name | ||
}; | ||
} catch (error) { | ||
return { | ||
...noData, | ||
error: `${error}` | ||
}; | ||
} | ||
} |
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,33 @@ | ||
let memoryCache: Record<string, string> = {}; | ||
|
||
export let tokenDataStorage = { | ||
setItem: async <T>(key: string, tokenData: T) => { | ||
try { | ||
memoryCache[key] = JSON.stringify(tokenData); | ||
} catch (e) { | ||
console.error('tokenDataStorage unable to serialize', e); | ||
} | ||
}, | ||
getItem: async (key: string) => { | ||
if (!memoryCache[key]) { | ||
return null; | ||
} | ||
try { | ||
return JSON.parse(memoryCache[key]); | ||
} catch (e) { | ||
console.error('tokenDataStorage unable to parse', e); | ||
} | ||
}, | ||
clear: async () => { | ||
memoryCache = {}; | ||
}, | ||
removeItem: async (key: string) => { | ||
delete memoryCache[key]; | ||
} | ||
}; | ||
|
||
export const setTokenDataStorage = ( | ||
tokenDataCacheStorage: typeof tokenDataStorage | ||
) => { | ||
tokenDataStorage = tokenDataCacheStorage; | ||
}; |
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
35 changes: 34 additions & 1 deletion
35
src/core/managers/SignTransactionsStateManager/types/signTransactionsModal.types.ts
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
Oops, something went wrong.