Skip to content

Commit

Permalink
show correct amount for shakedex transfer (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
chikeichan authored Oct 22, 2021
1 parent 11c7224 commit ecb89de
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 9 deletions.
21 changes: 14 additions & 7 deletions app/components/Transactions/Transaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,22 @@ class Transaction extends Component {
|| tx.type === REVEAL
|| tx.type === REDEEM
|| tx.type === REGISTER
|| (tx.type === FINALIZE && tx.value > 0))
|| (tx.type === FINALIZE && tx.value > 0)
|| (tx.type === TRANSFER && tx.value > 0))
&& !tx.pending,
'transaction__number--neutral':
(tx.type === UPDATE
|| tx.type === CLAIM
|| tx.type === RENEW
|| tx.type === OPEN
|| tx.type === TRANSFER
|| (tx.type === FINALIZE && tx.value === 0))
|| (tx.type === FINALIZE && tx.value === 0)
|| (tx.type === TRANSFER && tx.value === 0))
&& !tx.pending,
'transaction__number--negative':
(tx.type === SEND
|| tx.type === BID
|| (tx.type === FINALIZE && tx.value < 0))
|| (tx.type === FINALIZE && tx.value < 0)
|| (tx.type === TRANSFER && tx.value < 0))
&& !tx.pending,
});

Expand Down Expand Up @@ -161,11 +163,16 @@ class Transaction extends Component {
{tx.pending ? <em>(pending)</em> : null}
{' '}
{
tx.type === RECEIVE || tx.type === COINBASE || tx.type === REDEEM || tx.type === REVEAL || tx.type === REGISTER ? '+'
: tx.type === UPDATE || tx.type === RENEW || tx.type === OPEN || tx.type === FINALIZE || tx.type === CLAIM ? ''
: '-'
[RECEIVE, COINBASE, REDEEM, REVEAL, REGISTER].includes(tx.type)
? '+'
: [UPDATE, RENEW, OPEN, FINALIZE, CLAIM].includes(tx.type)
? ''
: [SEND, BID].includes(tx.type)
? '-'
: ''
}
{ (tx.type === FINALIZE && tx.value > 0) ? '+': '' }
{ (tx.type === TRANSFER && tx.value > 0) ? '+': '' }
{displayBalance(tx.value)} HNS
</div>
</div>
Expand Down
31 changes: 29 additions & 2 deletions app/ducks/walletActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,18 @@ async function parseInputsOutputs(net, tx) {
// Renewals and Updates have a value, but it doesn't
// affect the spendable balance of the wallet.
if (covenant.action === 'RENEW' ||
covenant.action === 'UPDATE' ||
covenant.action === 'TRANSFER') {
covenant.action === 'UPDATE') {
covValue = 0;
}

if (covenant.action === 'TRANSFER' ) {
if (output.path) {
covValue = 0;
} else {
covValue = getNetValue(tx);
}
}

// May be called redundantly but should be handled by cache
covData = await parseCovenant(net, covenant);

Expand Down Expand Up @@ -470,6 +477,26 @@ async function parseInputsOutputs(net, tx) {
};
}

function getNetValue(tx) {
let totalValue = 0;

for (let i = 0; i < tx.outputs.length; i++) {
const output = tx.outputs[i];
if (output.path) {
totalValue += output.value;
}
}

for (let j = 0; j < tx.inputs.length; j++) {
const input = tx.inputs[j];
if (input.path) {
totalValue -= input.value;
}
}

return totalValue;
}

async function parseCovenant(net, covenant) {
switch (covenant.action) {
case 'CLAIM':
Expand Down
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"bcurl": "^0.1.9",
"bdb": "^1.2.2",
"bignumber.js": "8.0.1",
"bns": "~0.15.0",
"classnames": "2.2.6",
"copy-to-clipboard": "3.0.8",
"deep-equal": "2.0.1",
Expand Down

0 comments on commit ecb89de

Please sign in to comment.