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

View File

@ -786,7 +786,7 @@ Future<void> shieldTAddr(BuildContext context) async {
final s = S.of(context); final s = S.of(context);
Navigator.of(context).pop(); Navigator.of(context).pop();
showSnackBar(s.shieldingInProgress, autoClose: true); 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)); showSnackBar(s.txId(txid));
})), })),
); );

View File

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

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

View File

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

View File

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

View File

@ -461,6 +461,7 @@ class NativeLibrary {
int from_pool, int from_pool,
int to_pool, int to_pool,
int amount, int amount,
int fee_included,
ffi.Pointer<ffi.Int8> memo, ffi.Pointer<ffi.Int8> memo,
int split_amount, int split_amount,
int confirmations, int confirmations,
@ -471,6 +472,7 @@ class NativeLibrary {
from_pool, from_pool,
to_pool, to_pool,
amount, amount,
fee_included,
memo, memo,
split_amount, split_amount,
confirmations, confirmations,
@ -485,11 +487,13 @@ class NativeLibrary {
CResult_____c_char shield_taddr( CResult_____c_char shield_taddr(
int coin, int coin,
int account, int account,
int amount,
int confirmations, int confirmations,
) { ) {
return _shield_taddr( return _shield_taddr(
coin, coin,
account, account,
amount,
confirmations, confirmations,
); );
} }
@ -1264,6 +1268,7 @@ typedef _c_transfer_pools = CResult_____c_char Function(
ffi.Uint8 from_pool, ffi.Uint8 from_pool,
ffi.Uint8 to_pool, ffi.Uint8 to_pool,
ffi.Uint64 amount, ffi.Uint64 amount,
ffi.Int8 fee_included,
ffi.Pointer<ffi.Int8> memo, ffi.Pointer<ffi.Int8> memo,
ffi.Uint64 split_amount, ffi.Uint64 split_amount,
ffi.Uint32 confirmations, ffi.Uint32 confirmations,
@ -1275,6 +1280,7 @@ typedef _dart_transfer_pools = CResult_____c_char Function(
int from_pool, int from_pool,
int to_pool, int to_pool,
int amount, int amount,
int fee_included,
ffi.Pointer<ffi.Int8> memo, ffi.Pointer<ffi.Int8> memo,
int split_amount, int split_amount,
int confirmations, int confirmations,
@ -1283,12 +1289,14 @@ typedef _dart_transfer_pools = CResult_____c_char Function(
typedef _c_shield_taddr = CResult_____c_char Function( typedef _c_shield_taddr = CResult_____c_char Function(
ffi.Uint8 coin, ffi.Uint8 coin,
ffi.Uint32 account, ffi.Uint32 account,
ffi.Uint64 amount,
ffi.Uint32 confirmations, ffi.Uint32 confirmations,
); );
typedef _dart_shield_taddr = CResult_____c_char Function( typedef _dart_shield_taddr = CResult_____c_char Function(
int coin, int coin,
int account, int account,
int amount,
int confirmations, 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. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at # Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.2.17+316 version: 1.2.17+317
environment: environment:
sdk: ">=2.12.0 <3.0.0" sdk: ">=2.12.0 <3.0.0"