diff --git a/CHANGELOG.md b/CHANGELOG.md index 96fe765bc1..d6c06ec063 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## Unreleased +- Improve sats amount readability adding thousands separator + ## 4.37.0 - Bundle BitBox02 firmware version v9.14.0 - Enable auto HiDPI scaling to correctly manage scale factor on high density screens diff --git a/frontends/web/src/api/account.ts b/frontends/web/src/api/account.ts index 3897e41232..36e154cff7 100644 --- a/frontends/web/src/api/account.ts +++ b/frontends/web/src/api/account.ts @@ -25,13 +25,7 @@ export type Fiat = 'AUD' | 'BRL' | 'BTC' | 'CAD' | 'CHF' | 'CNY' | 'EUR' | 'GBP' export type ConversionUnit = Fiat | 'sat' -export type MainnetCoin = 'BTC' | 'LTC' | 'ETH'; - -export type TestnetCoin = 'TBTC' | 'TLTC' | 'GOETH'; - -export type Coin = MainnetCoin | TestnetCoin; - -export type CoinWithSAT = Coin | 'sat' | 'tsat'; +export type CoinUnit = 'BTC' | 'sat' | 'LTC' | 'ETH' | 'TBTC' | 'tsat' | 'TLTC' | 'GOETH'; export interface IActiveToken { tokenCode: string; @@ -141,7 +135,7 @@ export type Conversions = { export interface IAmount { amount: string; conversions?: Conversions; - unit: Coin; + unit: CoinUnit; } export interface IBalance { diff --git a/frontends/web/src/components/amount/amount.module.css b/frontends/web/src/components/amount/amount.module.css new file mode 100644 index 0000000000..c19f1a5bf2 --- /dev/null +++ b/frontends/web/src/components/amount/amount.module.css @@ -0,0 +1,3 @@ +.space { + margin-left: 0.5ch; +} diff --git a/frontends/web/src/components/amount/amount.test.tsx b/frontends/web/src/components/amount/amount.test.tsx new file mode 100644 index 0000000000..8f9d07ac26 --- /dev/null +++ b/frontends/web/src/components/amount/amount.test.tsx @@ -0,0 +1,179 @@ +/** + * Copyright 2023 Shift Crypto AG + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { render } from '@testing-library/react'; +import { Amount } from './amount'; +import { CoinUnit, ConversionUnit } from './../../api/account'; + +describe('Amount formatting', () => { + + describe('sat amounts', () => { + let coins: CoinUnit[] = ['sat', 'tsat']; + coins.forEach(coin => { + it('12345678901234 ' + coin + ' with removeBtcTrailingZeroes enabled gets spaced', () => { + const { getByTestId } = render(); + const blocks = getByTestId('amountBlocks'); + expect(blocks.innerHTML).toBe( + '12' + + '345' + + '678' + + '901' + + '234'); + }); + + it('1234567 ' + coin + ' with removeBtcTrailingZeroes enabled gets spaced', () => { + const { getByTestId } = render(); + const blocks = getByTestId('amountBlocks'); + expect(blocks.innerHTML).toBe( + '1' + + '234' + + '567'); + }); + + it('12345 ' + coin + ' with removeBtcTrailingZeroes enabled gets spaced', () => { + const { getByTestId } = render(); + const blocks = getByTestId('amountBlocks'); + expect(blocks.innerHTML).toBe( + '12' + + '345'); + }); + + it('21 ' + coin + ' with removeBtcTrailingZeroes enabled gets spaced', () => { + const { getByTestId } = render(); + const blocks = getByTestId('amountBlocks'); + expect(blocks.innerHTML).toBe('21'); + }); + + it('12345678901234 ' + coin + ' with removeBtcTrailingZeroes disabled gets spaced', () => { + const { getByTestId } = render(); + const blocks = getByTestId('amountBlocks'); + expect(blocks.innerHTML).toBe( + '12' + + '345' + + '678' + + '901' + + '234'); + }); + + it('1234567 ' + coin + ' with removeBtcTrailingZeroes disabled gets spaced', () => { + const { getByTestId } = render(); + const blocks = getByTestId('amountBlocks'); + expect(blocks.innerHTML).toBe( + '1' + + '234' + + '567'); + }); + + it('12345 ' + coin + ' with removeBtcTrailingZeroes disabled gets spaced', () => { + const { getByTestId } = render(); + const blocks = getByTestId('amountBlocks'); + expect(blocks.innerHTML).toBe( + '12' + + '345'); + }); + + it('21 ' + coin + ' with removeBtcTrailingZeroes disabled gets spaced', () => { + const { getByTestId } = render(); + const blocks = getByTestId('amountBlocks'); + expect(blocks.innerHTML).toBe('21'); + }); + }); + }); + + describe('BTC/LTC coins amounts', () => { + let coins: CoinUnit[] = ['BTC', 'TBTC', 'LTC', 'TLTC']; + coins.forEach(coin => { + it('10.00000000 ' + coin + ' with removeBtcTrailingZeroes enabled becomes 10', () => { + const { container } = render(); + expect(container).toHaveTextContent('10'); + }); + it('10.12300000 ' + coin + ' with removeBtcTrailingZeroes enabled becomes 10.123', () => { + const { container } = render(); + expect(container).toHaveTextContent('10.123'); + }); + it('42 ' + coin + ' with removeBtcTrailingZeroes enabled stays 42', () => { + const { container } = render(); + expect(container).toHaveTextContent('42'); + }); + it('10.00000000 ' + coin + ' with removeBtcTrailingZeroes disabled stays 10.00000000', () => { + const { container } = render(); + expect(container).toHaveTextContent('10.00000000'); + }); + it('10.12300000 ' + coin + ' with removeBtcTrailingZeroes disabled stays 10.12300000', () => { + const { container } = render(); + expect(container).toHaveTextContent('10.12300000'); + }); + it('42 ' + coin + ' with removeBtcTrailingZeroes disabled stays 42', () => { + const { container } = render(); + expect(container).toHaveTextContent('42'); + }); + + }); + }); + + describe('non BTC coins amounts', () => { + let coins: CoinUnit[] = ['ETH', 'GOETH']; + coins.forEach(coin => { + it('10.00000000 ' + coin + ' with removeBtcTrailingZeroes enabled stays 10.00000000', () => { + const { container } = render(); + expect(container).toHaveTextContent('10.00000000'); + }); + it('10.12300000 ' + coin + ' with removeBtcTrailingZeroes enabled stays 10.12300000', () => { + const { container } = render(); + expect(container).toHaveTextContent('10.12300000'); + }); + it('42 ' + coin + ' with removeBtcTrailingZeroes enabled stays 42', () => { + const { container } = render(); + expect(container).toHaveTextContent('42'); + }); + it('10.00000000 ' + coin + ' with removeBtcTrailingZeroes disabled stays 10.00000000', () => { + const { container } = render(); + expect(container).toHaveTextContent('10.00000000'); + }); + it('10.12300000 ' + coin + ' with removeBtcTrailingZeroes disabled stays 10.12300000', () => { + const { container } = render(); + expect(container).toHaveTextContent('10.12300000'); + }); + it('42 ' + coin + ' with removeBtcTrailingZeroes disabled stays 42', () => { + const { container } = render(); + expect(container).toHaveTextContent('42'); + }); + }); + }); + + describe('fiat amounts', () => { + let fiatCoins: ConversionUnit[] = ['USD', 'EUR', 'CHF']; + fiatCoins.forEach(coin => { + it('1\'340.25 ' + coin + ' with removeBtcTrailingZeroes enabled stays 1\'340.25', () => { + const { container } = render(); + expect(container).toHaveTextContent('1\'340.25'); + }); + it('218.00 ' + coin + ' with removeBtcTrailingZeroes enabled stays 218.00', () => { + const { container } = render(); + expect(container).toHaveTextContent('218.00'); + }); + it('1\'340.25 ' + coin + ' with removeBtcTrailingZeroes disabled stays 1\'340.25', () => { + const { container } = render(); + expect(container).toHaveTextContent('1\'340.25'); + }); + it('218.00 ' + coin + ' with removeBtcTrailingZeroes disabled stays 218.00', () => { + const { container } = render(); + expect(container).toHaveTextContent('218.00'); + }); + + }); + }); +}); diff --git a/frontends/web/src/components/amount/amount.tsx b/frontends/web/src/components/amount/amount.tsx new file mode 100644 index 0000000000..43f10691e2 --- /dev/null +++ b/frontends/web/src/components/amount/amount.tsx @@ -0,0 +1,58 @@ +/** + * Copyright 2023 Shift Crypto AG + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import style from './amount.module.css'; +import { CoinUnit, ConversionUnit } from './../../api/account'; + +type TProps = { + amount: string; + unit: CoinUnit | ConversionUnit; + removeBtcTrailingZeroes?: boolean; +}; + +export const Amount = ({ amount, unit, removeBtcTrailingZeroes }: TProps) => { + const formatSats = (amount: string): JSX.Element => { + const blocks: JSX.Element[] = []; + const blockSize = 3; + + for (let i = amount.length; i > 0 ; i -= blockSize) { + const start = Math.max(0, i - blockSize); + + blocks.push( + + {amount.slice(start, i)} + + ); + } + + return {blocks.reverse()}; + }; + + switch (unit) { + case 'BTC': + case 'TBTC': + case 'LTC': + case 'TLTC': + if (removeBtcTrailingZeroes && amount.includes('.')) { + return <>{amount.replace(/\.?0+$/, '')}; + } + break; + case 'sat': + case 'tsat': + return formatSats(amount); + } + return <>{amount}; + +}; diff --git a/frontends/web/src/components/balance/balance.tsx b/frontends/web/src/components/balance/balance.tsx index ff9c5427c3..374848dfd9 100644 --- a/frontends/web/src/components/balance/balance.tsx +++ b/frontends/web/src/components/balance/balance.tsx @@ -1,6 +1,6 @@ /** * Copyright 2018 Shift Devices AG - * Copyright 2021 Shift Crypto AG + * Copyright 2023 Shift Crypto AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ import { useTranslation } from 'react-i18next'; import { IBalance } from '../../api/account'; import { FiatConversion } from '../../components/rates/rates'; -import { bitcoinRemoveTrailingZeroes } from '../../utils/trailing-zeroes'; +import { Amount } from '../../components/amount/amount'; import style from './balance.module.css'; type TProps = { @@ -37,16 +37,17 @@ export const Balance = ({ ); } - // remove trailing zeroes from Bitcoin balance - const availableBalance = bitcoinRemoveTrailingZeroes(balance.available.amount, balance.available.unit); - const incomingBalance = bitcoinRemoveTrailingZeroes(balance.incoming.amount, balance.incoming.unit); - return (
- + @@ -54,11 +55,18 @@ export const Balance = ({
{availableBalance} + + {balance.available.unit}
{ balance.hasIncoming && ( -

- {t('account.incoming')} +{incomingBalance} {balance.incoming.unit} / - - {' '} - +

+ {t('account.incoming')} + + + + {' '}{balance.incoming.unit} / + + {' '} + +

) diff --git a/frontends/web/src/components/rates/rates.tsx b/frontends/web/src/components/rates/rates.tsx index 5d0ae6fe49..c29d31ad35 100644 --- a/frontends/web/src/components/rates/rates.tsx +++ b/frontends/web/src/components/rates/rates.tsx @@ -21,7 +21,7 @@ import { reinitializeAccounts } from '../../api/backend'; import { share } from '../../decorators/share'; import { Store } from '../../decorators/store'; import { setConfig } from '../../utils/config'; -import { bitcoinRemoveTrailingZeroes } from '../../utils/trailing-zeroes'; +import { Amount } from '../../components/amount/amount'; import { equal } from '../../utils/equal'; import { apiGet } from '../../utils/request'; import style from './rates.module.css'; @@ -128,27 +128,25 @@ function Conversion({ btcUnit, }: TProps) { - let formattedValue = '---'; + let formattedAmount = <>{'---'}; let isAvailable = false; + var activeUnit: ConversionUnit = active; + if (active === 'BTC' && btcUnit === 'sat') { + activeUnit = 'sat'; + } + // amount.conversions[active] can be empty in recent transactions. if (amount && amount.conversions && amount.conversions[active] && amount.conversions[active] !== '') { isAvailable = true; - formattedValue = amount.conversions[active]; - if (noBtcZeroes) { - formattedValue = bitcoinRemoveTrailingZeroes(formattedValue, active); - } + formattedAmount = ; } - var activeUnit: ConversionUnit = active; - if (active === 'BTC' && btcUnit === 'sat') { - activeUnit = 'sat'; - } if (tableRow) { return ( - {formattedValue} + {formattedAmount} { !noAction && ( {activeUnit} @@ -165,7 +163,7 @@ function Conversion({ return ( {isAvailable ? sign : ''} - {formattedValue} + {formattedAmount} {' '} { !skipUnit && !noAction && ( diff --git a/frontends/web/src/components/transactions/transaction.tsx b/frontends/web/src/components/transactions/transaction.tsx index 7894b8a7b0..0881577031 100644 --- a/frontends/web/src/components/transactions/transaction.tsx +++ b/frontends/web/src/components/transactions/transaction.tsx @@ -25,6 +25,7 @@ import { CopyableInput } from '../copy/Copy'; import { Edit, EditLight, ExpandIcon, Save, SaveLight } from '../icon/icon'; import { ProgressRing } from '../progressRing/progressRing'; import { FiatConversion } from '../rates/rates'; +import { Amount } from '../../components/amount/amount'; import { ArrowIn, ArrowOut, ArrowSelf } from './components/icons'; import style from './transaction.module.css'; import parentStyle from './transactions.module.css'; @@ -214,7 +215,8 @@ class Transaction extends Component { - {sign}{amount.amount} + {sign} +  {amount.unit} @@ -312,7 +314,10 @@ class Transaction extends Component {

- {sign}{amount.amount} + + {sign} + + {' '} {transactionInfo.amount.unit}

@@ -322,7 +327,7 @@ class Transaction extends Component { { transactionInfo.fee && transactionInfo.fee.amount ? (

- {transactionInfo.fee.amount} + {' '} {transactionInfo.fee.unit}

diff --git a/frontends/web/src/routes/account/info/buyReceiveCTA.tsx b/frontends/web/src/routes/account/info/buyReceiveCTA.tsx index b19d8ab05f..3f4c4799ad 100644 --- a/frontends/web/src/routes/account/info/buyReceiveCTA.tsx +++ b/frontends/web/src/routes/account/info/buyReceiveCTA.tsx @@ -16,7 +16,7 @@ import { useTranslation } from 'react-i18next'; import { route } from '../../../utils/route'; -import { CoinWithSAT, IBalance } from '../../../api/account'; +import { CoinUnit, IBalance } from '../../../api/account'; import { Button } from '../../../components/forms'; import { Balances } from '../summary/accountssummary'; import styles from './buyReceiveCTA.module.css'; @@ -29,7 +29,7 @@ type TBuyReceiveCTAProps = { }; export const BuyReceiveCTA = ({ code, unit, balanceList }: TBuyReceiveCTAProps) => { - const formattedUnit = isBitcoinCoin(unit as CoinWithSAT) ? 'BTC' : unit; + const formattedUnit = isBitcoinCoin(unit as CoinUnit) ? 'BTC' : unit; const { t } = useTranslation(); const onBuyCTA = () => route(code ? `/buy/info/${code}` : '/buy/info'); const onReceiveCTA = () => { diff --git a/frontends/web/src/routes/account/send/send.tsx b/frontends/web/src/routes/account/send/send.tsx index c32fae2e73..75c9d13a1f 100644 --- a/frontends/web/src/routes/account/send/send.tsx +++ b/frontends/web/src/routes/account/send/send.tsx @@ -1,6 +1,6 @@ /** * Copyright 2018 Shift Devices AG - * Copyright 2022 Shift Crypto AG + * Copyright 2023 Shift Crypto AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,6 +39,7 @@ import { WaitDialog } from '../../../components/wait-dialog/wait-dialog'; import { translate, TranslateProps } from '../../../decorators/translate'; import { debug } from '../../../utils/env'; import { apiGet, apiPost } from '../../../utils/request'; +import { Amount } from '../../../components/amount/amount'; import { apiWebsocket } from '../../../utils/websocket'; import { isBitcoinBased, customFeeUnit, isBitcoinOnly, findAccount } from '../utils'; import { FeeTargets } from './feetargets'; @@ -771,14 +772,18 @@ class Send extends Component {

- {(proposedAmount && proposedAmount.amount) || 'N/A'} + {(proposedAmount && + ) || 'N/A'} {' '} {(proposedAmount && proposedAmount.unit) || 'N/A'} { proposedAmount && proposedAmount.conversions && ( - / {proposedAmount.conversions[fiatUnit]} {baseCurrencyUnit} - ) + + / + + {' '}{baseCurrencyUnit} + ) }

@@ -792,14 +797,16 @@ class Send extends Component {

- {(proposedFee && proposedFee.amount) || 'N/A'} + {(proposedFee && + ) || 'N/A'} {' '} {(proposedFee && proposedFee.unit) || 'N/A'} {proposedFee && proposedFee.conversions && ( / - {proposedFee.conversions[fiatUnit]} {baseCurrencyUnit} + + {' '}{baseCurrencyUnit} )} {customFee ? ( @@ -826,12 +833,19 @@ class Send extends Component {

- {(proposedTotal && proposedTotal.amount) || 'N/A'} + + {(proposedTotal && + ) || 'N/A'} + {' '} {(proposedTotal && proposedTotal.unit) || 'N/A'} {(proposedTotal && proposedTotal.conversions) && ( - / {proposedTotal.conversions[fiatUnit]} {baseCurrencyUnit} + + / + + {' '}{baseCurrencyUnit} + )}

diff --git a/frontends/web/src/routes/account/send/utxos.tsx b/frontends/web/src/routes/account/send/utxos.tsx index 827d9ee481..08e1ef94c8 100644 --- a/frontends/web/src/routes/account/send/utxos.tsx +++ b/frontends/web/src/routes/account/send/utxos.tsx @@ -28,6 +28,7 @@ import A from '../../../components/anchor/anchor'; import { Dialog } from '../../../components/dialog/dialog'; import { Button, Checkbox } from '../../../components/forms'; import { ExpandOpen } from '../../../components/icon'; +import { Amount } from '../../../components/amount/amount'; import { FiatConversion } from '../../../components/rates/rates'; import { getScriptName } from '../utils'; import style from './utxos.module.css'; @@ -100,7 +101,7 @@ export const UTXOs = ({
- {utxo.amount.amount} + {' '} {utxo.amount.unit} diff --git a/frontends/web/src/routes/account/summary/accountssummary.tsx b/frontends/web/src/routes/account/summary/accountssummary.tsx index 7e30e48531..8ee79bc4a5 100644 --- a/frontends/web/src/routes/account/summary/accountssummary.tsx +++ b/frontends/web/src/routes/account/summary/accountssummary.tsx @@ -33,6 +33,7 @@ import { AddBuyReceiveOnEmptyBalances } from '../info/buyReceiveCTA'; import { apiPost } from '../../../utils/request'; import style from './accountssummary.module.css'; import { route } from '../../../utils/route'; +import { Amount } from '../../../components/amount/amount'; import { Skeleton } from '../../../components/skeleton/skeleton'; interface AccountSummaryProps { @@ -214,7 +215,7 @@ class AccountsSummary extends Component { { nameCol } - {balance.available.amount}{' '} + {' '} {balance.available.unit} @@ -262,7 +263,9 @@ class AccountsSummary extends Component { { nameCol } - {balance.amount} + + + {' '} {balance.unit} @@ -363,7 +366,7 @@ class AccountsSummary extends Component { {(data && data.formattedChartTotal !== null) ? ( <> - {data.formattedChartTotal} + {' '} diff --git a/frontends/web/src/routes/account/summary/chart.tsx b/frontends/web/src/routes/account/summary/chart.tsx index 142decc1dc..b98d67675c 100644 --- a/frontends/web/src/routes/account/summary/chart.tsx +++ b/frontends/web/src/routes/account/summary/chart.tsx @@ -1,5 +1,5 @@ /** - * Copyright 2020 Shift Crypto AG + * Copyright 2023 Shift Crypto AG * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ import { ISummary } from '../../../api/account'; import { translate, TranslateProps } from '../../../decorators/translate'; import { Skeleton } from '../../../components/skeleton/skeleton'; import { formatNumber } from '../../../components/rates/rates'; -import { bitcoinRemoveTrailingZeroes } from '../../../utils/trailing-zeroes'; +import { Amount } from '../../../components/amount/amount'; import styles from './chart.module.css'; import Filters from './filters'; import { getDarkmode } from '../../../components/darkmode/darkmode'; @@ -471,7 +471,7 @@ class Chart extends Component {
{formattedChartTotal !== null ? ( // remove trailing zeroes for BTC fiat total - bitcoinRemoveTrailingZeroes(!showMobileTotalValue ? formattedChartTotal : toolTipValue, chartFiat) + ) : ( )} @@ -522,7 +522,7 @@ class Chart extends Component { {toolTipValue !== undefined ? (

- {toolTipValue} + {chartFiat}

diff --git a/frontends/web/src/routes/account/utils.ts b/frontends/web/src/routes/account/utils.ts index b2d0e3642c..ed19f7c30f 100644 --- a/frontends/web/src/routes/account/utils.ts +++ b/frontends/web/src/routes/account/utils.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { CoinCode, ScriptType, IAccount, CoinWithSAT } from '../../api/account'; +import { CoinCode, ScriptType, IAccount, CoinUnit } from '../../api/account'; export function findAccount(accounts: IAccount[], accountCode: string): IAccount | undefined { return accounts.find(({ code }) => accountCode === code); @@ -38,7 +38,7 @@ export function isBitcoinOnly(coinCode: CoinCode): boolean { } } -export const isBitcoinCoin = (coin: CoinWithSAT) => (coin === 'BTC') || (coin === 'TBTC') || (coin === 'sat') || (coin === 'tsat'); +export const isBitcoinCoin = (coin: CoinUnit) => (coin === 'BTC') || (coin === 'TBTC') || (coin === 'sat') || (coin === 'tsat'); export function isBitcoinBased(coinCode: CoinCode): boolean { switch (coinCode) { diff --git a/frontends/web/src/utils/trailing-zeroes.test.tsx b/frontends/web/src/utils/trailing-zeroes.test.tsx deleted file mode 100644 index a6a39beda2..0000000000 --- a/frontends/web/src/utils/trailing-zeroes.test.tsx +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright 2022 Shift Crypto AG - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { bitcoinRemoveTrailingZeroes } from '../../src/utils/trailing-zeroes'; - -describe('removeTrailingZeroes', () => { - let coins; - - describe('coins that need to remove trailing zeroes', () => { - coins = ['BTC', 'TBTC', 'LTC', 'TLTC']; - coins.forEach(coin => { - it('10.00000000 ' + coin + ' becomes 10', () => { - expect(bitcoinRemoveTrailingZeroes('10.00000000', coin)).toBe('10'); - }); - it('10.12300000 ' + coin + ' becomes 10.123', () => { - expect(bitcoinRemoveTrailingZeroes('10.12300000', coin)).toBe('10.123'); - }); - it('42 ' + coin + ' stays 42', () => { - expect(bitcoinRemoveTrailingZeroes('42', coin)).toBe('42'); - }); - }); - }); - - describe('coins that don\'t need to remove trailing zeroes', () => { - coins = ['ETH', 'GOETH']; - coins.forEach(coin => { - it('10.00000000 ' + coin + ' stays 10.00000000', () => { - expect(bitcoinRemoveTrailingZeroes('10.00000000', coin)).toBe('10.00000000'); - }); - it('10.12300000 ' + coin + ' stays 10.12300000', () => { - expect(bitcoinRemoveTrailingZeroes('10.12300000', coin)).toBe('10.12300000'); - }); - it('42 ' + coin + ' stays 42', () => { - expect(bitcoinRemoveTrailingZeroes('42', coin)).toBe('42'); - }); - }); - }); - -}); diff --git a/frontends/web/src/utils/trailing-zeroes.ts b/frontends/web/src/utils/trailing-zeroes.ts deleted file mode 100644 index 9f85359011..0000000000 --- a/frontends/web/src/utils/trailing-zeroes.ts +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright 2022 Shift Crypto AG - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export function bitcoinRemoveTrailingZeroes(amount: string, unit: string): string { - if (amount.includes('.')) { - switch (unit) { - case 'BTC': - case 'TBTC': - case 'LTC': - case 'TLTC': - return amount.replace(/\.?0+$/, ''); - default: - } - } - return amount; -} - -