improve balance results; workaround batch (wip)
This commit is contained in:
parent
cd91ea838b
commit
99c559d38c
|
@ -385,19 +385,20 @@ class GenerateWalletsProvider with ChangeNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var derivationNbr in [for (var i = 0; i < numberScan; i += 1) i]) {
|
for (var derivationNbr in [for (var i = 0; i < numberScan; i += 1) i]) {
|
||||||
final addressData = await sub.sdk.api.keyring.addressFromMnemonic(sub.ss58,
|
final addressData = await sub.sdk.api.keyring.addressFromMnemonic(
|
||||||
|
sub.ss58,
|
||||||
cryptoType: CryptoType.sr25519,
|
cryptoType: CryptoType.sr25519,
|
||||||
mnemonic: generatedMnemonic!,
|
mnemonic: generatedMnemonic!,
|
||||||
derivePath: '//$derivationNbr');
|
derivePath: '//$derivationNbr');
|
||||||
|
|
||||||
final balance = await sub.getBalance(addressData.address!).timeout(
|
final balance = await sub.getBalance(addressData.address!).timeout(
|
||||||
const Duration(seconds: 1),
|
const Duration(seconds: 1),
|
||||||
onTimeout: () => 0,
|
onTimeout: () => {},
|
||||||
);
|
);
|
||||||
// const balance = 0;
|
// const balance = 0;
|
||||||
|
|
||||||
log.d(balance);
|
log.d(balance);
|
||||||
if (balance != 0) {
|
if (balance != {}) {
|
||||||
isAlive = true;
|
isAlive = true;
|
||||||
String walletName = scanedWalletNumber == 0
|
String walletName = scanedWalletNumber == 0
|
||||||
? 'currentWallet'.tr()
|
? 'currentWallet'.tr()
|
||||||
|
@ -431,11 +432,11 @@ class GenerateWalletsProvider with ChangeNotifier {
|
||||||
|
|
||||||
final balance = await sub.getBalance(addressData.address!).timeout(
|
final balance = await sub.getBalance(addressData.address!).timeout(
|
||||||
const Duration(seconds: 1),
|
const Duration(seconds: 1),
|
||||||
onTimeout: () => 0,
|
onTimeout: () => {},
|
||||||
);
|
);
|
||||||
|
|
||||||
log.d(balance);
|
log.d(balance);
|
||||||
if (balance != 0) {
|
if (balance != {}) {
|
||||||
String walletName = 'myRootWallet'.tr();
|
String walletName = 'myRootWallet'.tr();
|
||||||
await sub.importAccount(
|
await sub.importAccount(
|
||||||
mnemonic: '', fromMnemonic: true, password: pin.text);
|
mnemonic: '', fromMnemonic: true, password: pin.text);
|
||||||
|
|
|
@ -78,9 +78,8 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
'batchAll',
|
'batchAll',
|
||||||
sender,
|
sender,
|
||||||
);
|
);
|
||||||
List txOptions = calls;
|
|
||||||
|
|
||||||
return [txInfo, txOptions];
|
return [txInfo, calls];
|
||||||
}
|
}
|
||||||
|
|
||||||
TxSenderData _setSender() {
|
TxSenderData _setSender() {
|
||||||
|
@ -99,7 +98,9 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
|
|
||||||
for (var element in keyring.allAccounts) {
|
for (var element in keyring.allAccounts) {
|
||||||
final account = AddressInfo(address: element.address);
|
final account = AddressInfo(address: element.address);
|
||||||
account.balance = await getBalance(element.address!);
|
final globalBalance = await getBalance(element.address!);
|
||||||
|
account.balance = globalBalance['transferableBalance']!;
|
||||||
|
|
||||||
result.add(account);
|
result.add(account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +165,7 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
// return balance;
|
// return balance;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
Future<double> getBalance(String address) async {
|
Future<Map<String, double>> getBalance(String address) async {
|
||||||
// Get onchain storage values
|
// Get onchain storage values
|
||||||
final Map balanceGlobal = await getStorage('system.account("$address")');
|
final Map balanceGlobal = await getStorage('system.account("$address")');
|
||||||
final int? idtyIndex =
|
final int? idtyIndex =
|
||||||
|
@ -178,22 +179,26 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
await getStorage('universalDividend.pastReevals()');
|
await getStorage('universalDividend.pastReevals()');
|
||||||
|
|
||||||
// Compute amount of claimable UDs
|
// Compute amount of claimable UDs
|
||||||
final int newUdsAmount = _computeClaimUds(currentUdIndex,
|
final int unclaimedUds = _computeUnclaimUds(currentUdIndex,
|
||||||
idtyData?['data']?['firstEligibleUd'] ?? 0, pastReevals);
|
idtyData?['data']?['firstEligibleUd'] ?? 0, pastReevals);
|
||||||
|
|
||||||
// Calculate transferable and potential balance
|
// Calculate transferable and potential balance
|
||||||
final int transferableBalance =
|
final int transferableBalance =
|
||||||
(balanceGlobal['data']['free'] + newUdsAmount);
|
(balanceGlobal['data']['free'] + unclaimedUds);
|
||||||
final int potentialBalance =
|
|
||||||
(balanceGlobal['data']['reserved'] + transferableBalance);
|
|
||||||
|
|
||||||
log.i(
|
Map<String, double> finalBalances = {
|
||||||
'transferableBalance: $transferableBalance --- potentialBalance: $potentialBalance');
|
'transferableBalance': transferableBalance / 100,
|
||||||
|
'free': balanceGlobal['data']['free'] / 100,
|
||||||
|
'unclaimedUds': unclaimedUds / 100,
|
||||||
|
'reserved': balanceGlobal['data']['reserved'] / 100,
|
||||||
|
};
|
||||||
|
|
||||||
return transferableBalance / 100;
|
// log.i(finalBalances);
|
||||||
|
|
||||||
|
return finalBalances;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _computeClaimUds(
|
int _computeUnclaimUds(
|
||||||
int currentUdIndex, int firstEligibleUd, List pastReevals) {
|
int currentUdIndex, int firstEligibleUd, List pastReevals) {
|
||||||
int totalAmount = 0;
|
int totalAmount = 0;
|
||||||
|
|
||||||
|
@ -618,9 +623,50 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
fromPubkey!.keys.first,
|
fromPubkey!.keys.first,
|
||||||
);
|
);
|
||||||
|
|
||||||
final txInfo = TxInfoData(
|
final globalBalance = await getBalance(fromAddress);
|
||||||
'balances', amount == -1 ? 'transferAll' : 'transferKeepAlive', sender);
|
TxInfoData txInfo;
|
||||||
final txOptions = [destAddress, amount == -1 ? false : amountUnit];
|
List txOptions;
|
||||||
|
|
||||||
|
log.d(globalBalance);
|
||||||
|
|
||||||
|
// if (globalBalance['unclaimedUds'] != 0) {
|
||||||
|
// claimUDs(password);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// txInfo = TxInfoData(
|
||||||
|
// 'balances', amount == -1 ? 'transferAll' : 'transferKeepAlive', sender);
|
||||||
|
// txOptions = [destAddress, amount == -1 ? false : amountUnit];
|
||||||
|
|
||||||
|
if (globalBalance['unclaimedUds'] == 0) {
|
||||||
|
txInfo = TxInfoData('balances',
|
||||||
|
amount == -1 ? 'transferAll' : 'transferKeepAlive', sender);
|
||||||
|
txOptions = [destAddress, amount == -1 ? false : amountUnit];
|
||||||
|
} else {
|
||||||
|
txInfo = TxInfoData(
|
||||||
|
'utility',
|
||||||
|
'batchAll',
|
||||||
|
sender,
|
||||||
|
);
|
||||||
|
|
||||||
|
txOptions = [
|
||||||
|
['api.tx.universalDividend.claimUds()']
|
||||||
|
];
|
||||||
|
// 'balances.transferKeepAlive($destAddress, $amountUnit)'
|
||||||
|
// amount == -1
|
||||||
|
// ? 'balances.transferAll(false)'
|
||||||
|
// : 'balances.transferKeepAlive([$destAddress, $amountUnit])'
|
||||||
|
}
|
||||||
|
|
||||||
|
log.d('yooooo: ${txInfo.module}, ${txInfo.call}, $txOptions');
|
||||||
|
// Map tata = await sdk.webView!
|
||||||
|
// .evalJavascript('api.tx.universalDividend.claimUds()',
|
||||||
|
// wrapPromise: false)
|
||||||
|
// .timeout(
|
||||||
|
// const Duration(seconds: 12),
|
||||||
|
// onTimeout: () => {},
|
||||||
|
// );
|
||||||
|
|
||||||
|
// return tata.toString();
|
||||||
|
|
||||||
return await executeCall(txInfo, txOptions, password);
|
return await executeCall(txInfo, txOptions, password);
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ class WalletOptionsProvider with ChangeNotifier {
|
||||||
if (answer ?? false) {
|
if (answer ?? false) {
|
||||||
//Check if balance is null
|
//Check if balance is null
|
||||||
final balance = await sub.getBalance(wallet.address!);
|
final balance = await sub.getBalance(wallet.address!);
|
||||||
if (balance != 0) {
|
if (balance != {}) {
|
||||||
MyWalletsProvider myWalletProvider =
|
MyWalletsProvider myWalletProvider =
|
||||||
Provider.of<MyWalletsProvider>(context, listen: false);
|
Provider.of<MyWalletsProvider>(context, listen: false);
|
||||||
final defaultWallet = myWalletProvider.getDefaultWallet();
|
final defaultWallet = myWalletProvider.getDefaultWallet();
|
||||||
|
@ -531,9 +531,10 @@ Widget balance(BuildContext context, String address, double size,
|
||||||
Consumer<SubstrateSdk>(builder: (context, sdk, _) {
|
Consumer<SubstrateSdk>(builder: (context, sdk, _) {
|
||||||
return FutureBuilder(
|
return FutureBuilder(
|
||||||
future: sdk.getBalance(address),
|
future: sdk.getBalance(address),
|
||||||
builder: (BuildContext context, AsyncSnapshot<double> balance) {
|
builder: (BuildContext context,
|
||||||
if (balance.connectionState != ConnectionState.done ||
|
AsyncSnapshot<Map<String, double>> globalBalance) {
|
||||||
balance.hasError) {
|
if (globalBalance.connectionState != ConnectionState.done ||
|
||||||
|
globalBalance.hasError) {
|
||||||
if (balanceCache[address] != null &&
|
if (balanceCache[address] != null &&
|
||||||
balanceCache[address] != -1) {
|
balanceCache[address] != -1) {
|
||||||
return Text(
|
return Text(
|
||||||
|
@ -551,7 +552,7 @@ Widget balance(BuildContext context, String address, double size,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
balanceCache[address] = balance.data!;
|
balanceCache[address] = globalBalance.data!['transferableBalance']!;
|
||||||
if (balanceCache[address] != -1) {
|
if (balanceCache[address] != -1) {
|
||||||
return Text(
|
return Text(
|
||||||
"${balanceCache[address]!.toString()} $currencyName",
|
"${balanceCache[address]!.toString()} $currencyName",
|
||||||
|
|
|
@ -518,10 +518,10 @@ class WalletViewScreen extends StatelessWidget {
|
||||||
future:
|
future:
|
||||||
sub.getBalance(defaultWallet.address!),
|
sub.getBalance(defaultWallet.address!),
|
||||||
builder: (BuildContext context,
|
builder: (BuildContext context,
|
||||||
AsyncSnapshot<double> balance) {
|
AsyncSnapshot<Map<String, double>> globalBalance) {
|
||||||
if (balance.connectionState !=
|
if (globalBalance.connectionState !=
|
||||||
ConnectionState.done ||
|
ConnectionState.done ||
|
||||||
balance.hasError) {
|
globalBalance.hasError) {
|
||||||
if (balanceCache[
|
if (balanceCache[
|
||||||
defaultWallet.address!] !=
|
defaultWallet.address!] !=
|
||||||
null) {
|
null) {
|
||||||
|
@ -542,7 +542,7 @@ class WalletViewScreen extends StatelessWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
balanceCache[defaultWallet.address!] =
|
balanceCache[defaultWallet.address!] =
|
||||||
balance.data!;
|
globalBalance.data!['transferableBalance']!;
|
||||||
return Text(
|
return Text(
|
||||||
"${balanceCache[defaultWallet.address!]} $currencyName",
|
"${balanceCache[defaultWallet.address!]} $currencyName",
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
|
|
Loading…
Reference in New Issue