mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-11 05:04:35 +00:00
Merge branch 'add-xtz' of https://github.com/cypherstack/stack_wallet into add-xtz
This commit is contained in:
commit
be0d820822
3 changed files with 54 additions and 52 deletions
|
@ -292,8 +292,8 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateBalance() async {
|
Future<void> updateBalance() async {
|
||||||
var api = "https://api.mainnet.tzkt.io/v1/accounts/${await currentReceivingAddress}/balance"; // TODO: Can we use current node instead of this?
|
var api = "${getCurrentNode().host}:${getCurrentNode().port}/chains/main/blocks/head/context/contracts/${await currentReceivingAddress}/balance";
|
||||||
var theBalance = await get(Uri.parse(api)).then((value) => value.body);
|
var theBalance = (await get(Uri.parse(api)).then((value) => value.body)).substring(1, (await get(Uri.parse(api)).then((value) => value.body)).length - 2);
|
||||||
Logging.instance.log("Balance for ${await currentReceivingAddress}: $theBalance", level: LogLevel.Info);
|
Logging.instance.log("Balance for ${await currentReceivingAddress}: $theBalance", level: LogLevel.Info);
|
||||||
var balanceInAmount = Amount(rawValue: BigInt.parse(theBalance.toString()), fractionDigits: 6);
|
var balanceInAmount = Amount(rawValue: BigInt.parse(theBalance.toString()), fractionDigits: 6);
|
||||||
_balance = Balance(
|
_balance = Balance(
|
||||||
|
@ -306,30 +306,32 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateTransactions() async {
|
Future<void> updateTransactions() async {
|
||||||
var api = "https://api.mainnet.tzkt.io/v1/accounts/${await currentReceivingAddress}/balance_history"; // TODO: Can we use current node instead of this?
|
// TODO: Use node RPC instead of tzstats API
|
||||||
var returnedTxs = await get(Uri.parse(api)).then((value) => value.body);
|
var api = "https://api.tzstats.com/tables/op?address=${await currentReceivingAddress}";
|
||||||
Logging.instance.log(
|
var jsonResponse = jsonDecode(await get(Uri.parse(api)).then((value) => value.body));
|
||||||
"Transactions for ${await currentReceivingAddress}: $returnedTxs",
|
|
||||||
level: LogLevel.Info);
|
|
||||||
List<Tuple2<Transaction, Address>> txs = [];
|
List<Tuple2<Transaction, Address>> txs = [];
|
||||||
Object? jsonTxs = jsonDecode(returnedTxs);
|
for (var tx in jsonResponse as List) {
|
||||||
if (jsonTxs == null) {
|
var txApi = "https://api.tzstats.com/explorer/op/${tx["hash"]}";
|
||||||
await db.addNewTransactionData(txs, walletId);
|
var txJsonResponse = jsonDecode(await get(Uri.parse(txApi)).then((value) => value.body))[0];
|
||||||
|
TransactionType txType;
|
||||||
|
if (txJsonResponse["sender"] == (await currentReceivingAddress)) {
|
||||||
|
txType = TransactionType.outgoing;
|
||||||
} else {
|
} else {
|
||||||
for (var tx in jsonTxs as List) {
|
txType = TransactionType.incoming;
|
||||||
|
}
|
||||||
var theTx = Transaction(
|
var theTx = Transaction(
|
||||||
walletId: walletId,
|
walletId: walletId,
|
||||||
txid: "",
|
txid: txJsonResponse["hash"].toString(),
|
||||||
timestamp: DateTime.parse(tx["timestamp"].toString()).toUtc().millisecondsSinceEpoch ~/ 1000,
|
timestamp: DateTime.parse(txJsonResponse["time"].toString()).toUtc().millisecondsSinceEpoch ~/ 1000,
|
||||||
type: TransactionType.unknown,
|
type: txType,
|
||||||
subType: TransactionSubType.none,
|
subType: TransactionSubType.none,
|
||||||
amount: int.parse(tx["balance"].toString()),
|
amount: (float.parse(txJsonResponse["volume"].toString()) * 1000000).toInt(),
|
||||||
amountString: Amount(
|
amountString: Amount(
|
||||||
rawValue: BigInt.parse(tx["balance"].toString()),
|
rawValue: BigInt.parse((float.parse(txJsonResponse["volume"].toString()) * 1000000).toString()),
|
||||||
fractionDigits: 6
|
fractionDigits: 6
|
||||||
).toJsonString(),
|
).toJsonString(),
|
||||||
fee: 0,
|
fee: (float.parse(txJsonResponse["fee"].toString()) * 1000000).toInt(),
|
||||||
height: int.parse(tx["level"].toString()),
|
height: int.parse(txJsonResponse["height"].toString()),
|
||||||
isCancelled: false,
|
isCancelled: false,
|
||||||
isLelantus: false,
|
isLelantus: false,
|
||||||
slateId: "",
|
slateId: "",
|
||||||
|
@ -341,7 +343,7 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
);
|
);
|
||||||
var theAddress = Address(
|
var theAddress = Address(
|
||||||
walletId: walletId,
|
walletId: walletId,
|
||||||
value: await currentReceivingAddress,
|
value: txJsonResponse["receiver"].toString(),
|
||||||
publicKey: [], // TODO: Add public key
|
publicKey: [], // TODO: Add public key
|
||||||
derivationIndex: 0,
|
derivationIndex: 0,
|
||||||
derivationPath: null,
|
derivationPath: null,
|
||||||
|
@ -352,12 +354,12 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
}
|
}
|
||||||
await db.addNewTransactionData(txs, walletId);
|
await db.addNewTransactionData(txs, walletId);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> updateChainHeight() async {
|
Future<void> updateChainHeight() async {
|
||||||
var api = "https://api.tzkt.io/v1/blocks/count"; // TODO: Can we use current node instead of this?
|
var api = "${getCurrentNode().host}:${getCurrentNode().port}/chains/main/blocks/head/header/shell";
|
||||||
var returnedHeight = await get(Uri.parse(api)).then((value) => value.body);
|
var jsonParsedResponse = jsonDecode(await get(Uri.parse(api)).then((value) => value.body));
|
||||||
final int intHeight = int.parse(returnedHeight.toString());
|
final int intHeight = int.parse(jsonParsedResponse["level"].toString());
|
||||||
|
Logging.instance.log("Chain height: $intHeight", level: LogLevel.Info);
|
||||||
await updateCachedChainHeight(intHeight);
|
await updateCachedChainHeight(intHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,7 +377,7 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
@override
|
@override
|
||||||
Future<bool> testNetworkConnection() async{
|
Future<bool> testNetworkConnection() async{
|
||||||
try {
|
try {
|
||||||
await get(Uri.parse("https://api.mainnet.tzkt.io/v1/accounts/${await currentReceivingAddress}/balance"));
|
await get(Uri.parse("${getCurrentNode().host}:${getCurrentNode().port}/chains/main/blocks/head/header/shell"));
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -100,7 +100,7 @@ class PriceAPI {
|
||||||
Uri.parse("https://api.coingecko.com/api/v3/coins/markets?vs_currency"
|
Uri.parse("https://api.coingecko.com/api/v3/coins/markets?vs_currency"
|
||||||
"=${baseCurrency.toLowerCase()}"
|
"=${baseCurrency.toLowerCase()}"
|
||||||
"&ids=monero,bitcoin,litecoin,ecash,epic-cash,zcoin,dogecoin,"
|
"&ids=monero,bitcoin,litecoin,ecash,epic-cash,zcoin,dogecoin,"
|
||||||
"bitcoin-cash,namecoin,wownero,ethereum,particl,nano,banano"
|
"bitcoin-cash,namecoin,wownero,ethereum,particl,nano,banano,tezos"
|
||||||
"&order=market_cap_desc&per_page=50&page=1&sparkline=false");
|
"&order=market_cap_desc&per_page=50&page=1&sparkline=false");
|
||||||
|
|
||||||
final coinGeckoResponse = await client.get(
|
final coinGeckoResponse = await client.get(
|
||||||
|
|
|
@ -182,8 +182,8 @@ abstract class DefaultNodes {
|
||||||
isDown: false
|
isDown: false
|
||||||
);
|
);
|
||||||
|
|
||||||
static NodeModel get tezos => NodeModel( // TODO: Change this to original one
|
static NodeModel get tezos => NodeModel( // TODO: Change this to stack wallet one
|
||||||
host: "mainnet.api.tez.ie",
|
host: "https://mainnet.api.tez.ie",
|
||||||
port: 443,
|
port: 443,
|
||||||
name: defaultName,
|
name: defaultName,
|
||||||
id: _nodeId(Coin.tezos),
|
id: _nodeId(Coin.tezos),
|
||||||
|
|
Loading…
Reference in a new issue