Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

fix: total amount and recipients in multipayment transactions #489

Merged
merged 3 commits into from
Feb 19, 2020
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
27 changes: 22 additions & 5 deletions src/app/models/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import moment from "moment";

import { MarketCurrency, MarketHistory, MarketTicker } from "@/models/market";

import { TRANSACTION_GROUPS } from "@/app/app.constants";
import { TRANSACTION_GROUPS, TRANSACTION_TYPES } from "@/app/app.constants";
import { Interfaces } from "@arkecosystem/crypto";
import { ArkUtility } from "../utils/ark-utility";

const TX_TYPES = {
Expand Down Expand Up @@ -58,11 +59,13 @@ const TX_TYPES_ACTIVITY = {
export type TransactionEntity = TransactionModel & {
isSender: boolean;
isTransfer: boolean;
isMultipayment: boolean;
appropriateAddress: string;
activityLabel: string;
typeLabel: string;
totalAmount: number;
date: Date;
asset: Interfaces.ITransactionAsset;
amountEquivalent: number;
};

Expand All @@ -80,7 +83,7 @@ export class Transaction extends TransactionModel {
public typeGroup?: number;
public version?: number;
public date: Date;
public asset: any;
public asset: Interfaces.ITransactionAsset;

constructor(public address: string) {
super();
Expand All @@ -104,13 +107,20 @@ export class Transaction extends TransactionModel {
}

getAmount(forceFee?: boolean) {
let amount = this.amount;
let amount = new BigNumber(this.amount);

if (this.isSender() || forceFee) {
amount = this.amount + this.fee;
amount = amount.plus(this.fee);
}

return amount;
if (this.isMultipayment()) {
for (const payment of this.asset.payments) {
// @ts-ignore
amount = amount.plus(payment.amount);
}
}

return amount.toNumber();
}

getAmountEquivalent(
Expand Down Expand Up @@ -182,6 +192,13 @@ export class Transaction extends TransactionModel {
return type;
}

isMultipayment(): boolean {
return (
this.type === TRANSACTION_TYPES.GROUP_1.MULTI_PAYMENT &&
this.typeGroup === TRANSACTION_GROUPS.STANDARD
);
}

isTransfer(): boolean {
return (
this.type === TransactionType.SendArk &&
Expand Down
26 changes: 25 additions & 1 deletion src/app/pages/transaction/transaction-show/transaction-show.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
>
<span>{{ transaction.typeLabel | translate }}</span>
<ion-text
[color]="isSender ? 'danger' : 'success'"
[color]="transaction.isSender ? 'danger' : 'success'"
class="text-xl font-semibold my-3"
>
{{ transaction.isSender ? '-' : '+' }} {{
Expand Down Expand Up @@ -122,6 +122,30 @@
</ion-label>
</ion-item>
</ion-list>

<ion-list
inset
*ngIf="transaction?.isMultipayment"
class="mt-5 list-selectable"
>
<ion-list-header class="pl-0">
<ion-label
>{{ 'TRANSACTIONS_PAGE.RECIPIENTS' | translate
}}</ion-label
>
</ion-list-header>
<ion-item *ngFor="let item of transaction?.asset?.payments">
<ion-label>
<div class="item-content flex justify-between">
<span
>{{ item?.recipientId | truncateMiddle: 12
}}</span
>
<span>{{ item?.amount | unitsSatoshi }}</span>
</div>
</ion-label>
</ion-item>
</ion-list>
</ion-col>
</ion-row>
</ion-grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ export class TransactionShowPage {
public currentNetwork: StoredNetwork;
private currentWallet: Wallet;

public isSender: boolean;
public totalAmount: number;
public typeLabel: string;

constructor(
private navCtrl: NavController,
private route: ActivatedRoute,
Expand Down
2 changes: 2 additions & 0 deletions src/app/pages/wallet/wallet-dashboard/wallet-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,9 @@ export class WalletDashboardPage implements OnInit, OnDestroy {
senderId: transaction.senderId,
confirmations: transaction.confirmations,
isTransfer: transaction.isTransfer(),
isMultipayment: transaction.isMultipayment(),
isSender: transaction.isSender(),
asset: transaction.asset,
appropriateAddress: transaction.getAppropriateAddress(),
activityLabel: transaction.getActivityLabel(),
typeLabel: transaction.getTypeLabel(),
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
"RECEIVED": "Received",
"RECEIVED_FROM": "Received from",
"RECIPIENT": "Recipient",
"RECIPIENTS": "Recipients",
"SECOND_SIGNATURE_CREATION": "Second Signature Creation",
"SECOND_PASSPHRASE_NOT_ENTERED": "The second passphrase has not been entered",
"SEND": "Send",
Expand Down