Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tx value for atomic name swap finalize #296

Merged
merged 1 commit into from
Apr 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions app/components/Transactions/Transaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,20 @@ class Transaction extends Component {
|| tx.type === COINBASE
|| tx.type === REVEAL
|| tx.type === REDEEM
|| tx.type === REGISTER)
|| tx.type === REGISTER
|| (tx.type === FINALIZE && tx.value > 0))
&& !tx.pending,
'transaction__number--neutral':
(tx.type === UPDATE
|| tx.type === RENEW
|| tx.type === OPEN
|| tx.type === TRANSFER
|| tx.type === FINALIZE)
|| (tx.type === FINALIZE && tx.value === 0))
&& !tx.pending,
'transaction__number--negative':
(tx.type === SEND
|| tx.type === BID)
|| tx.type === BID
|| (tx.type === FINALIZE && tx.value < 0))
&& !tx.pending,
});

Expand Down Expand Up @@ -129,6 +131,8 @@ class Transaction extends Component {
content = this.formatDomain(tx.meta.domain);
} else if (tx.type === 'FINALIZE') {
description = 'Finalized Domain';
if (tx.value > 0) description = 'Received Payment for Domain';
if (tx.value < 0) description = 'Finalized With Payment';
content = this.formatDomain(tx.meta.domain);
} else {
description = 'Unknown Transaction';
Expand All @@ -153,9 +157,10 @@ class Transaction extends Component {
{' '}
{
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 === UPDATE || tx.type === RENEW || tx.type === OPEN || tx.type === FINALIZE ? ''
: '-'
}
{ (tx.type === FINALIZE && tx.value > 0) ? '+': '' }
{displayBalance(tx.value)} HNS
</div>
</div>
Expand Down
21 changes: 19 additions & 2 deletions app/ducks/walletActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,29 @@ async function parseInputsOutputs(net, tx) {
covValue += output.value;
}

if (covenant.action == 'FINALIZE') {
const isSender = output.path == null;

// Start with no payment for normal Finalizes
covValue = 0;

// containsOtherOutputs: Look for outputs that are not change addresses to self
if (isSender) {
// If yes, sum all self outputs (payment made by receiver)
const containsOtherOutputs = tx.outputs.findIndex(x => x.covenant.action == 'NONE' && x.path === null) !== -1;
if (containsOtherOutputs) covValue = tx.outputs.reduce((sum, op) => op.path ? (sum+op.value) : sum, 0);
} else {
// If yes, sum all outputs to others' addresses (payment made to sender)
const containsOtherOutputs = tx.outputs.findIndex(x => x.covenant.action == 'NONE' && x.path !== null) !== -1;
if (containsOtherOutputs) covValue = -tx.outputs.reduce((sum, op) => !op.path ? (sum+op.value) : sum, 0);
}
}

// 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 === 'FINALIZE') {
covenant.action === 'TRANSFER') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could be wrong but I think if the wallet is receiving payment for a FINALIZE, then the payment value might just be equal to totalValue calculated above. I'm not sure if that'll work for the buyer though (who is sending money) but might save you some of the logic in the blob L371-390

Copy link
Collaborator Author

@rithvikvibhu rithvikvibhu Jan 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, this works for the seller and I initially tried this (but outside the for loop because totalValue won't be complete inside the loop).

if (covAction) {
    return {
      ...covData,
      fee: tx.fee,
      value: covenant.action === 'FINALIZE' ? totalValue : covValue, // <- instead of just covValue
    };
  }

Like you said, this only works for the seller, not buyer. There's also a problem of identifying if the value is +ve or -ve.

covValue = 0;
}

Expand Down