-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3491 from Cryptorubic/new-all-chains
New all chains
- Loading branch information
Showing
18 changed files
with
2,207 additions
and
2,205 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { TokenAddress } from '@app/features/trade/components/assets-selector/services/tokens-list-service/models/tokens-list'; | ||
import { Token } from '@app/shared/models/tokens/token'; | ||
import { TokenAmount } from '@app/shared/models/tokens/token-amount'; | ||
import { isTokenAmount } from '@app/shared/utils/is-token'; | ||
import { compareAddresses } from '@app/shared/utils/utils'; | ||
import BigNumber from 'bignumber.js'; | ||
import { List } from 'immutable'; | ||
import { BLOCKCHAIN_NAME, EvmWeb3Pure } from 'rubic-sdk'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class TokenConvertersService { | ||
constructor() {} | ||
|
||
/** | ||
* from https://assets.rubic.exchange/assets/ethereum-pow/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48/logo.png | ||
* @returns ethereum-pow/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48/logo.png | ||
*/ | ||
public getTokenKeyInMap(t: Token): string { | ||
// show only one native token in selector for METIS | ||
if ( | ||
t.address === BLOCKCHAIN_NAME.METIS && | ||
(compareAddresses(t.address, EvmWeb3Pure.nativeTokenAddress) || | ||
compareAddresses(t.address, '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000')) | ||
) { | ||
return `METIS_NATIVE`; | ||
} | ||
|
||
const splitted = t.image.split('/'); | ||
const imgKey = splitted.slice(splitted.length - 3).join('/'); | ||
return imgKey; | ||
} | ||
|
||
public convertTokensListToMap( | ||
tokensWithBalances: List<TokenAmount | Token> | ||
): Map<TokenAddress, TokenAmount> { | ||
const tokensWithBalancesMap = new Map<TokenAddress, TokenAmount>(); | ||
tokensWithBalances.forEach((t: TokenAmount | Token) => { | ||
if (isTokenAmount(t)) { | ||
tokensWithBalancesMap.set(this.getTokenKeyInMap(t), t); | ||
} else { | ||
const tokenAmount = { amount: new BigNumber(NaN), favorite: false, ...t } as TokenAmount; | ||
tokensWithBalancesMap.set(this.getTokenKeyInMap(tokenAmount), tokenAmount); | ||
} | ||
}); | ||
|
||
return tokensWithBalancesMap; | ||
} | ||
} |
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.