fiat fixes

This commit is contained in:
fosse 2023-08-21 16:10:22 -04:00
parent cf42991891
commit 53a1ffe40f
6 changed files with 77 additions and 85 deletions

View file

@ -119,7 +119,6 @@ class NanoUtil {
// static String hdSeedToAddress(String seed, int index) {
// // return NanoAccounts.createAccount(NanoAccountType.NANO, NanoKeys.createPublicKey(seedToPrivate(seed, index)));
// return "";
// }

View file

@ -177,11 +177,15 @@ abstract class NanoWalletBase
BigInt.zero;
}
if (balance[currency]?.currentBalance != null && amt > balance[currency]!.currentBalance) {
throw Exception("Trying to send more than entire balance!");
}
runningBalance = runningBalance - amt;
final block = await _client.constructSendBlock(
amountRaw: amt.toString(),
destinationAddress: txOut.address,
destinationAddress: txOut.extractedAddress ?? txOut.address,
privateKey: _privateKey!,
balanceAfterTx: runningBalance,
previousHash: previousHash,

View file

@ -20,6 +20,11 @@ class PendingNanoTransaction with PendingTransaction {
@override
String get amountFormatted {
final String amt = NanoUtil.getRawAsUsableString(amount.toString(), NanoUtil.rawPerNano);
return amt;
}
String get accurateAmountFormatted {
final String amt = NanoUtil.getRawAsUsableString(amount.toString(), NanoUtil.rawPerNano);
final String acc = NanoUtil.getRawAccuracy(amount.toString(), NanoUtil.rawPerNano);
return "$acc$amt";

View file

@ -66,9 +66,8 @@ class SendPage extends BasePage {
color: titleColor(context),
size: 16,
);
final _closeButton = currentTheme.type == ThemeType.dark
? closeButtonImageDarkTheme
: closeButtonImage;
final _closeButton =
currentTheme.type == ThemeType.dark ? closeButtonImageDarkTheme : closeButtonImage;
bool isMobileView = ResponsiveLayoutUtil.instance.isMobile;
@ -79,13 +78,10 @@ class SendPage extends BasePage {
child: ButtonTheme(
minWidth: double.minPositive,
child: Semantics(
label: !isMobileView
? S.of(context).close
: S.of(context).seed_alert_back,
label: !isMobileView ? S.of(context).close : S.of(context).seed_alert_back,
child: TextButton(
style: ButtonStyle(
overlayColor: MaterialStateColor.resolveWith(
(states) => Colors.transparent),
overlayColor: MaterialStateColor.resolveWith((states) => Colors.transparent),
),
onPressed: () => onClose(context),
child: !isMobileView ? _closeButton : _backButton,
@ -123,8 +119,7 @@ class SendPage extends BasePage {
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Observer(
builder: (_) =>
SyncIndicatorIcon(isSynced: sendViewModel.isReadyForSend),
builder: (_) => SyncIndicatorIcon(isSynced: sendViewModel.isReadyForSend),
),
),
if (supMiddle != null) supMiddle
@ -158,10 +153,10 @@ class SendPage extends BasePage {
_setEffects(context);
return GestureDetector(
onLongPress: () => sendViewModel.balanceViewModel.isReversing =
!sendViewModel.balanceViewModel.isReversing,
onLongPressUp: () => sendViewModel.balanceViewModel.isReversing =
!sendViewModel.balanceViewModel.isReversing,
onLongPress: () =>
sendViewModel.balanceViewModel.isReversing = !sendViewModel.balanceViewModel.isReversing,
onLongPressUp: () =>
sendViewModel.balanceViewModel.isReversing = !sendViewModel.balanceViewModel.isReversing,
child: Form(
key: _formKey,
child: ScrollableWithBottomSection(
@ -191,8 +186,7 @@ class SendPage extends BasePage {
},
)),
Padding(
padding: EdgeInsets.only(
top: 10, left: 24, right: 24, bottom: 10),
padding: EdgeInsets.only(top: 10, left: 24, right: 24, bottom: 10),
child: Container(
height: 10,
child: Observer(
@ -208,8 +202,12 @@ class SendPage extends BasePage {
radius: 6.0,
dotWidth: 6.0,
dotHeight: 6.0,
dotColor: Theme.of(context).extension<SendPageTheme>()!.indicatorDotColor,
activeDotColor: Theme.of(context).extension<SendPageTheme>()!.templateBackgroundColor),
dotColor: Theme.of(context)
.extension<SendPageTheme>()!
.indicatorDotColor,
activeDotColor: Theme.of(context)
.extension<SendPageTheme>()!
.templateBackgroundColor),
)
: Offstage();
},
@ -230,8 +228,7 @@ class SendPage extends BasePage {
return Row(
children: <Widget>[
AddTemplateButton(
onTap: () => Navigator.of(context)
.pushNamed(Routes.sendTemplate),
onTap: () => Navigator.of(context).pushNamed(Routes.sendTemplate),
currentTemplatesLength: templates.length,
),
ListView.builder(
@ -244,9 +241,8 @@ class SendPage extends BasePage {
return TemplateTile(
key: UniqueKey(),
to: template.name,
hasMultipleRecipients:
template.additionalRecipients != null &&
template.additionalRecipients!.length > 1,
hasMultipleRecipients: template.additionalRecipients != null &&
template.additionalRecipients!.length > 1,
amount: template.isCurrencySelected
? template.amount
: template.amountFiat,
@ -257,7 +253,9 @@ class SendPage extends BasePage {
if (template.additionalRecipients?.isNotEmpty ?? false) {
sendViewModel.clearOutputs();
for (int i = 0;i < template.additionalRecipients!.length;i++) {
for (int i = 0;
i < template.additionalRecipients!.length;
i++) {
Output output;
try {
output = sendViewModel.outputs[i];
@ -286,26 +284,17 @@ class SendPage extends BasePage {
context: context,
builder: (dialogContext) {
return AlertWithTwoActions(
alertTitle:
S.of(context).template,
alertContent: S
.of(context)
.confirm_delete_template,
rightButtonText:
S.of(context).delete,
leftButtonText:
S.of(context).cancel,
alertTitle: S.of(context).template,
alertContent: S.of(context).confirm_delete_template,
rightButtonText: S.of(context).delete,
leftButtonText: S.of(context).cancel,
actionRightButton: () {
Navigator.of(dialogContext)
.pop();
sendViewModel
.sendTemplateViewModel
.removeTemplate(
template: template);
Navigator.of(dialogContext).pop();
sendViewModel.sendTemplateViewModel
.removeTemplate(template: template);
},
actionLeftButton: () =>
Navigator.of(dialogContext)
.pop());
Navigator.of(dialogContext).pop());
},
);
},
@ -321,8 +310,7 @@ class SendPage extends BasePage {
],
),
),
bottomSectionPadding:
EdgeInsets.only(left: 24, right: 24, bottom: 24),
bottomSectionPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
bottomSection: Column(
children: [
if (sendViewModel.hasCurrecyChanger)
@ -331,10 +319,10 @@ class SendPage extends BasePage {
padding: EdgeInsets.only(bottom: 12),
child: PrimaryButton(
onPressed: () => presentCurrencyPicker(context),
text:
'Change your asset (${sendViewModel.selectedCryptoCurrency})',
text: 'Change your asset (${sendViewModel.selectedCryptoCurrency})',
color: Colors.transparent,
textColor: Theme.of(context).extension<SeedWidgetTheme>()!.hintTextColor,
textColor:
Theme.of(context).extension<SeedWidgetTheme>()!.hintTextColor,
))),
if (sendViewModel.sendTemplateViewModel.hasMultiRecipient)
Padding(
@ -343,22 +331,21 @@ class SendPage extends BasePage {
onPressed: () {
sendViewModel.addOutput();
Future.delayed(const Duration(milliseconds: 250), () {
controller
.jumpToPage(sendViewModel.outputs.length - 1);
controller.jumpToPage(sendViewModel.outputs.length - 1);
});
},
text: S.of(context).add_receiver,
color: Colors.transparent,
textColor: Theme.of(context).extension<SeedWidgetTheme>()!.hintTextColor,
isDottedBorder: true,
borderColor: Theme.of(context).extension<SendPageTheme>()!.templateDottedBorderColor,
borderColor:
Theme.of(context).extension<SendPageTheme>()!.templateDottedBorderColor,
)),
Observer(
builder: (_) {
return LoadingPrimaryButton(
onPressed: () async {
if (_formKey.currentState != null &&
!_formKey.currentState!.validate()) {
if (_formKey.currentState != null && !_formKey.currentState!.validate()) {
if (sendViewModel.outputs.length > 1) {
showErrorValidationAlert(context);
}
@ -367,9 +354,7 @@ class SendPage extends BasePage {
}
final notValidItems = sendViewModel.outputs
.where((item) =>
item.address.isEmpty ||
item.cryptoAmount.isEmpty)
.where((item) => item.address.isEmpty || item.cryptoAmount.isEmpty)
.toList();
if (notValidItems.isNotEmpty) {
@ -389,8 +374,7 @@ class SendPage extends BasePage {
);
},
text: S.of(context).send,
color:
Theme.of(context).primaryColor,
color: Theme.of(context).primaryColor,
textColor: Colors.white,
isLoading: sendViewModel.state is IsExecutingState ||
sendViewModel.state is TransactionCommitting,
@ -433,14 +417,11 @@ class SendPage extends BasePage {
return ConfirmSendingAlert(
alertTitle: S.of(context).confirm_sending,
amount: S.of(context).send_amount,
amountValue:
sendViewModel.pendingTransaction!.amountFormatted,
fiatAmountValue:
sendViewModel.pendingTransactionFiatAmountFormatted,
amountValue: sendViewModel.pendingTransaction!.amountFormatted,
fiatAmountValue: sendViewModel.pendingTransactionFiatAmountFormatted,
fee: S.of(context).send_fee,
feeValue: sendViewModel.pendingTransaction!.feeFormatted,
feeFiatAmount: sendViewModel
.pendingTransactionFeeFiatAmountFormatted,
feeFiatAmount: sendViewModel.pendingTransactionFeeFiatAmountFormatted,
outputs: sendViewModel.outputs,
rightButtonText: S.of(context).ok,
leftButtonText: S.of(context).cancel,
@ -461,8 +442,7 @@ class SendPage extends BasePage {
return AlertWithOneAction(
alertTitle: '',
alertContent: S.of(context).send_success(
sendViewModel.selectedCryptoCurrency
.toString()),
sendViewModel.selectedCryptoCurrency.toString()),
buttonText: S.of(context).ok,
buttonAction: () {
Navigator.of(context).pop();
@ -492,8 +472,8 @@ class SendPage extends BasePage {
Future<void> _setInputsFromTemplate(BuildContext context,
{required Output output, required Template template}) async {
final fiatFromTemplate = FiatCurrency.all
.singleWhere((element) => element.title == template.fiatCurrency);
final fiatFromTemplate =
FiatCurrency.all.singleWhere((element) => element.title == template.fiatCurrency);
output.address = template.address;
@ -534,12 +514,11 @@ class SendPage extends BasePage {
builder: (_) => Picker(
items: sendViewModel.currencies,
displayItem: (Object item) => item.toString(),
selectedAtIndex: sendViewModel.currencies
.indexOf(sendViewModel.selectedCryptoCurrency),
selectedAtIndex:
sendViewModel.currencies.indexOf(sendViewModel.selectedCryptoCurrency),
title: S.of(context).please_select,
mainAxisAlignment: MainAxisAlignment.center,
onItemSelected: (CryptoCurrency cur) =>
sendViewModel.selectedCryptoCurrency = cur,
onItemSelected: (CryptoCurrency cur) => sendViewModel.selectedCryptoCurrency = cur,
),
context: context);
}

View file

@ -167,8 +167,10 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
AddressTextFieldOption.qrCode,
AddressTextFieldOption.addressBook
],
buttonColor: Theme.of(context).extension<SendPageTheme>()!.textFieldButtonColor,
borderColor: Theme.of(context).extension<SendPageTheme>()!.textFieldBorderColor,
buttonColor:
Theme.of(context).extension<SendPageTheme>()!.textFieldButtonColor,
borderColor:
Theme.of(context).extension<SendPageTheme>()!.textFieldBorderColor,
textStyle: TextStyle(
fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white),
hintStyle: TextStyle(
@ -419,11 +421,13 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
),
),
hintText: '0.00',
borderColor: Theme.of(context).extension<SendPageTheme>()!.textFieldBorderColor,
borderColor:
Theme.of(context).extension<SendPageTheme>()!.textFieldBorderColor,
textStyle: TextStyle(
fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white),
placeholderTextStyle: TextStyle(
color: Theme.of(context).extension<SendPageTheme>()!.textFieldHintColor,
color:
Theme.of(context).extension<SendPageTheme>()!.textFieldHintColor,
fontWeight: FontWeight.w500,
fontSize: 14),
),
@ -434,7 +438,8 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
controller: noteController,
keyboardType: TextInputType.multiline,
maxLines: null,
borderColor: Theme.of(context).extension<SendPageTheme>()!.textFieldBorderColor,
borderColor:
Theme.of(context).extension<SendPageTheme>()!.textFieldBorderColor,
textStyle: TextStyle(
fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white),
hintText: S.of(context).note_optional,

View file

@ -96,15 +96,15 @@ abstract class SendViewModelBase with Store {
@computed
String get pendingTransactionFiatAmount {
if (pendingTransaction == null) {
return '0.00';
}
try {
if (pendingTransaction != null) {
final fiat = calculateFiatAmount(
price: _fiatConversationStore.prices[selectedCryptoCurrency]!,
cryptoAmount: pendingTransaction!.amountFormatted);
return fiat;
} else {
return '0.00';
}
final fiat = calculateFiatAmount(
price: _fiatConversationStore.prices[selectedCryptoCurrency]!,
cryptoAmount: pendingTransaction!.amountFormatted);
return fiat;
} catch (_) {
return '0.00';
}