Skip to content

Commit

Permalink
add usdRif as default token in testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigoncalves committed Aug 28, 2023
1 parent 6765822 commit 2432d64
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/core/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,16 @@ const defaultTestnetTokens: ITokenWithoutLogo[] = Object.keys(testnetContracts)
usdBalance: 0,
}
})
export const getDefaultTokens = (chainId: ChainTypesByIdType) =>
chainTypesById[chainId] === ChainTypeEnum.MAINNET
export const getDefaultTokens = (chainId: ChainTypesByIdType) => {
const usdRifTestnet = {
decimals: 18,
name: 'RIF US Dollar',
symbol: 'USDRIF',
contractAddress: '0x8dbf326e12a9ff37ed6ddf75ada548c2640a6482',
balance: '0x00',
usdBalance: 0,
} as ITokenWithoutLogo
return chainTypesById[chainId] === ChainTypeEnum.MAINNET
? defaultMainnetTokens
: defaultTestnetTokens
: [...defaultTestnetTokens, usdRifTestnet]
}
13 changes: 9 additions & 4 deletions src/subscriptions/rifSockets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import EventEmitter from 'eventemitter3'
import { RIFWallet } from '@rsksmart/rif-wallet-core'
import {
ITokenWithBalance,
RifWalletServicesFetcher,
RifWalletServicesSocket,
} from '@rsksmart/rif-wallet-services'
Expand Down Expand Up @@ -95,12 +96,16 @@ export const rifSockets = ({
}

const defaultTokens = getDefaultTokens(chainId)
defaultTokens.forEach(t => {
const defaultTokensWithBalance = defaultTokens.map(t => {
const tokenBalance = balances[t.contractAddress]
t.balance = tokenBalance?.balance ?? t.balance
t.usdBalance = tokenBalance?.usdBalance ?? t.usdBalance
return {
...t,
logo: '',
balance: tokenBalance?.balance ?? t.balance,
usdBalance: tokenBalance?.usdBalance ?? t.usdBalance,
} as ITokenWithBalance
})
dispatch(addOrUpdateBalances(defaultTokens))
dispatch(addOrUpdateBalances(defaultTokensWithBalance))

rifWalletServicesSocket.removeAllListeners()

Expand Down

0 comments on commit 2432d64

Please sign in to comment.