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;
|
||||
|
||||
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/widgets_keys.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/wallets_profiles.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;
|
||||
await configBox.put('isUdUnit', !isUdUnit);
|
||||
balanceCache = {};
|
||||
sub.getBalanceRatio();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
|
|
@ -160,6 +160,13 @@ class SubstrateSdk with ChangeNotifier {
|
|||
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 {
|
||||
// log.d('currencyParameters: $currencyParameters');
|
||||
|
||||
|
@ -192,10 +199,6 @@ class SubstrateSdk with ChangeNotifier {
|
|||
final int transferableBalance =
|
||||
(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');
|
||||
|
||||
Map<String, double> finalBalances = {
|
||||
|
@ -428,6 +431,8 @@ class SubstrateSdk with ChangeNotifier {
|
|||
});
|
||||
|
||||
await initCurrencyParameters();
|
||||
await getBalanceRatio();
|
||||
|
||||
notifyListeners();
|
||||
homeProvider.changeMessage(
|
||||
"wellConnectedToNode"
|
||||
|
@ -691,7 +696,6 @@ class SubstrateSdk with ChangeNotifier {
|
|||
required double amount,
|
||||
required String password}) async {
|
||||
transactionStatus = '';
|
||||
final int amountUnit = (amount * 100).toInt();
|
||||
|
||||
final sender = await _setSender(fromAddress);
|
||||
|
||||
|
@ -710,12 +714,15 @@ class SubstrateSdk with ChangeNotifier {
|
|||
txOptions = [destAddress, false];
|
||||
tx2 = 'api.tx.balances.transferAll("$destAddress", false)';
|
||||
} else {
|
||||
int amountUnit;
|
||||
if (isUdUnit) {
|
||||
palette = 'universalDividend';
|
||||
call = 'transferUd';
|
||||
amountUnit = (amount * 1000).toInt();
|
||||
} else {
|
||||
palette = 'balances';
|
||||
call = 'transferKeepAlive';
|
||||
amountUnit = (amount * 100).toInt();
|
||||
}
|
||||
txOptions = [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;
|
||||
|
||||
if (isUdUnit) {
|
||||
amount = round(amount / (sub.udValue / 1000));
|
||||
amount = round(amount / balanceRatio);
|
||||
finalAmount = 'ud'.tr(args: ['$amount ']);
|
||||
} else {
|
||||
finalAmount = '$amount $currencyName';
|
||||
|
|
|
@ -85,7 +85,7 @@ class SettingsScreen extends StatelessWidget {
|
|||
return InkWell(
|
||||
key: keyUdUnit,
|
||||
onTap: () async {
|
||||
await homeProvider.changeCurrencyUnit();
|
||||
await homeProvider.changeCurrencyUnit(context);
|
||||
},
|
||||
child: SizedBox(
|
||||
height: 50,
|
||||
|
|
|
@ -398,7 +398,6 @@ void paymentPopup(BuildContext context, String toAddress) {
|
|||
|
||||
final myWalletProvider =
|
||||
Provider.of<MyWalletsProvider>(context, listen: false);
|
||||
final sub = Provider.of<SubstrateSdk>(context, listen: false);
|
||||
|
||||
const double shapeSize = 20;
|
||||
WalletData? defaultWallet = myWalletProvider.getDefaultWallet();
|
||||
|
@ -406,10 +405,6 @@ void paymentPopup(BuildContext context, String toAddress) {
|
|||
|
||||
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);
|
||||
|
||||
Future executeTransfert() async {
|
||||
|
|
Loading…
Reference in New Issue