forked from axiom-team/gecko
refactor Ud ratio compute
This commit is contained in:
parent
a0d6bfaf22
commit
bf58e8e3d1
|
@ -48,3 +48,5 @@ String currencyName = 'ĞD';
|
||||||
const debugPin = true;
|
const debugPin = true;
|
||||||
|
|
||||||
String indexerEndpoint = '';
|
String indexerEndpoint = '';
|
||||||
|
late double balanceRatio;
|
||||||
|
late int udValue;
|
||||||
|
|
|
@ -13,6 +13,7 @@ import 'package:gecko/globals.dart';
|
||||||
import 'package:gecko/models/wallet_data.dart';
|
import 'package:gecko/models/wallet_data.dart';
|
||||||
import 'package:gecko/models/widgets_keys.dart';
|
import 'package:gecko/models/widgets_keys.dart';
|
||||||
import 'package:gecko/providers/my_wallets.dart';
|
import 'package:gecko/providers/my_wallets.dart';
|
||||||
|
import 'package:gecko/providers/substrate_sdk.dart';
|
||||||
import 'package:gecko/providers/wallet_options.dart';
|
import 'package:gecko/providers/wallet_options.dart';
|
||||||
import 'package:gecko/providers/wallets_profiles.dart';
|
import 'package:gecko/providers/wallets_profiles.dart';
|
||||||
import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
|
import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
|
||||||
|
@ -64,10 +65,12 @@ class HomeProvider with ChangeNotifier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future changeCurrencyUnit() async {
|
Future changeCurrencyUnit(BuildContext context) async {
|
||||||
|
final sub = Provider.of<SubstrateSdk>(context, listen: false);
|
||||||
final bool isUdUnit = configBox.get('isUdUnit') ?? false;
|
final bool isUdUnit = configBox.get('isUdUnit') ?? false;
|
||||||
await configBox.put('isUdUnit', !isUdUnit);
|
await configBox.put('isUdUnit', !isUdUnit);
|
||||||
balanceCache = {};
|
balanceCache = {};
|
||||||
|
sub.getBalanceRatio();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -160,6 +160,13 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
return udValue;
|
return udValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<double> getBalanceRatio() async {
|
||||||
|
udValue = await getUdValue();
|
||||||
|
balanceRatio =
|
||||||
|
(configBox.get('isUdUnit') ?? false) ? round(udValue / 100, 6) : 1;
|
||||||
|
return balanceRatio;
|
||||||
|
}
|
||||||
|
|
||||||
Future<Map<String, double>> getBalance(String address) async {
|
Future<Map<String, double>> getBalance(String address) async {
|
||||||
// log.d('currencyParameters: $currencyParameters');
|
// log.d('currencyParameters: $currencyParameters');
|
||||||
|
|
||||||
|
@ -192,10 +199,6 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
final int transferableBalance =
|
final int transferableBalance =
|
||||||
(balanceGlobal['data']['free'] + unclaimedUds);
|
(balanceGlobal['data']['free'] + unclaimedUds);
|
||||||
|
|
||||||
final bool isUdUnit = configBox.get('isUdUnit') ?? false;
|
|
||||||
final udValue = await getUdValue();
|
|
||||||
final double balanceRatio = isUdUnit ? round(udValue / 1000, 6) : 1;
|
|
||||||
|
|
||||||
// log.d('udValue: $udValue');
|
// log.d('udValue: $udValue');
|
||||||
|
|
||||||
Map<String, double> finalBalances = {
|
Map<String, double> finalBalances = {
|
||||||
|
@ -428,6 +431,8 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
});
|
});
|
||||||
|
|
||||||
await initCurrencyParameters();
|
await initCurrencyParameters();
|
||||||
|
await getBalanceRatio();
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
homeProvider.changeMessage(
|
homeProvider.changeMessage(
|
||||||
"wellConnectedToNode"
|
"wellConnectedToNode"
|
||||||
|
@ -691,7 +696,6 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
required double amount,
|
required double amount,
|
||||||
required String password}) async {
|
required String password}) async {
|
||||||
transactionStatus = '';
|
transactionStatus = '';
|
||||||
final int amountUnit = (amount * 100).toInt();
|
|
||||||
|
|
||||||
final sender = await _setSender(fromAddress);
|
final sender = await _setSender(fromAddress);
|
||||||
|
|
||||||
|
@ -710,12 +714,15 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
txOptions = [destAddress, false];
|
txOptions = [destAddress, false];
|
||||||
tx2 = 'api.tx.balances.transferAll("$destAddress", false)';
|
tx2 = 'api.tx.balances.transferAll("$destAddress", false)';
|
||||||
} else {
|
} else {
|
||||||
|
int amountUnit;
|
||||||
if (isUdUnit) {
|
if (isUdUnit) {
|
||||||
palette = 'universalDividend';
|
palette = 'universalDividend';
|
||||||
call = 'transferUd';
|
call = 'transferUd';
|
||||||
|
amountUnit = (amount * 1000).toInt();
|
||||||
} else {
|
} else {
|
||||||
palette = 'balances';
|
palette = 'balances';
|
||||||
call = 'transferKeepAlive';
|
call = 'transferKeepAlive';
|
||||||
|
amountUnit = (amount * 100).toInt();
|
||||||
}
|
}
|
||||||
txOptions = [destAddress, amountUnit];
|
txOptions = [destAddress, amountUnit];
|
||||||
tx2 = 'api.tx.$palette.$call("$destAddress", $amountUnit)';
|
tx2 = 'api.tx.$palette.$call("$destAddress", $amountUnit)';
|
||||||
|
|
|
@ -281,7 +281,7 @@ class ActivityScreen extends StatelessWidget with ChangeNotifier {
|
||||||
amount = repository[4] == 'RECEIVED' ? repository[3] : repository[3] * -1;
|
amount = repository[4] == 'RECEIVED' ? repository[3] : repository[3] * -1;
|
||||||
|
|
||||||
if (isUdUnit) {
|
if (isUdUnit) {
|
||||||
amount = round(amount / (sub.udValue / 1000));
|
amount = round(amount / balanceRatio);
|
||||||
finalAmount = 'ud'.tr(args: ['$amount ']);
|
finalAmount = 'ud'.tr(args: ['$amount ']);
|
||||||
} else {
|
} else {
|
||||||
finalAmount = '$amount $currencyName';
|
finalAmount = '$amount $currencyName';
|
||||||
|
|
|
@ -85,7 +85,7 @@ class SettingsScreen extends StatelessWidget {
|
||||||
return InkWell(
|
return InkWell(
|
||||||
key: keyUdUnit,
|
key: keyUdUnit,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
await homeProvider.changeCurrencyUnit();
|
await homeProvider.changeCurrencyUnit(context);
|
||||||
},
|
},
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 50,
|
height: 50,
|
||||||
|
|
|
@ -398,7 +398,6 @@ void paymentPopup(BuildContext context, String toAddress) {
|
||||||
|
|
||||||
final myWalletProvider =
|
final myWalletProvider =
|
||||||
Provider.of<MyWalletsProvider>(context, listen: false);
|
Provider.of<MyWalletsProvider>(context, listen: false);
|
||||||
final sub = Provider.of<SubstrateSdk>(context, listen: false);
|
|
||||||
|
|
||||||
const double shapeSize = 20;
|
const double shapeSize = 20;
|
||||||
WalletData? defaultWallet = myWalletProvider.getDefaultWallet();
|
WalletData? defaultWallet = myWalletProvider.getDefaultWallet();
|
||||||
|
@ -406,10 +405,6 @@ void paymentPopup(BuildContext context, String toAddress) {
|
||||||
|
|
||||||
bool canValidate = false;
|
bool canValidate = false;
|
||||||
|
|
||||||
final bool isUdUnit = configBox.get('isUdUnit') ?? false;
|
|
||||||
final udValue = sub.udValue;
|
|
||||||
final double balanceRatio = isUdUnit ? round(udValue / 1000, 6) : 1;
|
|
||||||
|
|
||||||
final toWalletData = myWalletProvider.getWalletDataByAddress(toAddress);
|
final toWalletData = myWalletProvider.getWalletDataByAddress(toAddress);
|
||||||
|
|
||||||
Future executeTransfert() async {
|
Future executeTransfert() async {
|
||||||
|
|
Loading…
Reference in New Issue