-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
388 additions
and
417 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,39 @@ | ||
import type { MarketData } from '@shared/models/market.model'; | ||
import type { Money } from '@shared/models/money.model'; | ||
|
||
import { baseCurrencyAmountInQuote } from './money/calculate-money'; | ||
import { i18nFormatCurrency } from './money/format-money'; | ||
import { isMoneyGreaterThanZero } from './money/money.utils'; | ||
|
||
export function sortAssetsByName<T extends { name: string }[]>(assets: T) { | ||
return assets | ||
.sort((a, b) => { | ||
if (a.name < b.name) return -1; | ||
if (a.name > b.name) return 1; | ||
return 0; | ||
}) | ||
.sort((a, b) => { | ||
if (a.name === 'STX') return -1; | ||
if (b.name !== 'STX') return 1; | ||
return 0; | ||
}) | ||
.sort((a, b) => { | ||
if (a.name === 'BTC') return -1; | ||
if (b.name !== 'BTC') return 1; | ||
return 0; | ||
}); | ||
} | ||
|
||
export function migratePositiveAssetBalancesToTop<T extends { balance: Money }[]>(assets: T) { | ||
const assetsWithPositiveBalance = assets.filter(asset => asset.balance.amount.isGreaterThan(0)); | ||
const assetsWithZeroBalance = assets.filter(asset => asset.balance.amount.isEqualTo(0)); | ||
return [...assetsWithPositiveBalance, ...assetsWithZeroBalance] as T; | ||
} | ||
|
||
export function convertAssetBalanceToFiat< | ||
T extends { balance: Money | null; marketData: MarketData | null }, | ||
>(asset: T) { | ||
if (!asset.marketData || !asset.balance || !isMoneyGreaterThanZero(asset.marketData.price)) | ||
return ''; | ||
return i18nFormatCurrency(baseCurrencyAmountInQuote(asset.balance, asset.marketData)); | ||
} |
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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
src/app/common/money/is-money.ts → src/app/common/money/money.utils.ts
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,7 +1,14 @@ | ||
import BigNumber from 'bignumber.js'; | ||
|
||
import { Money } from '@shared/models/money.model'; | ||
import { isObject } from '@shared/utils'; | ||
|
||
export function isMoney(val: unknown): val is Money { | ||
if (!isObject(val)) return false; | ||
return 'amount' in val && 'symbol' in val && 'decimals' in val; | ||
} | ||
|
||
export function isMoneyGreaterThanZero(money: Money) { | ||
if (!BigNumber.isBigNumber(money.amount)) return; | ||
return !(money.amount.isNaN() || money.amount.isZero()); | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.