Skip to content

Commit ef66f74

Browse files
committed
fix: remove fixed precision on Ada and fiat values
- Ada has a 6 decimal point precision, but currently we're rounding to 2 - For consistency this change also now only shows decimals when needed, Since displaying 6 decimal points on all Ada values is not ideal.
1 parent 48a74ad commit ef66f74

File tree

9 files changed

+20
-28
lines changed

9 files changed

+20
-28
lines changed

apps/browser-extension-wallet/src/api/__tests__/input-output-transformer.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('Testing inputOutputTransformer function', () => {
3232
expect(result.addr).toEqual(
3333
'addr_test1qz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3jcu5d8ps7zex2k2xt3uqxgjqnnj83ws8lhrn648jjxtwq2ytjqp'
3434
);
35-
expect(result.amount).toBe('1.00');
35+
expect(result.amount).toBe('1');
3636
expect(result.assetList.length).toEqual(0);
3737
});
3838

@@ -46,7 +46,7 @@ describe('Testing inputOutputTransformer function', () => {
4646
expect(result.addr).toEqual(
4747
'addr_test1qz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3jcu5d8ps7zex2k2xt3uqxgjqnnj83ws8lhrn648jjxtwq2ytjqp'
4848
);
49-
expect(result.amount).toBe('3.00');
49+
expect(result.amount).toBe('3');
5050
expect(result.assetList.length).toEqual(0);
5151
});
5252

@@ -66,7 +66,7 @@ describe('Testing inputOutputTransformer function', () => {
6666
expect(result.addr).toEqual(
6767
'addr_test1qz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3jcu5d8ps7zex2k2xt3uqxgjqnnj83ws8lhrn648jjxtwq2ytjqp'
6868
);
69-
expect(result.amount).toBe('3.00');
69+
expect(result.amount).toBe('3');
7070
expect(result.assetList.length).toEqual(1);
7171
});
7272
});

apps/browser-extension-wallet/src/api/__tests__/wallet-balance-transformer.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { walletBalanceTransformer } from '../transformers';
55
describe('Testing walletBalanceTransformer function', () => {
66
test('given a wallet balance in lovelace should return the balance in ada and undefined for fiat', () => {
77
const result = walletBalanceTransformer('10000000');
8-
expect(result.coinBalance).toBe('10.00');
8+
expect(result.coinBalance).toBe('10');
99
expect(result.fiatBalance).toBeUndefined();
1010
});
1111

1212
test('given a wallet balance in lovelace and a fiat price should return the balance in ada and in fiat', () => {
1313
const result = walletBalanceTransformer('10000000', 2);
14-
expect(result.coinBalance).toBe('10.00');
14+
expect(result.coinBalance).toBe('10');
1515
expect(result.fiatBalance).toBe('20.00');
1616
});
1717
});

