-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional transaction balance change details
- Loading branch information
Showing
7 changed files
with
188 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/komodo_defi_types/lib/src/transactions/balance_changes.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'package:decimal/decimal.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:komodo_defi_types/komodo_defi_types.dart'; | ||
|
||
/// Represents the effect a transaction has on wallet balances | ||
class BalanceChanges extends Equatable { | ||
const BalanceChanges({ | ||
required this.netChange, | ||
required this.receivedByMe, | ||
required this.spentByMe, | ||
required this.totalAmount, | ||
}); | ||
|
||
factory BalanceChanges.fromJson(JsonMap json) => BalanceChanges( | ||
netChange: Decimal.parse(json.value<String>('my_balance_change')), | ||
receivedByMe: Decimal.parse(json.value<String>('received_by_me')), | ||
spentByMe: Decimal.parse(json.value<String>('spent_by_me')), | ||
totalAmount: Decimal.parse(json.value<String>('total_amount')), | ||
); | ||
|
||
/// The net change in the wallet's balance (positive for incoming, | ||
/// negative for outgoing) | ||
final Decimal netChange; | ||
|
||
/// Amount received by my addresses in this transaction | ||
final Decimal receivedByMe; | ||
|
||
/// Amount spent from my addresses in this transaction | ||
final Decimal spentByMe; | ||
|
||
/// The total amount of coins transferred | ||
final Decimal totalAmount; | ||
|
||
bool get isIncoming => netChange > Decimal.zero; | ||
|
||
@override | ||
List<Object?> get props => [netChange, receivedByMe, spentByMe, totalAmount]; | ||
|
||
Map<String, dynamic> toJson() => { | ||
'my_balance_change': netChange.toString(), | ||
'received_by_me': receivedByMe.toString(), | ||
'spent_by_me': spentByMe.toString(), | ||
'total_amount': totalAmount.toString(), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.