Skip to content

Commit

Permalink
add transfer limit with estimated fee & max amount button
Browse files Browse the repository at this point in the history
  • Loading branch information
RomeroYang committed Apr 17, 2021
1 parent b0b30b8 commit 2f902c3
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 50 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@
# 2.0.2-beta
- Add ChainX network support.
- Hide tips by default in tx confirm page.
- Fix known Bugs.

# 2.0.3-beta
- Add Edgeware network support.
- Update ChainX plugin.
- Update Laminar plugin to TC3.
- Fix known Bugs.
4 changes: 2 additions & 2 deletions lib/main-dev.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:polkawallet_plugin_kusama/polkawallet_plugin_kusama.dart';
import 'package:polkawallet_plugin_acala/polkawallet_plugin_acala.dart';
import 'package:polkawallet_plugin_laminar/polkawallet_plugin_laminar.dart';
import 'package:polkawallet_plugin_chainx/polkawallet_plugin_chainx.dart';
// import 'package:polkawallet_plugin_edgeware/polkawallet_plugin_edgeware.dart';
import 'package:polkawallet_plugin_edgeware/polkawallet_plugin_edgeware.dart';

import 'package:get_storage/get_storage.dart';

Expand All @@ -18,7 +18,7 @@ void main() async {
PluginAcala(),
PluginLaminar(),
PluginChainX(),
// PluginEdgeware(),
PluginEdgeware(),
];

runApp(WalletApp(_plugins, BuildTargets.dev));
Expand Down
4 changes: 2 additions & 2 deletions lib/main-google.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:polkawallet_plugin_kusama/polkawallet_plugin_kusama.dart';
import 'package:polkawallet_plugin_acala/polkawallet_plugin_acala.dart';
import 'package:polkawallet_plugin_laminar/polkawallet_plugin_laminar.dart';
import 'package:polkawallet_plugin_chainx/polkawallet_plugin_chainx.dart';
// import 'package:polkawallet_plugin_edgeware/polkawallet_plugin_edgeware.dart';
import 'package:polkawallet_plugin_edgeware/polkawallet_plugin_edgeware.dart';

import 'package:get_storage/get_storage.dart';

Expand All @@ -18,7 +18,7 @@ void main() async {
PluginAcala(),
PluginLaminar(),
PluginChainX(),
// PluginEdgeware(),
PluginEdgeware(),
];

runApp(WalletApp(_plugins, BuildTargets.playStore));
Expand Down
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:polkawallet_plugin_kusama/polkawallet_plugin_kusama.dart';
import 'package:polkawallet_plugin_acala/polkawallet_plugin_acala.dart';
import 'package:polkawallet_plugin_laminar/polkawallet_plugin_laminar.dart';
import 'package:polkawallet_plugin_chainx/polkawallet_plugin_chainx.dart';
// import 'package:polkawallet_plugin_edgeware/polkawallet_plugin_edgeware.dart';
import 'package:polkawallet_plugin_edgeware/polkawallet_plugin_edgeware.dart';

import 'package:get_storage/get_storage.dart';

Expand All @@ -18,7 +18,7 @@ void main() async {
PluginAcala(),
PluginLaminar(),
PluginChainX(),
// PluginEdgeware(),
PluginEdgeware(),
];

runApp(WalletApp(_plugins, BuildTargets.apk));
Expand Down
23 changes: 23 additions & 0 deletions lib/pages/assets/transfer/transferPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,23 @@ class _TransferPageState extends State<TransferPage> {
return fee.partialFee.toString();
}

Future<void> _setMaxAmount(BigInt available, String amountExist) async {
final decimals =
(widget.service.plugin.networkState.tokenDecimals ?? [12])[0];
final fee = await _getTxFee();
// keep double amount of estimated fee
final max = available -
Fmt.balanceInt(fee) * BigInt.two -
(_keepAlive ? Fmt.balanceInt(amountExist) : BigInt.zero);
if (mounted) {
setState(() {
_amountCtrl.text = max > BigInt.zero
? Fmt.bigIntToDouble(max, decimals).toStringAsFixed(8)
: '0';
});
}
}