apps/browser-extension-wallet/src/features/send/helpers/__tests__/transformers.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('Testing availableCoinsTransformer function', () => {
1515
const coins = availableCoinsTransformer(totalCoins.toString(), assets);
1616
expect(coins).toEqual([
1717
{
18-
balance: '10.00',
18+
balance: '10',
1919
id: '1',
2020
symbol: 'ADA'
2121
},

apps/browser-extension-wallet/src/utils/mocks/test-helpers.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ export const cardanoStakePoolSelectedDetails = {
569569
status: 'active',
570570
ticker: 'STTST',
571571
blocks: '20',
572-
pledge: '2000.00'
572+
pledge: '2000'
573573
};
574574

575575
export const transformedStakePool = {
@@ -585,7 +585,7 @@ export const transformedStakePool = {
585585
'stake_test1uqrw9tjymlm8wrwq7jk68n6v7fs9qz8z0tkdkve26dylmfc2ux2hj',
586586
'stake_test1uq7g7kqeucnqfweqzgxk3dw34e8zg4swnc7nagysug2mm4cm77jrx'
587587
],
588-
pledge: '2000.00ADA',
588+
pledge: '2000ADA',
589589
retired: false,
590590
saturation: '5.12',
591591
size: '- %',

apps/browser-extension-wallet/src/views/browser-view/features/activity/helpers/__tests__/pending-tx-transformer.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ describe('Testing tx transformers utils', () => {
117117
deposit: undefined,
118118
depositReclaim: undefined,
119119
direction: 'Outgoing',
120-
fee: '1.00',
121-
fiatAmount: '1.00 USD',
120+
fee: '1',
121+
fiatAmount: '1 USD',
122122
id: '6804edf9712d2b619edb6ac86861fe93a730693183a262b165fcc1ba1bc99cad',
123-
amount: '1.00 ADA',
123+
amount: '1 ADA',
124124
assets: [
125125
{
126126
id: '6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7',

apps/browser-extension-wallet/src/views/browser-view/features/send-transaction/components/Form/CoinInput/__tests__/util.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('CoinInput util', () => {
3131
describe('getADACoinProperties', () => {
3232
test('returns 0 for availableADA and false for hasMaxBtn when balance is 0', () => {
3333
expect(getADACoinProperties('0', '1000000', '0', '0')).toEqual({
34-
availableADA: '0.00',
34+
availableADA: '0',
3535
max: '1',
3636
hasMaxBtn: false,
3737
hasReachedMaxAmount: false,
@@ -40,7 +40,7 @@ describe('CoinInput util', () => {
4040
});
4141
test('returns 0 for max and true for hasReachedMaxAmount when spendable coins is 0', () => {
4242
expect(getADACoinProperties('1000000', '0', '0', '0')).toEqual({
43-
availableADA: '1.00',
43+
availableADA: '1',
4444
max: '0',
4545
hasMaxBtn: true,
4646
hasReachedMaxAmount: true,
@@ -49,7 +49,7 @@ describe('CoinInput util', () => {
4949
});
5050
test('returns formatted balance as availableADA, and the spendable coin in ADA as max when there is no spending', () => {
5151
expect(getADACoinProperties('20000000', '10000000', '0', '0')).toEqual({
52-
availableADA: '20.00',
52+
availableADA: '20',
5353
max: '10',
5454
hasMaxBtn: true,
5555
hasReachedMaxAmount: false,
@@ -58,7 +58,7 @@ describe('CoinInput util', () => {
5858
});
5959
test('returns the calculated max amount when there is less spent coin than spendable coin', () => {
6060
expect(getADACoinProperties('20000000', '10000000', '5', '2')).toEqual({
61-
availableADA: '20.00',
61+
availableADA: '20',
6262
max: '7',
6363
hasMaxBtn: true,
6464
hasReachedMaxAmount: false,
@@ -67,7 +67,7 @@ describe('CoinInput util', () => {
6767
});
6868
test('returns max amount as 0 and hasReachedMaxAmount as true when there is more spent coin than spendable coin', () => {
6969
expect(getADACoinProperties('20000000', '10000000', '10', '0')).toEqual({
70-
availableADA: '20.00',
70+
availableADA: '20',
7171
max: '0',
7272
hasMaxBtn: true,
7373
hasReachedMaxAmount: true,

apps/browser-extension-wallet/src/views/browser-view/features/send-transaction/components/Form/CoinInput/util.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const getADACoinProperties = (
4747
): ADARow => {
4848
// Convert to ADA
4949
const availableADA = Wallet.util.lovelacesToAdaString(balance);
50-
const spendableCoinInAda = Wallet.util.lovelacesToAdaString(spendableCoin, undefined, BigNumber.ROUND_DOWN);
50+
const spendableCoinInAda = Wallet.util.lovelacesToAdaString(spendableCoin);
5151
// Calculate max amount in ADA
5252
const max = getMaxSpendableAmount(spendableCoinInAda, spentCoins, currentSpendingAmount);
5353
return {

packages/cardano/src/wallet/util/__tests__/unit-converters.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ import {
1010
describe('Testing lovelacesToAdaString function', () => {
1111
test('should convert lovelaces to ada', async () => {
1212
const result = lovelacesToAdaString('1000000');
13-
expect(result).toBe('1.00');
14-
});
15-
16-
test('should return ada value with 4 decimals', async () => {
17-
const result = lovelacesToAdaString('1000000', 4);
18-
expect(result).toBe('1.0000');
13+
expect(result).toBe('1');
1914
});
2015
});
2116

packages/cardano/src/wallet/util/unit-converters.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ import { CoinId } from '../types';
44
const LOVELACE_VALUE = 1_000_000;
55
const DEFAULT_DECIMALS = 2;
66

7-
export const lovelacesToAdaString = (
8-
lovelaces: string,
9-
decimalValues: number = DEFAULT_DECIMALS,
10-
roudingMode: BigNumber.RoundingMode = BigNumber.ROUND_HALF_UP
11-
): string => new BigNumber(lovelaces).dividedBy(LOVELACE_VALUE).toFixed(decimalValues, roudingMode);
7+
export const lovelacesToAdaString = (lovelaces: string): string =>
8+
new BigNumber(lovelaces).dividedBy(LOVELACE_VALUE).toString();
129

1310
export const adaToLovelacesString = (ada: string): string => new BigNumber(ada).multipliedBy(LOVELACE_VALUE).toString();
1411

0 commit comments

Comments
 (0)