@@ -50,33 +50,31 @@ export interface InfoError {
50
50
}
51
51
52
52
export type DecimalLike = string | number | bigint | BigDecimal ;
53
- export const sleep = ( ms : number ) => new Promise ( ( r ) => setTimeout ( r , ms ) ) ;
54
- export const EVM_CHAIN_ID : NetworkChainId [ ] = evmChains . map ( ( c ) => c . chainId ) ;
53
+ export const sleep = ( ms : number ) => new Promise ( r => setTimeout ( r , ms ) ) ;
54
+ export const EVM_CHAIN_ID : NetworkChainId [ ] = evmChains . map ( c => c . chainId ) ;
55
55
export const networks = chainInfosWithIcon . filter (
56
- ( c ) => c . chainId !== ChainIdEnum . OraiBridge && c . chainId !== ( 'oraibtc-mainnet-1' as any ) && c . chainId !== '0x1ae6'
56
+ c => c . chainId !== ChainIdEnum . OraiBridge && c . chainId !== ( 'oraibtc-mainnet-1' as any ) && c . chainId !== '0x1ae6'
57
57
) ;
58
58
export const cosmosNetworks = chainInfos . filter (
59
- ( c ) =>
60
- c . networkType === 'cosmos' && c . chainId !== ChainIdEnum . OraiBridge && c . chainId !== ( 'oraibtc-mainnet-1' as any )
59
+ c => c . networkType === 'cosmos' && c . chainId !== ChainIdEnum . OraiBridge && c . chainId !== ( 'oraibtc-mainnet-1' as any )
61
60
) ;
62
61
63
- export const bitcoinNetworks = chainInfos . filter ( ( c ) => c . chainId === bitcoinChainId ) ;
62
+ export const bitcoinNetworks = chainInfos . filter ( c => c . chainId === bitcoinChainId ) ;
64
63
export const cosmosNetworksWithIcon = chainInfos . filter (
65
- ( c ) =>
66
- c . networkType === 'cosmos' && c . chainId !== ChainIdEnum . OraiBridge && c . chainId !== ( 'oraibtc-mainnet-1' as any )
64
+ c => c . networkType === 'cosmos' && c . chainId !== ChainIdEnum . OraiBridge && c . chainId !== ( 'oraibtc-mainnet-1' as any )
67
65
) ;
68
66
69
- export const evmNetworksWithoutTron = chainInfos . filter ( ( c ) => c . networkType === 'evm' && c . chainId !== '0x2b6653dc' ) ;
67
+ export const evmNetworksWithoutTron = chainInfos . filter ( c => c . networkType === 'evm' && c . chainId !== '0x2b6653dc' ) ;
70
68
export const evmNetworksIconWithoutTron = chainInfosWithIcon . filter (
71
- ( c ) => c . networkType === 'evm' && c . chainId !== '0x2b6653dc'
69
+ c => c . networkType === 'evm' && c . chainId !== '0x2b6653dc'
72
70
) ;
73
71
74
72
// export const bitcoinNetworks = chainInfos.filter((c) => c.chainId === ChainIdEnum.Bitcoin);
75
- export const tronNetworks = chainInfos . filter ( ( c ) => c . chainId === '0x2b6653dc' ) ;
76
- export const tronNetworksWithIcon = chainInfosWithIcon . filter ( ( c ) => c . chainId === '0x2b6653dc' ) ;
77
- export const btcNetworksWithIcon = chainInfosWithIcon . filter ( ( c ) => c . chainId === bitcoinChainId ) ;
78
- export const solanaNetworksWithIcon = chainInfosWithIcon . filter ( ( c ) => c . chainId === solChainId ) ;
79
- export const tonNetworksWithIcon = chainInfosWithIcon . filter ( ( c ) => c . chainId === TonChainId ) ;
73
+ export const tronNetworks = chainInfos . filter ( c => c . chainId === '0x2b6653dc' ) ;
74
+ export const tronNetworksWithIcon = chainInfosWithIcon . filter ( c => c . chainId === '0x2b6653dc' ) ;
75
+ export const btcNetworksWithIcon = chainInfosWithIcon . filter ( c => c . chainId === bitcoinChainId ) ;
76
+ export const solanaNetworksWithIcon = chainInfosWithIcon . filter ( c => c . chainId === solChainId ) ;
77
+ export const tonNetworksWithIcon = chainInfosWithIcon . filter ( c => c . chainId === TonChainId ) ;
80
78
81
79
export const filterChainBridge = ( token : Tokens | TokenItemType , item : CustomChainInfo ) => {
82
80
const tokenCanBridgeTo = token . bridgeTo ?? [ 'Oraichain' ] ;
@@ -95,7 +93,7 @@ export const getDenomEvm = (): EvmDenom => {
95
93
} ;
96
94
97
95
export const getSpecialCoingecko = ( fromCoingecko : string , toCoingecko : string ) => {
98
- const isSpecialCoingecko = ( coinGeckoId ) =>
96
+ const isSpecialCoingecko = coinGeckoId =>
99
97
[ 'kawaii-islands' , 'milky-token' , 'injective-protocol' ] . includes ( coinGeckoId ) ;
100
98
const isSpecialFromCoingecko = isSpecialCoingecko ( fromCoingecko ) ;
101
99
const isSpecialToCoingecko = isSpecialCoingecko ( toCoingecko ) ;
@@ -138,7 +136,7 @@ export const getAccountUrl = (account: string) => {
138
136
export const getNetworkGasPrice = async ( chainId ) : Promise < number > => {
139
137
try {
140
138
const chainInfosWithoutEndpoints = await window . Keplr ?. getChainInfosWithoutEndpoints ( chainId ) ;
141
- const findToken = chainInfosWithoutEndpoints . find ( ( e ) => e . chainId === chainId ) ;
139
+ const findToken = chainInfosWithoutEndpoints . find ( e => e . chainId === chainId ) ;
142
140
if ( findToken ) {
143
141
return findToken . feeCurrencies [ 0 ] . gasPriceStep . average ;
144
142
}
@@ -186,11 +184,11 @@ export const handleCheckWallet = async () => {
186
184
}
187
185
} ;
188
186
189
- export const handleCheckChainEvmWallet = async ( fromChainId ) => {
187
+ export const handleCheckChainEvmWallet = async fromChainId => {
190
188
const supportedChainIds = [ '0x01' , '0x38' ] ;
191
189
192
190
if ( supportedChainIds . includes ( fromChainId ) ) {
193
- const fromChainInfo = evmChainInfos . find ( ( evm ) => Number ( evm . chainId ) === Number ( fromChainId ) ) ;
191
+ const fromChainInfo = evmChainInfos . find ( evm => Number ( evm . chainId ) === Number ( fromChainId ) ) ;
194
192
if ( fromChainInfo ) {
195
193
try {
196
194
await window . ethereumDapp . request ( {
@@ -242,7 +240,7 @@ const transferMsgError = (message: string, info?: InfoError) => {
242
240
return `Your previous transaction has not been included in a block. Please wait until it is included before creating a new transaction!` ;
243
241
244
242
const network = info ?. chainName
245
- ? [ ...evmChains , ...cosmosChains ] . find ( ( evm ) => evm . chainId === info . chainName ) ?. chainName
243
+ ? [ ...evmChains , ...cosmosChains ] . find ( evm => evm . chainId === info . chainName ) ?. chainName
246
244
: '' ;
247
245
if ( message . includes ( 'Insufficient funds to redeem voucher' ) || message . includes ( 'checking balance channel ibc' ) )
248
246
return `Insufficient ${ info ?. tokenName ?? '' } liquidity on ${ network } Bridge` ;
@@ -371,7 +369,11 @@ export const switchWalletTron = async (walletType: WalletType) => {
371
369
} else {
372
370
const { code, message = 'Tronlink is not ready' } = res ;
373
371
if ( code !== 200 ) throw new Error ( message ) ;
374
- tronAddress = window . tronWeb ?. defaultAddress ?. base58 ;
372
+ if ( res ?. base58 ) {
373
+ tronAddress = res . base58 ;
374
+ } else {
375
+ tronAddress = window . tronWeb ?. defaultAddress ?. base58 ;
376
+ }
375
377
}
376
378
377
379
if ( ! tronAddress ) throw new Error ( res ?. message ?? 'Error get Tron address!' ) ;
@@ -396,10 +398,10 @@ export const isConnectSpecificNetwork = (status: string | null) => {
396
398
export const getAddressTransferForEvm = async ( walletByNetworks : WalletsByNetwork , network : CustomChainInfo ) => {
397
399
let address = '' ;
398
400
if ( network . chainId === EVM_CHAIN_ID_COMMON . TRON_CHAIN_ID ) {
399
- if ( window . tronLinkDapp ?. isOwallet ) {
400
- const accountTron : interfaceRequestTron = await window . tronLinkDapp . request ( {
401
- method : 'tron_requestAccounts'
402
- } ) ;
401
+ const accountTron : interfaceRequestTron = await window . tronLinkDapp . request ( {
402
+ method : 'tron_requestAccounts'
403
+ } ) ;
404
+ if ( accountTron && accountTron . code === 200 && accountTron . base58 ) {
403
405
address = accountTron . base58 ;
404
406
} else {
405
407
address = window ?. tronWebDapp ?. defaultAddress ?. base58 ;
@@ -423,6 +425,7 @@ export const getAddressTransfer = async (network: CustomChainInfo, walletByNetwo
423
425
toUserFriendlyAddress ( window . Ton ?. account ?. address ) ;
424
426
// address = useTonAddress();
425
427
} else if ( network . networkType === 'evm' && isConnectSpecificNetwork ( walletByNetworks . evm ) ) {
428
+ //here
426
429
address = await getAddressTransferForEvm ( walletByNetworks , network ) ;
427
430
} else if ( network . networkType == 'svm' && isConnectSpecificNetwork ( walletByNetworks . solana ) ) {
428
431
let provider = window ?. solana ;
@@ -490,7 +493,7 @@ export const getChainSupported = async () => {
490
493
}
491
494
} ) ;
492
495
} ;
493
- export const getAddressBySnap = async ( chainId ) => {
496
+ export const getAddressBySnap = async chainId => {
494
497
await window . Keplr . suggestChain ( chainId ) ;
495
498
const rs = await getChainSupported ( ) ;
496
499
if ( rs ?. [ chainId ] ) {
@@ -516,7 +519,7 @@ type ChainInfoWithoutIcons = Omit<CustomChainInfo, 'currencies' | 'Icon' | 'Icon
516
519
currencies : Array < Omit < CustomChainInfo [ 'currencies' ] [ number ] , 'Icon' | 'IconLight' > > ;
517
520
bech32Config : Bech32Config ;
518
521
} ;
519
- const checkErrorObj = ( info ) => {
522
+ const checkErrorObj = info => {
520
523
if ( info ?. Icon && info ?. IconLight ) {
521
524
const { Icon, IconLight, ...data } = info ;
522
525
return data ;
@@ -531,16 +534,16 @@ const checkErrorObj = (info) => {
531
534
} ;
532
535
export const chainInfoWithoutIcon = ( ) : ChainInfoWithoutIcons [ ] => {
533
536
let chainInfoData = [ ...chainInfos ] ;
534
- return chainInfoData . map ( ( info ) => {
537
+ return chainInfoData . map ( info => {
535
538
const infoWithoutIcon = checkErrorObj ( info ) ;
536
539
537
- const currenciesWithoutIcons = info . currencies . map ( ( currency ) => {
540
+ const currenciesWithoutIcons = info . currencies . map ( currency => {
538
541
const currencyWithoutIcons = checkErrorObj ( currency ) ;
539
542
return currencyWithoutIcons ;
540
543
} ) ;
541
544
542
545
const stakeCurrencyyWithoutIcons = checkErrorObj ( info . stakeCurrency ) ;
543
- const feeCurrenciesWithoutIcons = info ?. feeCurrencies ?. map ( ( feeCurrency ) => {
546
+ const feeCurrenciesWithoutIcons = info ?. feeCurrencies ?. map ( feeCurrency => {
544
547
const feeCurrencyyWithoutIcon = checkErrorObj ( feeCurrency ) ;
545
548
546
549
return feeCurrencyyWithoutIcon ;
@@ -607,7 +610,7 @@ export interface GetIconInterface {
607
610
export const minimize = ( priceUsd : string ) => {
608
611
const regex = / ^ 0 \. 0 * ( \d + ) / ;
609
612
const match = priceUsd . match ( regex ) ;
610
- const getSubscript = ( num ) => String . fromCharCode ( 0x2080 + num ) ;
613
+ const getSubscript = num => String . fromCharCode ( 0x2080 + num ) ;
611
614
612
615
if ( match ) {
613
616
const leadingZeros = match [ 0 ] . length - match [ 1 ] . length - 2 ;
@@ -649,7 +652,7 @@ export function formatMoney(num) {
649
652
650
653
export const getIcon = ( { isLightTheme, type, chainId, coinGeckoId, width, height } : GetIconInterface ) => {
651
654
if ( type === 'token' ) {
652
- const tokenIcon = flattenTokens . find ( ( token ) => token . coinGeckoId === coinGeckoId ) ;
655
+ const tokenIcon = flattenTokens . find ( token => token . coinGeckoId === coinGeckoId ) ;
653
656
if ( tokenIcon ) {
654
657
return isLightTheme ? (
655
658
< img src = { tokenIcon . iconLight } alt = "" width = { width } height = { height } />
@@ -660,7 +663,7 @@ export const getIcon = ({ isLightTheme, type, chainId, coinGeckoId, width, heigh
660
663
661
664
return < DefaultIcon /> ;
662
665
} else {
663
- const networkIcon = chainInfos . find ( ( chain ) => chain . chainId === chainId ) ;
666
+ const networkIcon = chainInfos . find ( chain => chain . chainId === chainId ) ;
664
667
if ( networkIcon ) {
665
668
return isLightTheme ? (
666
669
< img src = { networkIcon . chainSymbolImageUrl } alt = "" width = { width } height = { height } />
@@ -680,7 +683,7 @@ export const getIconWallet = () => {
680
683
export const getIconToken = ( { isLightTheme, denom, width = 30 , height = 30 } ) => {
681
684
const storage = store . getState ( ) ;
682
685
const allOraichainTokens = storage . token . allOraichainTokens || [ ] ;
683
- const tokenIcon = allOraichainTokens . find ( ( tokenWithIcon ) =>
686
+ const tokenIcon = allOraichainTokens . find ( tokenWithIcon =>
684
687
[ tokenWithIcon . contractAddress , tokenWithIcon . denom ] . includes ( denom )
685
688
) ;
686
689
if ( tokenIcon ) {
@@ -765,7 +768,7 @@ export const inspectTokenFromOraiCommonApi = async (denoms: string[]): Promise<T
765
768
if ( response . status !== 200 ) throw new Error ( 'Failed to fetch token list: ' + response . statusText ) ;
766
769
767
770
const inspectedTokens = await response . json ( ) ;
768
- const tokenItemTypes = inspectedTokens . map ( ( info ) => onChainTokenToTokenItem ( info ) ) ;
771
+ const tokenItemTypes = inspectedTokens . map ( info => onChainTokenToTokenItem ( info ) ) ;
769
772
return tokenItemTypes ;
770
773
} catch ( error ) {
771
774
console . log ( 'Error inspectTokenFromOraiCommonApi: ' , error ) ;
0 commit comments