diff --git a/package.json b/package.json index 167c689..3d18ecf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@normalfinance/utils", - "version": "1.6.2", + "version": "1.6.3", "description": "A Typescript modules for frequently used types, utilities, constants, and more across Normal repositories.", "homepage": "https://github.com/normalfinance/utils#readme", "bugs": { @@ -46,7 +46,8 @@ "lint:misc": "prettier '**/*.json' '**/*.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern", "prepack": "./scripts/prepack.sh", "test": "jest && jest-it-up", - "test:watch": "jest --watch" + "test:watch": "jest --watch", + "publish": "npm publish --access public" }, "dependencies": { "customerio-node": "^4.1.1", diff --git a/src/types/exchange.ts b/src/types/exchange.ts index ac4fe40..827a70c 100644 --- a/src/types/exchange.ts +++ b/src/types/exchange.ts @@ -5,9 +5,11 @@ export type ExchangeBalance = { asset: string; amount: string; }; + export type PortfolioItem = ExchangeBalance & { + currency: string; price: string; - usdValue: string; + value: string; oneHourChange: string; oneDayChange: string; oneWeekChange: string; @@ -21,7 +23,8 @@ export type ExchangeOrder = { orderId: string; side: string; amount: string; - usdValue: string; + currency: string; + value: string; price: string; fee: string; status: string; diff --git a/src/utils/exchange.ts b/src/utils/exchange.ts index f9bd591..ea834d4 100644 --- a/src/utils/exchange.ts +++ b/src/utils/exchange.ts @@ -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' ? 'billing@normalfinance.io' : '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 }; +};