-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
US-2128: Change the order of tokens list to match the following sequence: RIF, USDRIF, RBTC, BTC, RDOC & others #886
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
57439b4
sort tokens by symbol and define default tokens
rodrigoncalves b8b7826
define a new type TokenOrBitcoinNetwork
rodrigoncalves 5b864b4
wrap with Number instead
rodrigoncalves e68ee07
fix imports
rodrigoncalves 3a21f4a
fix import
rodrigoncalves 25b944e
get back symbol as string
rodrigoncalves 7a4a3aa
remove token filtering
rodrigoncalves f4807cf
change sorting balances approach
rodrigoncalves 329363c
delete unused file
rodrigoncalves 18c83bb
some adjustments
rodrigoncalves File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, getTokenByChainId } 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 = getTokenByChainId(TokenSymbol.RIF, chainId) | ||
const usdrif = getTokenByChainId(TokenSymbol.USDRIF, chainId) | ||
const rbtc = getTokenByChainId(TokenSymbol.RBTC, chainId) | ||
const btc = getTokenByChainId(TokenSymbol.BTC, chainId) | ||
const rdoc = getTokenByChainId(TokenSymbol.RDOC, chainId) | ||
|
||
const defaultOrder = [rif, usdrif, rbtc, btc, rdoc] | ||
|
||
return balances.sort((a, b) => { | ||
const symbolA = getTokenByChainId(a.symbol, chainId) | ||
const symbolB = getTokenByChainId(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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ import { | |
ViewStyle, | ||
} from 'react-native' | ||
|
||
import { ChainID } from 'lib/eoaWallet' | ||
|
||
import { FrownFaceIcon } from 'components/icons' | ||
import { sharedColors } from 'shared/constants' | ||
interface Props { | ||
|
@@ -277,3 +279,24 @@ export const getIconSource = ( | |
return undefined | ||
} | ||
} | ||
|
||
export const getTokenByChainId = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, done. |
||
symbol: string | TokenSymbol, | ||
chainId: ChainID, | ||
) => { | ||
const upperSymbol = symbol.toUpperCase() | ||
const isMainnet = chainId === 30 | ||
switch (upperSymbol) { | ||
case 'RIF': | ||
case 'TRIF': | ||
return isMainnet ? TokenSymbol.RIF : TokenSymbol.TRIF | ||
case 'RBTC': | ||
case 'TRBTC': | ||
return isMainnet ? TokenSymbol.RBTC : TokenSymbol.TRBTC | ||
case 'BTC': | ||
case 'BTCT': | ||
return isMainnet ? TokenSymbol.BTC : TokenSymbol.BTCT | ||
default: | ||
return TokenSymbol[upperSymbol as keyof typeof TokenSymbol] || upperSymbol | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better if we use
getCurrentChainId
since anytime we switch networks we modify this, it will make thechainId
fetching more consistent and it can be used everywhere.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done