WIP: unclaimed UD are almost calculated

This commit is contained in:
poka 2022-08-09 10:19:16 +02:00
parent 29754e23b5
commit d71261d0ec
1 changed files with 33 additions and 21 deletions

View File

@ -265,37 +265,49 @@ class SubstrateSdk with ChangeNotifier {
} else { } else {
balance = -1; balance = -1;
} }
await getUnclaimedUd(address);
return balance; return balance;
} }
Future<double> getUnclaimedUd(String address) async { Future<double> getUnclaimedUd(String address) async {
// TODO: Implement unclaimedUd evaluation final balanceGlobal = await sdk.webView!
// Pour ce faire, il vous faut requêter cinq éléments de storage : .evalJavascript('api.query.system.account("$address")');
// system.account(address) final idtyIndex = await sdk.webView!
// identity.identityIndexOf(address) .evalJavascript('api.query.identity.identityIndexOf("$address")');
// identity.identities(idtyIndex) final idtyData = await sdk.webView!
// universalDividend.currentUdIndex() .evalJavascript('api.query.identity.identities($idtyIndex)');
// universalDividend.pastReevals()
// const api = await ApiPromise.create(...); final int currentUdIndex = int.parse(await sdk.webView!
// const { data: balance } = await api.query.system.account(address); .evalJavascript('api.query.universalDividend.currentUdIndex()'));
// const idtyIndex = await api.query.identity.identityIndexOf(address);
// const { data: idtyData } = await api.query.identity.identies(idtyIndex);
// const currentUdIndex = await api.query.universalDividend.currentUdIndex();
// const pastReevals = await api.query.universalDividend.pastReevals();
// let newUdsAmount = computeClaimUds(currentUdIndex, idtyData.firstEligibleUd, pastReevals); final List pastReevals = await sdk.webView!
// let transferableBalance = balance.free + newUdsAmount; .evalJavascript('api.query.universalDividend.pastReevals()');
// let potentialBalance = balance.reserved + transferableBalance;
double balance = 0.0; log.d(
'DEBUGG ${getShortPubkey(address)} : $balanceGlobal |---| $idtyIndex |---| $idtyData |---| $currentUdIndex |---| $pastReevals');
final brutBalance = await sdk.api.account.queryBalance(address); final int newUdsAmount = _computeClaimUds(currentUdIndex,
// log.d(brutBalance?.toJson()); idtyData?['data']?['firstEligibleUd'] ?? 0, pastReevals);
balance = int.parse(brutBalance!.freeBalance) / 100;
return balance; final double transferableBalance =
(balanceGlobal['data']['free'] + newUdsAmount) / 100;
final double potentialBalance =
(balanceGlobal['data']['reserved'] + transferableBalance) / 100;
log.i(
'transferableBalance: $transferableBalance --- potentialBalance: $potentialBalance');
return transferableBalance;
}
int _computeClaimUds(
int currentUdIndex, int firstEligibleUd, List pastReevals) {
// TODO: Implement _computeClaimUds
log.d('DEBUGGG: $currentUdIndex - $firstEligibleUd - $pastReevals');
return 0;
} }
Future<double> subscribeBalance(String address, {bool isUd = false}) async { Future<double> subscribeBalance(String address, {bool isUd = false}) async {