Future<void> _initAccountTo(String address) async {
final acc = KeyPairData();
acc.address = address;
Expand Down Expand Up @@ -212,6 +229,12 @@ class _TransferPageState extends State<TransferPage> {
decimals,
lengthMax: 6,
)})',
suffix: GestureDetector(
child: Text(dic['amount.max'],
style: TextStyle(
color: Theme.of(context).primaryColor)),
onTap: () => _setMaxAmount(available, amountExist),
),
),
inputFormatters: [UI.decimalInputFormatter(decimals)],
controller: _amountCtrl,
Expand Down
1 change: 0 additions & 1 deletion lib/utils/UI.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';
import 'dart:io';

import 'package:app/common/consts.dart';
import 'package:app/main.dart';
import 'package:app/service/walletApi.dart';
import 'package:app/utils/i18n/index.dart';
import 'package:flutter/cupertino.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/format.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class AppFmt {
static bool checkPassword(String pass) {
var reg = RegExp(r'^(?![0-9]+$)(?![a-zA-Z]+$)[\S]{6,18}$');
var reg = RegExp(r'^(?![0-9]+$)(?![a-zA-Z]+$)[\S]{6,32}$');
return reg.hasMatch(pass);
}
}
1 change: 1 addition & 0 deletions lib/utils/i18n/en/assets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const Map<String, String> enAssets = {
'address.error': 'Invalid Address',
'address.subscan': 'More on Subscan',
'amount': 'Amount',
'amount.max': 'Max',
'amount.error': 'Invalid amount',
'amount.low': 'Insufficient balance',
'amount.exist': 'existential deposit',
Expand Down
1 change: 1 addition & 0 deletions lib/utils/i18n/zh/assets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const Map<String, String> zhAssets = {
'address.error': '无效地址',
'address.subscan': '前往 Subscan 查看更多',
'amount': '数量',
'amount.max': '最大值',
'amount.error': '格式错误',
'amount.low': '余额不足',
'amount.exist': '存活余额',
Expand Down
55 changes: 36 additions & 19 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -670,47 +670,64 @@ packages:
polkawallet_plugin_acala:
dependency: "direct main"
description:
path: "../../coding/polkawallet/polkawallet_plugin_acala"
relative: true
source: path
path: "."
ref: "8714c27a4f46e3f0277ab58b42eea547f7d33095"
resolved-ref: "8714c27a4f46e3f0277ab58b42eea547f7d33095"
url: "https://github.com/AcalaNetwork/polkawallet_plugin_acala.git"
source: git
version: "0.1.3"
polkawallet_plugin_chainx:
dependency: "direct main"
description:
path: "../../coding/polkawallet/polkawallet_plugin_chainx"
relative: true
source: path
path: "."
ref: "07b601d0aaae0b173e7a18006f7502b9bb55b32d"
resolved-ref: "07b601d0aaae0b173e7a18006f7502b9bb55b32d"
url: "https://github.com/true-eye/polkawallet_plugin_chainx.git"
source: git
version: "0.0.1"
polkawallet_plugin_edgeware:
dependency: "direct main"
description:
path: "."
ref: acdfd8bddce2075542e4678ef55855805700c752
resolved-ref: acdfd8bddce2075542e4678ef55855805700c752
url: "https://github.com/remzrn/polkawallet_plugin_edgeware.git"
source: git
version: "0.0.1"
polkawallet_plugin_kusama:
dependency: "direct main"
description:
path: "."
ref: f6f73b6896a6239f980063589fe1e1e3ef74ad78
resolved-ref: f6f73b6896a6239f980063589fe1e1e3ef74ad78
ref: a4ae23cc229016babf82fb0e6c85a6cb46ec16a3
resolved-ref: a4ae23cc229016babf82fb0e6c85a6cb46ec16a3
url: "https://github.com/polkawallet-io/polkawallet_plugin_kusama.git"
source: git
version: "0.1.4"
polkawallet_plugin_laminar:
dependency: "direct main"
description:
path: "../../coding/polkawallet/polkawallet_plugin_laminar"
relative: true
source: path
path: "."
ref: a6bcda75198f64b70e0f13f6c71f067b72d536b0
resolved-ref: a6bcda75198f64b70e0f13f6c71f067b72d536b0
url: "https://github.com/polkawallet-io/polkawallet_plugin_laminar.git"
source: git
version: "0.1.5"
polkawallet_sdk:
dependency: "direct overridden"
description:
path: "../../coding/polkawallet/sdk"
relative: true
source: path
version: "0.1.4"
name: polkawallet_sdk
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.5"
polkawallet_ui:
dependency: "direct overridden"
description:
path: "../../coding/polkawallet/ui"
relative: true
source: path
version: "0.1.4"
path: "."
ref: "51ebe9ffe2c9a0c524aadffc03cbe413d891fa57"
resolved-ref: "51ebe9ffe2c9a0c524aadffc03cbe413d891fa57"
url: "https://github.com/polkawallet-io/ui.git"
source: git
version: "0.1.5"
pool:
dependency: transitive
description:
Expand Down
47 changes: 24 additions & 23 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,27 @@ dependencies:
polkawallet_plugin_kusama:
git:
url: https://github.com/polkawallet-io/polkawallet_plugin_kusama.git
ref: f6f73b6896a6239f980063589fe1e1e3ef74ad78
ref: a4ae23cc229016babf82fb0e6c85a6cb46ec16a3
# path: ../../coding/polkawallet/polkawallet_plugin_kusama
polkawallet_plugin_acala:
# git:
# url: https://github.com/AcalaNetwork/polkawallet_plugin_acala.git
# ref: 2c6e11ba04331b402c238e5bc6b8df72f2bf06d2
path: ../../coding/polkawallet/polkawallet_plugin_acala
git:
url: https://github.com/AcalaNetwork/polkawallet_plugin_acala.git
ref: 8714c27a4f46e3f0277ab58b42eea547f7d33095
# path: ../../coding/polkawallet/polkawallet_plugin_acala
polkawallet_plugin_laminar:
# git:
# url: https://github.com/polkawallet-io/polkawallet_plugin_laminar.git
# ref: b115aa0ab5b341bcfa3b7f5e239ed22f2026f82b
path: ../../coding/polkawallet/polkawallet_plugin_laminar
git:
url: https://github.com/polkawallet-io/polkawallet_plugin_laminar.git
ref: a6bcda75198f64b70e0f13f6c71f067b72d536b0
# path: ../../coding/polkawallet/polkawallet_plugin_laminar
polkawallet_plugin_chainx:
# git:
# url: https://github.com/true-eye/polkawallet_plugin_chainx.git
# ref: 1659c6c5b92ef7deb38e3071284634cf1b6b40b7
path: ../../coding/polkawallet/polkawallet_plugin_chainx
# polkawallet_plugin_edgeware:
## git:
## url: https://github.com/remzrn/polkawallet_plugin_edgeware.git
## ref: 1e06fd124615d4dfee52ff5e6232361cacd0dcff
git:
url: https://github.com/true-eye/polkawallet_plugin_chainx.git
ref: 07b601d0aaae0b173e7a18006f7502b9bb55b32d
# path: ../../coding/polkawallet/polkawallet_plugin_chainx
polkawallet_plugin_edgeware:
git:
url: https://github.com/remzrn/polkawallet_plugin_edgeware.git
ref: acdfd8bddce2075542e4678ef55855805700c752
# path: ../../coding/polkawallet/polkawallet_plugin_edgeware

# The following adds the Cupertino Icons font to your application.
Expand All @@ -64,12 +64,13 @@ dependencies:

dependency_overrides:
polkawallet_ui:
# git:
# url: https://github.com/polkawallet-io/ui.git
# ref: e81dc98d117f589f57d23d23affdf29022e81a4c
path: ../../coding/polkawallet/ui
polkawallet_sdk:
path: ../../coding/polkawallet/sdk
git:
url: https://github.com/polkawallet-io/ui.git
ref: 51ebe9ffe2c9a0c524aadffc03cbe413d891fa57
# path: ../../coding/polkawallet/ui
polkawallet_sdk: ^0.1.5
# polkawallet_sdk:
# path: ../../coding/polkawallet/sdk

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 2f902c3

Please sign in to comment.