mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-11 13:24:51 +00:00
balance working
This commit is contained in:
parent
d30de4dc3f
commit
490618ebd6
3 changed files with 39 additions and 63 deletions
|
@ -1,6 +1,7 @@
|
|||
import 'package:cw_core/balance.dart';
|
||||
import 'package:cw_core/currency.dart';
|
||||
import 'package:cw_core/monero_amount_format.dart';
|
||||
import 'package:cw_nano/nano_util.dart';
|
||||
|
||||
String rawToFormattedAmount(BigInt amount, Currency currency) {
|
||||
return "";
|
||||
|
@ -29,11 +30,11 @@ class NanoBalance extends Balance {
|
|||
|
||||
@override
|
||||
String get formattedAvailableBalance {
|
||||
return "0";
|
||||
return NanoUtil.getRawAsUsableString(currentBalance.toString(), NanoUtil.rawPerNano);
|
||||
}
|
||||
|
||||
@override
|
||||
String get formattedAdditionalBalance {
|
||||
return "0";
|
||||
return NanoUtil.getRawAsUsableString(receivableBalance.toString(), NanoUtil.rawPerNano);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,67 +29,41 @@ class NanoClient {
|
|||
void setListeners(EthereumAddress userAddress, Function(FilterEvent) onNewTransaction) async {}
|
||||
|
||||
Future<NanoBalance> getBalance(String address) async {
|
||||
return NanoBalance(currentBalance: BigInt.zero, receivableBalance: BigInt.zero);
|
||||
// this is the preferred rpc call but the test node isn't returning this one:
|
||||
// final response = await _httpClient.post(
|
||||
// _node!.uri,
|
||||
// headers: {"Content-Type": "application/json"},
|
||||
// body: jsonEncode(
|
||||
// {
|
||||
// "action": "account_balance",
|
||||
// "account": address,
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
// final data = await jsonDecode(response.body);
|
||||
// final String currentBalance = data["balance"] as String;
|
||||
// final String receivableBalance = data["receivable"] as String;
|
||||
// final BigInt cur = BigInt.parse(currentBalance);
|
||||
// final BigInt rec = BigInt.parse(receivableBalance);
|
||||
|
||||
final response = await _httpClient.post(
|
||||
_node!.uri,
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: jsonEncode(
|
||||
{
|
||||
"action": "accounts_balances",
|
||||
"accounts": [address],
|
||||
},
|
||||
),
|
||||
);
|
||||
final data = await jsonDecode(response.body);
|
||||
final String currentBalance = data["balances"][address]["balance"] as String;
|
||||
final String receivableBalance = data["balances"][address]["receivable"] as String;
|
||||
final BigInt cur = BigInt.parse(currentBalance);
|
||||
final BigInt rec = BigInt.parse(receivableBalance);
|
||||
return NanoBalance(currentBalance: cur, receivableBalance: rec);
|
||||
}
|
||||
|
||||
// Future<PendingEthereumTransaction> signTransaction({
|
||||
// required EthPrivateKey privateKey,
|
||||
// required String toAddress,
|
||||
// required String amount,
|
||||
// required int gas,
|
||||
// required EthereumTransactionPriority priority,
|
||||
// required CryptoCurrency currency,
|
||||
// required int exponent,
|
||||
// String? contractAddress,
|
||||
// }) async {
|
||||
// assert(currency == CryptoCurrency.eth || contractAddress != null);
|
||||
|
||||
// bool _isEthereum = currency == CryptoCurrency.eth;
|
||||
|
||||
// final price = await _client!.getGasPrice();
|
||||
|
||||
// final Transaction transaction = Transaction(
|
||||
// from: privateKey.address,
|
||||
// to: EthereumAddress.fromHex(toAddress),
|
||||
// maxGas: gas,
|
||||
// gasPrice: price,
|
||||
// value: _isEthereum ? EtherAmount.inWei(BigInt.parse(amount)) : EtherAmount.zero(),
|
||||
// );
|
||||
|
||||
// final signedTransaction = await _client!.signTransaction(privateKey, transaction);
|
||||
|
||||
// final BigInt estimatedGas;
|
||||
// final Function _sendTransaction;
|
||||
|
||||
// if (_isEthereum) {
|
||||
// estimatedGas = BigInt.from(21000);
|
||||
// _sendTransaction = () async => await sendTransaction(signedTransaction);
|
||||
// } else {
|
||||
// estimatedGas = BigInt.from(50000);
|
||||
|
||||
// final erc20 = Erc20(
|
||||
// client: _client!,
|
||||
// address: EthereumAddress.fromHex(contractAddress!),
|
||||
// );
|
||||
|
||||
// _sendTransaction = () async {
|
||||
// await erc20.transfer(
|
||||
// EthereumAddress.fromHex(toAddress),
|
||||
// BigInt.parse(amount),
|
||||
// credentials: privateKey,
|
||||
// );
|
||||
// };
|
||||
// }
|
||||
|
||||
// return PendingEthereumTransaction(
|
||||
// signedTransaction: signedTransaction,
|
||||
// amount: amount,
|
||||
// fee: estimatedGas * price.getInWei,
|
||||
// sendTransaction: _sendTransaction,
|
||||
// exponent: exponent,
|
||||
// );
|
||||
// }
|
||||
|
||||
Future<dynamic> getTransactionDetails(String transactionHash) async {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
@ -106,7 +80,7 @@ class NanoClient {
|
|||
body: jsonEncode({
|
||||
"action": "account_history",
|
||||
"account": address,
|
||||
"count": "250",// TODO: pick a number
|
||||
"count": "250", // TODO: pick a number
|
||||
// "raw": true,
|
||||
}));
|
||||
final data = await jsonDecode(response.body);
|
||||
|
|
|
@ -131,7 +131,6 @@ abstract class NanoWalletBase
|
|||
}
|
||||
|
||||
Future<void> updateTransactions() async {
|
||||
print("updating_transactions");
|
||||
try {
|
||||
if (_isTransactionUpdating) {
|
||||
return;
|
||||
|
@ -246,6 +245,8 @@ abstract class NanoWalletBase
|
|||
}
|
||||
|
||||
Future<void> _updateBalance() async {
|
||||
// this.balance.update(CryptoCurrency.nano, (value) => (await _client.getBalance(_publicAddress)));
|
||||
balance[currency] = await _client.getBalance(_publicAddress);
|
||||
await save();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue