-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
US-2128: Change the order of tokens list to match the following seque…
…nce: RIF, USDRIF, RBTC, BTC, RDOC & others (#886) * sort tokens by symbol and define default tokens * define a new type TokenOrBitcoinNetwork * wrap with Number instead * fix imports * fix import * get back symbol as string * remove token filtering * change sorting balances approach * delete unused file * some adjustments
- Loading branch information
1 parent
794c2fd
commit 6d97c49
Showing
5 changed files
with
88 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { ChainID } from 'lib/eoaWallet' | ||
|
||
import { TokenSymbol, getTokenSymbolByChainId } from 'screens/home/TokenImage' | ||
import { TokenOrBitcoinNetwork } from 'shared/types' | ||
|
||
/** | ||
* Sorts balances by symbol in the following order: | ||
* RIF, USDRIF, RBTC, BTC, RDOC and then alphabetically by symbol | ||
* @param balances - array of balances | ||
* @param chainId - chain id (30 or 31) | ||
* @returns sorted array of balances | ||
*/ | ||
export const sortBalancesBySymbol = ( | ||
balances: Array<TokenOrBitcoinNetwork>, | ||
chainId: ChainID, | ||
): Array<TokenOrBitcoinNetwork> => { | ||
const rif = getTokenSymbolByChainId(TokenSymbol.RIF, chainId) | ||
const usdrif = getTokenSymbolByChainId(TokenSymbol.USDRIF, chainId) | ||
const rbtc = getTokenSymbolByChainId(TokenSymbol.RBTC, chainId) | ||
const btc = getTokenSymbolByChainId(TokenSymbol.BTC, chainId) | ||
const rdoc = getTokenSymbolByChainId(TokenSymbol.RDOC, chainId) | ||
|
||
const defaultOrder = [rif, usdrif, rbtc, btc, rdoc] | ||
|
||
return balances.sort((a, b) => { | ||
const symbolA = getTokenSymbolByChainId(a.symbol, chainId) | ||
const symbolB = getTokenSymbolByChainId(b.symbol, chainId) | ||
const indexA = defaultOrder.indexOf(symbolA) | ||
const indexB = defaultOrder.indexOf(symbolB) | ||
|
||
if (indexA !== -1 && indexB !== -1) { | ||
return indexA - indexB | ||
} | ||
if (indexA !== -1) { | ||
return -1 | ||
} | ||
if (indexB !== -1) { | ||
return 1 | ||
} | ||
if (symbolA < symbolB) { | ||
return -1 | ||
} | ||
if (symbolA > symbolB) { | ||
return 1 | ||
} | ||
return 0 | ||
}) | ||
} |
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