generated from MetaMask/metamask-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add currency and abstract value to support international cu…
…rrencies and stablecoins
- Loading branch information
1 parent
8ca3519
commit 2da1d1b
Showing
3 changed files
with
32 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { ExchangeIndexQuoteCurrencies } from '../constants'; | ||
import type { Exchange } from '../database'; | ||
|
||
export const FeeAsset = 'SOL'; | ||
|
@@ -6,3 +7,26 @@ export const getFeeAddress = (exchangeType: Exchange['type']) => | |
exchangeType === 'coinbase' | ||
? '[email protected]' | ||
: '7cbDHP5ksonpWJXmTWGsuD8yKVTxC4RfZ26JCYbSxRqX'; | ||
|
||
/** | ||
* Returns a base and quote asset from a non-delimited string. | ||
* @param exchangeType - The exchange the string came from. | ||
* @param symbol - The combined asset pair string. | ||
* @returns The base and quote assets. | ||
*/ | ||
export const parseAssetsFromCombinedSymbol = ( | ||
exchangeType: Exchange['type'], | ||
symbol: string, | ||
): { baseAsset: string; quoteAsset: string } => { | ||
let baseAsset = symbol.toUpperCase(); | ||
let quoteAsset = ''; | ||
|
||
for (const currency in ExchangeIndexQuoteCurrencies[exchangeType]) { | ||
if (baseAsset.includes(currency)) { | ||
quoteAsset = currency; | ||
baseAsset = baseAsset.replace(currency, ''); | ||
} | ||
} | ||
|
||
return { baseAsset, quoteAsset }; | ||
}; |