-
Notifications
You must be signed in to change notification settings - Fork 3
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
refactor: isReturn
and total
methods
#106
Changes from 13 commits
dcb6653
0d12881
aa6fc8b
a4a633a
6fd3ccc
d684d53
7856990
efe0692
91e03ca
81e620b
6660be9
bc77e7e
d5b8346
436ab2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -59,7 +59,24 @@ export class ExtendedSignedTransactionData { | |||
} | ||||
|
||||
public isReturn(): boolean { | ||||
return this.isSent() && this.isReceived(); | ||||
if (this.isTransfer()) { | ||||
return this.isSent() && this.isReceived(); | ||||
} | ||||
|
||||
if (this.isMultiPayment()) { | ||||
let isReturn = true; | ||||
|
||||
for (const recipient of this.recipients().values()) { | ||||
if (recipient.address !== this.sender()) { | ||||
isReturn = false; | ||||
break; | ||||
} | ||||
} | ||||
|
||||
return isReturn; | ||||
} | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same as above but for the signed transactions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shahin-hq I think here we could use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried that before but couldn't because I couldn't find a way to access given wallet in coin class.
|
||||
return false; | ||||
} | ||||
|
||||
public isSent(): boolean { | ||||
|
@@ -131,11 +148,25 @@ export class ExtendedSignedTransactionData { | |||
} | ||||
|
||||
public total(): number { | ||||
if (this.isReturn()) { | ||||
return this.amount() - this.fee(); | ||||
} | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a transaction is a returning the fee should be subtracted |
||||
|
||||
if (this.isSent()) { | ||||
return this.amount() + this.fee(); | ||||
} | ||||
|
||||
return this.amount(); | ||||
let total = this.amount(); | ||||
|
||||
if (this.isMultiPayment()) { | ||||
for (const recipient of this.recipients()) { | ||||
if (recipient.address !== this.wallet().address()) { | ||||
total -= recipient.amount; | ||||
} | ||||
} | ||||
} | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added
|
||||
return total; | ||||
} | ||||
|
||||
public convertedTotal(): number { | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change ensures that
isReturn
will returntrue
only when all of the recipients are the same as sender.