Skip to content

Commit 13e129f

Browse files
committed
fix: negative balance displayed as positive
1 parent bc84cfe commit 13e129f

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

app/sources/src/stores/accounts.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ const accounts = {
5050
};
5151
result[balance].denominationsAvailable[denomination].toString = () => {
5252
return denominations.get.data[balance][denomination].stringify(amountAvailable, {
53-
omitDirection: true,
53+
omitDirection: false,
54+
directionsShown: ['negative'],
5455
});
5556
};
5657

@@ -60,7 +61,8 @@ const accounts = {
6061
};
6162
result[balance].denominationsPending[denomination].toString = () => {
6263
return denominations.get.data[balance][denomination].stringify(amountPending, {
63-
omitDirection: true,
64+
omitDirection: false,
65+
directionsShown: ['negative'],
6466
});
6567
};
6668
});

app/sources/src/stores/denominations.js

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,23 @@ const denominations = {
3030
round(number) {
3131
return round(number, this.precision, this.precisionMax);
3232
},
33-
stringify(number, { omitDirection = false, omitSign = false } = {}) {
34-
return `${omitDirection ? '' : number === 0 ? '' : number > 0 ? '+ ' : '- '}${
35-
omitSign ? '' : `${this.sign} `
36-
}${this.round(Math.abs(number))
33+
stringify(
34+
number,
35+
{ omitDirection = false, omitSign = false, directionsShown = ['positive', 'negative'] } = {},
36+
) {
37+
return `${
38+
omitDirection
39+
? ''
40+
: number === 0
41+
? ''
42+
: number > 0
43+
? directionsShown.includes('positive')
44+
? '+ '
45+
: ''
46+
: directionsShown.includes('negative')
47+
? '- '
48+
: ''
49+
}${omitSign ? '' : `${this.sign} `}${this.round(Math.abs(number))
3750
.toFixed(this.precisionMax || 1)
3851
.replace(/0+$/, '')
3952
.replace(/\.$/, '')}`;
@@ -47,10 +60,23 @@ const denominations = {
4760
round(number) {
4861
return round(number, this.precision, this.precisionMax);
4962
},
50-
stringify(number, { omitDirection = false, omitSign = false } = {}) {
51-
return `${omitDirection ? '' : number === 0 ? '' : number > 0 ? '+ ' : '- '}${
52-
omitSign ? '' : `${this.sign} `
53-
}${this.round(Math.abs(number))
63+
stringify(
64+
number,
65+
{ omitDirection = false, omitSign = false, directionsShown = ['positive', 'negative'] } = {},
66+
) {
67+
return `${
68+
omitDirection
69+
? ''
70+
: number === 0
71+
? ''
72+
: number > 0
73+
? directionsShown.includes('positive')
74+
? '+ '
75+
: ''
76+
: directionsShown.includes('negative')
77+
? '- '
78+
: ''
79+
}${omitSign ? '' : `${this.sign} `}${this.round(Math.abs(number))
5480
.toFixed(this.precisionMax || 1)
5581
.replace(/0+$/, '')
5682
.replace(/\.$/, '')}`;

0 commit comments

Comments
 (0)