Payer or Recipient can pay the fees

This commit is contained in:
Hanh 2022-12-11 06:10:07 +08:00
parent c68fe8e2a0
commit 2817bb43cf
8 changed files with 54 additions and 22 deletions

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:mobx/mobx.dart';
import 'generated/l10n.dart';
@ -24,6 +25,7 @@ class DualMoneyInputState extends State<DualMoneyInputWidget> {
var amount = 0;
double sliderValue = 0;
var useMax = false;
var feeIncluded = false;
ReactionDisposer? priceAutorunDispose;
@ -68,7 +70,7 @@ class DualMoneyInputState extends State<DualMoneyInputWidget> {
inputInCoin = true;
}),
validator: _checkAmount,
onChanged: (_) { _updateFiatAmount(); _updateSlider(); },
onChanged: (_) { _updateFiatAmount(); _updateSlider(); _resetUseMax(); },
onSaved: _onAmount,
)),
if (widget.max) TextButton(child: Text(s.max), onPressed: _onMax),
@ -89,17 +91,28 @@ class DualMoneyInputState extends State<DualMoneyInputWidget> {
onTap: () => setState(() {
inputInCoin = false;
}),
onChanged: (_) { _updateAmount(); _updateSlider(); }))
onChanged: (_) { _updateAmount(); _updateSlider(); _resetUseMax(); }))
]),
if (widget.spendable != null)
Slider(value: sliderValue, onChanged: _onSliderChanged, min: 0, max: 100, divisions: 20,
label: "${sliderValue.toInt()} %")
]);
label: "${sliderValue.toInt()} %"),
if (widget.spendable != null) FormBuilderCheckbox(
key: UniqueKey(),
name: 'fee',
title: Text(s.includeFeeInAmount),
initialValue: feeIncluded || useMax,
onChanged: (v) {
setState(() {
feeIncluded = v ?? false;
});
}),
]);
}
void clear() {
setState(() {
useMax = false;
feeIncluded = false;
coinAmountController.text = zero;
fiatAmountController.text = zero;
});
@ -114,6 +127,7 @@ class DualMoneyInputState extends State<DualMoneyInputWidget> {
_onSliderChanged(double v) {
setState(() {
useMax = false;
sliderValue = v;
final a = (widget.spendable! * v / 100).round();
coinAmountController.text = amountToString(a, precision(settings.useMillis));
@ -126,11 +140,18 @@ class DualMoneyInputState extends State<DualMoneyInputWidget> {
final s = widget.spendable;
if (s != null) {
useMax = true;
sliderValue = 100;
setAmount(s);
}
});
}
void _resetUseMax() {
setState(() {
useMax = false;
});
}
String? _checkAmount(String? vs, {bool isFiat: false}) {
final s = S.of(context);
if (vs == null) return s.amountMustBeANumber;

View File

@ -786,7 +786,7 @@ Future<void> shieldTAddr(BuildContext context) async {
final s = S.of(context);
Navigator.of(context).pop();
showSnackBar(s.shieldingInProgress, autoClose: true);
final txid = await WarpApi.shieldTAddr(active.coin, active.id, settings.anchorOffset);
final txid = await WarpApi.shieldTAddr(active.coin, active.id, active.tbalance, settings.anchorOffset);
showSnackBar(s.txId(txid));
})),
);

View File

@ -170,9 +170,9 @@ class SendState extends State<SendPage> {
name: 'reply-to',
title: Text(s.includeReplyTo),
initialValue: _replyTo,
onChanged: (_) {
onChanged: (v) {
setState(() {
_replyTo = true;
_replyTo = v ?? false;
});
},
),
@ -254,11 +254,13 @@ class SendState extends State<SendPage> {
if (form.validate()) {
form.save();
final amount = amountInput?.amount ?? 0;
final feeIncluded = amountInput?.feeIncluded ?? false;
final memo = _memoController.text;
final subject = _subjectController.text;
final recipient = Recipient(
_address,
amount,
feeIncluded,
_replyTo,
subject,
memo,
@ -284,8 +286,7 @@ class SendState extends State<SendPage> {
_sBalance -
_excludedBalance -
_underConfirmedBalance -
_usedBalance -
_fee,
_usedBalance,
0);
get change => _unconfirmedSpentBalance + _unconfirmedBalance;
@ -331,8 +332,7 @@ class BalanceTable extends StatelessWidget {
tBalance -
excludedBalance -
underConfirmedBalance -
used -
fee,
used,
0);
}

@ -1 +1 @@
Subproject commit a817b05259d2f756ff4b5b834bce6d7a4881f697
Subproject commit 9e7677394fe5033cbbd005f9cead652f5de3d4e6

View File

@ -7,6 +7,7 @@ class Recipient {
// ignore: non_constant_identifier_names
final String address;
final int amount;
final bool fee_included;
// ignore: non_constant_identifier_names
final bool reply_to;
final String subject;
@ -14,7 +15,7 @@ class Recipient {
// ignore: non_constant_identifier_names
final int max_amount_per_note;
Recipient(this.address, this.amount, this.reply_to, this.subject, this.memo, this.max_amount_per_note);
Recipient(this.address, this.amount, this.fee_included, this.reply_to, this.subject, this.memo, this.max_amount_per_note);
factory Recipient.fromJson(Map<String, dynamic> json) =>
_$RecipientFromJson(json);

View File

@ -212,13 +212,13 @@ class WarpApi {
static Future<String> transferPools(int coin, int account, int fromPool, int toPool,
int amount, String memo, int splitAmount, int anchorOffset) async {
final txId = await compute(transferPoolsIsolateFn, TransferPoolsParams(coin, account, fromPool, toPool, amount, memo,
splitAmount, anchorOffset));
final txId = await compute(transferPoolsIsolateFn, TransferPoolsParams(coin, account, fromPool, toPool, amount,
false, memo, splitAmount, anchorOffset));
return txId;
}
static Future<String> shieldTAddr(int coin, int account, int anchorOffset) async {
final txId = await compute(shieldTAddrIsolateFn, ShieldTAddrParams(coin, account, anchorOffset));
static Future<String> shieldTAddr(int coin, int account, int amount, int anchorOffset) async {
final txId = await compute(shieldTAddrIsolateFn, ShieldTAddrParams(coin, account, amount, anchorOffset));
return txId;
}
@ -430,12 +430,12 @@ int getLatestHeightIsolateFn(Null n) {
String transferPoolsIsolateFn(TransferPoolsParams params) {
final txId = warp_api_lib.transfer_pools(params.coin, params.account, params.fromPool, params.toPool,
params.amount, toNative(params.memo), params.splitAmount, params.anchorOffset);
params.amount, params.takeFee ? 1 : 0, toNative(params.memo), params.splitAmount, params.anchorOffset);
return unwrapResultString(txId);
}
String shieldTAddrIsolateFn(ShieldTAddrParams params) {
final txId = warp_api_lib.shield_taddr(params.coin, params.account, params.anchorOffset);
final txId = warp_api_lib.shield_taddr(params.coin, params.account, params.amount, params.anchorOffset);
return unwrapResultString(txId);
}
@ -503,20 +503,22 @@ class TransferPoolsParams {
final int fromPool;
final int toPool;
final int amount;
final bool takeFee;
final String memo;
final int splitAmount;
final int anchorOffset;
TransferPoolsParams(this.coin, this.account, this.fromPool, this.toPool, this.amount, this.memo,
TransferPoolsParams(this.coin, this.account, this.fromPool, this.toPool, this.amount, this.takeFee, this.memo,
this.splitAmount, this.anchorOffset);
}
class ShieldTAddrParams {
final int coin;
final int account;
final int amount;
final int anchorOffset;
ShieldTAddrParams(this.coin, this.account, this.anchorOffset);
ShieldTAddrParams(this.coin, this.account, this.amount, this.anchorOffset);
}
class CommitContactsParams {

View File

@ -461,6 +461,7 @@ class NativeLibrary {
int from_pool,
int to_pool,
int amount,
int fee_included,
ffi.Pointer<ffi.Int8> memo,
int split_amount,
int confirmations,
@ -471,6 +472,7 @@ class NativeLibrary {
from_pool,
to_pool,
amount,
fee_included,
memo,
split_amount,
confirmations,
@ -485,11 +487,13 @@ class NativeLibrary {
CResult_____c_char shield_taddr(
int coin,
int account,
int amount,
int confirmations,
) {
return _shield_taddr(
coin,
account,
amount,
confirmations,
);
}
@ -1264,6 +1268,7 @@ typedef _c_transfer_pools = CResult_____c_char Function(
ffi.Uint8 from_pool,
ffi.Uint8 to_pool,
ffi.Uint64 amount,
ffi.Int8 fee_included,
ffi.Pointer<ffi.Int8> memo,
ffi.Uint64 split_amount,
ffi.Uint32 confirmations,
@ -1275,6 +1280,7 @@ typedef _dart_transfer_pools = CResult_____c_char Function(
int from_pool,
int to_pool,
int amount,
int fee_included,
ffi.Pointer<ffi.Int8> memo,
int split_amount,
int confirmations,
@ -1283,12 +1289,14 @@ typedef _dart_transfer_pools = CResult_____c_char Function(
typedef _c_shield_taddr = CResult_____c_char Function(
ffi.Uint8 coin,
ffi.Uint32 account,
ffi.Uint64 amount,
ffi.Uint32 confirmations,
);
typedef _dart_shield_taddr = CResult_____c_char Function(
int coin,
int account,
int amount,
int confirmations,
);

View File

@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.2.17+316
version: 1.2.17+317
environment:
sdk: ">=2.12.0 <3.0.0"