prepare to implement unclaimedUd evaluation

This commit is contained in:
poka 2022-08-08 19:40:24 +02:00
parent 175334457a
commit 29754e23b5
1 changed files with 32 additions and 1 deletions

View File

@ -255,11 +255,12 @@ class SubstrateSdk with ChangeNotifier {
return consumers == 0 ? false : true;
}
Future<double> getBalance(String address, {bool isUd = false}) async {
Future<double> getBalance(String address) async {
double balance = 0.0;
if (nodeConnected) {
final brutBalance = await sdk.api.account.queryBalance(address);
// log.d(brutBalance?.toJson());
balance = int.parse(brutBalance!.freeBalance) / 100;
} else {
balance = -1;
@ -267,6 +268,36 @@ class SubstrateSdk with ChangeNotifier {
return balance;
}
Future<double> getUnclaimedUd(String address) async {
// TODO: Implement unclaimedUd evaluation
// Pour ce faire, il vous faut requêter cinq éléments de storage :
// system.account(address)
// identity.identityIndexOf(address)
// identity.identities(idtyIndex)
// universalDividend.currentUdIndex()
// universalDividend.pastReevals()
// const api = await ApiPromise.create(...);
// const { data: balance } = await api.query.system.account(address);
// 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);
// let transferableBalance = balance.free + newUdsAmount;
// let potentialBalance = balance.reserved + transferableBalance;
double balance = 0.0;
final brutBalance = await sdk.api.account.queryBalance(address);
// log.d(brutBalance?.toJson());
balance = int.parse(brutBalance!.freeBalance) / 100;
return balance;
}
Future<double> subscribeBalance(String address, {bool isUd = false}) async {
double balance = 0.0;
if (nodeConnected) {