mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
start using Amount
This commit is contained in:
parent
7b353be350
commit
4bd87e8dce
3 changed files with 64 additions and 57 deletions
|
@ -1,5 +1,8 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:stackwallet/utilities/amount.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
|
||||
class EthTokenTxExtraDTO {
|
||||
EthTokenTxExtraDTO({
|
||||
required this.blockHash,
|
||||
|
@ -27,20 +30,16 @@ class EthTokenTxExtraDTO {
|
|||
timestamp: map['timestamp'] as int,
|
||||
from: map['from'] as String,
|
||||
to: map['to'] as String,
|
||||
value: int.parse(map['value'] as String),
|
||||
gas: map['gas'] as int,
|
||||
gasPrice: map['gasPrice'] as int,
|
||||
value: Amount(
|
||||
rawValue: BigInt.parse(map['value'] as String),
|
||||
fractionDigits: Coin.ethereum.decimals,
|
||||
),
|
||||
gas: _amountFromJsonNum(map['gas']),
|
||||
gasPrice: _amountFromJsonNum(map['gasPrice']),
|
||||
nonce: map['nonce'] as int,
|
||||
input: map['input'] as String,
|
||||
gasCost: map['gasCost'] as int,
|
||||
gasUsed: map['gasUsed'] as int,
|
||||
);
|
||||
|
||||
factory EthTokenTxExtraDTO.fromJsonString(String jsonString) =>
|
||||
EthTokenTxExtraDTO.fromMap(
|
||||
Map<String, dynamic>.from(
|
||||
jsonDecode(jsonString) as Map,
|
||||
),
|
||||
gasCost: _amountFromJsonNum(map['gasCost']),
|
||||
gasUsed: _amountFromJsonNum(map['gasUsed']),
|
||||
);
|
||||
|
||||
final String hash;
|
||||
|
@ -50,13 +49,20 @@ class EthTokenTxExtraDTO {
|
|||
final int timestamp;
|
||||
final String from;
|
||||
final String to;
|
||||
final int value;
|
||||
final int gas;
|
||||
final int gasPrice;
|
||||
final Amount value;
|
||||
final Amount gas;
|
||||
final Amount gasPrice;
|
||||
final String input;
|
||||
final int nonce;
|
||||
final int gasCost;
|
||||
final int gasUsed;
|
||||
final Amount gasCost;
|
||||
final Amount gasUsed;
|
||||
|
||||
static Amount _amountFromJsonNum(dynamic json) {
|
||||
return Amount(
|
||||
rawValue: BigInt.from(json as num),
|
||||
fractionDigits: Coin.ethereum.decimals,
|
||||
);
|
||||
}
|
||||
|
||||
EthTokenTxExtraDTO copyWith({
|
||||
String? hash,
|
||||
|
@ -66,13 +72,13 @@ class EthTokenTxExtraDTO {
|
|||
int? timestamp,
|
||||
String? from,
|
||||
String? to,
|
||||
int? value,
|
||||
int? gas,
|
||||
int? gasPrice,
|
||||
Amount? value,
|
||||
Amount? gas,
|
||||
Amount? gasPrice,
|
||||
int? nonce,
|
||||
String? input,
|
||||
int? gasCost,
|
||||
int? gasUsed,
|
||||
Amount? gasCost,
|
||||
Amount? gasUsed,
|
||||
}) =>
|
||||
EthTokenTxExtraDTO(
|
||||
hash: hash ?? this.hash,
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:stackwallet/utilities/amount.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
|
||||
class EthTxDTO {
|
||||
EthTxDTO({
|
||||
required this.hash,
|
||||
|
@ -29,22 +32,16 @@ class EthTxDTO {
|
|||
timestamp: map['timestamp'] as int,
|
||||
from: map['from'] as String,
|
||||
to: map['to'] as String,
|
||||
value: map['value'] as int,
|
||||
gas: map['gas'] as int,
|
||||
gasPrice: map['gasPrice'] as int,
|
||||
maxFeePerGas: map['maxFeePerGas'] as int,
|
||||
maxPriorityFeePerGas: map['maxPriorityFeePerGas'] as int,
|
||||
value: _amountFromJsonNum(map['value']),
|
||||
gas: _amountFromJsonNum(map['gas']),
|
||||
gasPrice: _amountFromJsonNum(map['gasPrice']),
|
||||
maxFeePerGas: _amountFromJsonNum(map['maxFeePerGas']),
|
||||
maxPriorityFeePerGas: _amountFromJsonNum(map['maxPriorityFeePerGas']),
|
||||
isError: map['isError'] as int,
|
||||
hasToken: map['hasToken'] as int,
|
||||
compressedTx: map['compressedTx'] as String,
|
||||
gasCost: map['gasCost'] as int,
|
||||
gasUsed: map['gasUsed'] as int,
|
||||
);
|
||||
|
||||
factory EthTxDTO.fromJsonString(String jsonString) => EthTxDTO.fromMap(
|
||||
Map<String, dynamic>.from(
|
||||
jsonDecode(jsonString) as Map,
|
||||
),
|
||||
gasCost: _amountFromJsonNum(map['gasCost']),
|
||||
gasUsed: _amountFromJsonNum(map['gasUsed']),
|
||||
);
|
||||
|
||||
final String hash;
|
||||
|
@ -54,16 +51,23 @@ class EthTxDTO {
|
|||
final int timestamp;
|
||||
final String from;
|
||||
final String to;
|
||||
final int value;
|
||||
final int gas;
|
||||
final int gasPrice;
|
||||
final int maxFeePerGas;
|
||||
final int maxPriorityFeePerGas;
|
||||
final Amount value;
|
||||
final Amount gas;
|
||||
final Amount gasPrice;
|
||||
final Amount maxFeePerGas;
|
||||
final Amount maxPriorityFeePerGas;
|
||||
final int isError;
|
||||
final int hasToken;
|
||||
final String compressedTx;
|
||||
final int gasCost;
|
||||
final int gasUsed;
|
||||
final Amount gasCost;
|
||||
final Amount gasUsed;
|
||||
|
||||
static Amount _amountFromJsonNum(dynamic json) {
|
||||
return Amount(
|
||||
rawValue: BigInt.from(json as num),
|
||||
fractionDigits: Coin.ethereum.decimals,
|
||||
);
|
||||
}
|
||||
|
||||
EthTxDTO copyWith({
|
||||
String? hash,
|
||||
|
@ -73,16 +77,16 @@ class EthTxDTO {
|
|||
int? timestamp,
|
||||
String? from,
|
||||
String? to,
|
||||
int? value,
|
||||
int? gas,
|
||||
int? gasPrice,
|
||||
int? maxFeePerGas,
|
||||
int? maxPriorityFeePerGas,
|
||||
Amount? value,
|
||||
Amount? gas,
|
||||
Amount? gasPrice,
|
||||
Amount? maxFeePerGas,
|
||||
Amount? maxPriorityFeePerGas,
|
||||
int? isError,
|
||||
int? hasToken,
|
||||
String? compressedTx,
|
||||
int? gasCost,
|
||||
int? gasUsed,
|
||||
Amount? gasCost,
|
||||
Amount? gasUsed,
|
||||
}) =>
|
||||
EthTxDTO(
|
||||
hash: hash ?? this.hash,
|
||||
|
|
|
@ -854,7 +854,7 @@ class EthereumWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
final allTxs = txsResponse.value!;
|
||||
final List<Tuple2<Transaction, Address?>> txnsData = [];
|
||||
for (final element in allTxs) {
|
||||
int transactionAmount = element.value;
|
||||
Amount transactionAmount = element.value;
|
||||
|
||||
bool isIncoming;
|
||||
bool txFailed = false;
|
||||
|
@ -869,7 +869,7 @@ class EthereumWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
|
||||
//Calculate fees (GasLimit * gasPrice)
|
||||
// int txFee = element.gasPrice * element.gasUsed;
|
||||
int txFee = element.gasCost;
|
||||
Amount txFee = element.gasCost;
|
||||
|
||||
final String addressString = checksumEthereumAddress(element.to);
|
||||
final int height = element.blockNumber;
|
||||
|
@ -881,12 +881,9 @@ class EthereumWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
type:
|
||||
isIncoming ? TransactionType.incoming : TransactionType.outgoing,
|
||||
subType: TransactionSubType.none,
|
||||
amount: transactionAmount,
|
||||
amountString: Amount(
|
||||
rawValue: BigInt.from(transactionAmount),
|
||||
fractionDigits: coin.decimals,
|
||||
).toJsonString(),
|
||||
fee: txFee,
|
||||
amount: transactionAmount.raw.toInt(),
|
||||
amountString: transactionAmount.toJsonString(),
|
||||
fee: txFee.raw.toInt(),
|
||||
height: height,
|
||||
isCancelled: txFailed,
|
||||
isLelantus: false,
|
||||
|
|
Loading…
Reference in a new issue