transferKeepAlive for all payments; transferAll to defaultWallet when deleting wallet with non null balance
This commit is contained in:
parent
86467c06f3
commit
55f08dddd6
|
@ -372,17 +372,20 @@ class SubstrateSdk with ChangeNotifier {
|
||||||
log.d(keyring.current.address);
|
log.d(keyring.current.address);
|
||||||
log.d(fromAddress);
|
log.d(fromAddress);
|
||||||
log.d(password);
|
log.d(password);
|
||||||
log.d(await checkPassword(fromAddress, password));
|
// log.d(await checkPassword(fromAddress, password));
|
||||||
|
|
||||||
|
final fromPubkey = await sdk.api.account.decodeAddress([fromAddress]);
|
||||||
|
log.d(fromPubkey!.keys.first);
|
||||||
final sender = TxSenderData(
|
final sender = TxSenderData(
|
||||||
keyring.current.address,
|
fromAddress,
|
||||||
keyring.current.pubKey,
|
fromPubkey.keys.first,
|
||||||
);
|
);
|
||||||
final txInfo = TxInfoData('balances', 'transfer', sender);
|
final txInfo = TxInfoData(
|
||||||
|
'balances', amount == -1 ? 'transferAll' : 'transferKeepAlive', sender);
|
||||||
try {
|
try {
|
||||||
final hash = await sdk.api.tx.signAndSend(
|
final hash = await sdk.api.tx.signAndSend(
|
||||||
txInfo,
|
txInfo,
|
||||||
[destAddress, amount * 100],
|
[destAddress, amount == -1 ? false : (amount * 100)],
|
||||||
password,
|
password,
|
||||||
onStatusChange: (status) {
|
onStatusChange: (status) {
|
||||||
log.d('Transaction status: ' + status);
|
log.d('Transaction status: ' + status);
|
||||||
|
|
|
@ -66,6 +66,20 @@ class WalletOptionsProvider with ChangeNotifier {
|
||||||
'Êtes-vous sûr de vouloir oublier le portefeuille "${wallet.name}" ?'));
|
'Êtes-vous sûr de vouloir oublier le portefeuille "${wallet.name}" ?'));
|
||||||
|
|
||||||
if (_answer ?? false) {
|
if (_answer ?? false) {
|
||||||
|
//Check if balance is null
|
||||||
|
final _balance = await _sub.getBalance(wallet.address!);
|
||||||
|
if (_balance != 0) {
|
||||||
|
MyWalletsProvider _myWalletProvider =
|
||||||
|
Provider.of<MyWalletsProvider>(context, listen: false);
|
||||||
|
final _defaultWallet = _myWalletProvider.getDefaultWallet();
|
||||||
|
log.d(_defaultWallet.address);
|
||||||
|
await _sub.pay(
|
||||||
|
fromAddress: wallet.address!,
|
||||||
|
destAddress: _defaultWallet.address!,
|
||||||
|
amount: -1,
|
||||||
|
password: _myWalletProvider.pinCode);
|
||||||
|
}
|
||||||
|
|
||||||
await walletBox.delete(wallet.key);
|
await walletBox.delete(wallet.key);
|
||||||
await _sub.deleteAccounts([wallet.address!]);
|
await _sub.deleteAccounts([wallet.address!]);
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ class SettingsScreen extends StatelessWidget {
|
||||||
const SizedBox(height: 60),
|
const SizedBox(height: 60),
|
||||||
Row(children: [
|
Row(children: [
|
||||||
Consumer<SubstrateSdk>(builder: (context, _sub, _) {
|
Consumer<SubstrateSdk>(builder: (context, _sub, _) {
|
||||||
|
log.d(_sub.sdk.api.connectedNode?.endpoint);
|
||||||
return Expanded(
|
return Expanded(
|
||||||
child: Row(children: [
|
child: Row(children: [
|
||||||
Text(' Noeud $currencyName :'),
|
Text(' Noeud $currencyName :'),
|
||||||
|
|
|
@ -36,7 +36,7 @@ class SubstrateSandBox extends StatelessWidget {
|
||||||
await _sub.connectNode(context);
|
await _sub.connectNode(context);
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
'Noeud connecté ?: ${_sub.nodeConnected} (${configBox.get('endpoint')})')),
|
'Noeud connecté ?: ${_sub.nodeConnected} (${_sub.sdk.api.connectedNode?.endpoint})')),
|
||||||
if (_sub.nodeConnected)
|
if (_sub.nodeConnected)
|
||||||
Text('Noeud "$currencyName", bloc N°${_sub.blocNumber}'),
|
Text('Noeud "$currencyName", bloc N°${_sub.blocNumber}'),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
|
|
|
@ -22,6 +22,7 @@ class TransactionInProgress extends StatelessWidget {
|
||||||
Provider.of<WalletsProfilesProvider>(context, listen: false);
|
Provider.of<WalletsProfilesProvider>(context, listen: false);
|
||||||
MyWalletsProvider _myWalletProvider =
|
MyWalletsProvider _myWalletProvider =
|
||||||
Provider.of<MyWalletsProvider>(context, listen: false);
|
Provider.of<MyWalletsProvider>(context, listen: false);
|
||||||
|
bool isValid = false;
|
||||||
|
|
||||||
String _resultText;
|
String _resultText;
|
||||||
bool isLoading = true;
|
bool isLoading = true;
|
||||||
|
@ -84,8 +85,10 @@ class TransactionInProgress extends StatelessWidget {
|
||||||
// jsonResult = json.decode(_result);
|
// jsonResult = json.decode(_result);
|
||||||
log.d(_result);
|
log.d(_result);
|
||||||
if (_result.contains('blockHash: ')) {
|
if (_result.contains('blockHash: ')) {
|
||||||
|
isValid = true;
|
||||||
_resultText = '$_actionName validé !';
|
_resultText = '$_actionName validé !';
|
||||||
} else {
|
} else {
|
||||||
|
isValid = false;
|
||||||
_resultText = "Une erreur s'est produite:\n";
|
_resultText = "Une erreur s'est produite:\n";
|
||||||
final List _exceptionSplit = _result.split('Exception: ');
|
final List _exceptionSplit = _result.split('Exception: ');
|
||||||
String _exception;
|
String _exception;
|
||||||
|
@ -94,7 +97,7 @@ class TransactionInProgress extends StatelessWidget {
|
||||||
} else {
|
} else {
|
||||||
_exception = _exceptionSplit[0];
|
_exception = _exceptionSplit[0];
|
||||||
}
|
}
|
||||||
|
// log.d('expection: $_exception');
|
||||||
switch (_exception) {
|
switch (_exception) {
|
||||||
case 'cert.NotRespectCertPeriod':
|
case 'cert.NotRespectCertPeriod':
|
||||||
case 'identity.CreatorNotAllowedToCreateIdty':
|
case 'identity.CreatorNotAllowedToCreateIdty':
|
||||||
|
@ -114,6 +117,23 @@ class TransactionInProgress extends StatelessWidget {
|
||||||
_resultText += "Ce nom est déjà pris";
|
_resultText += "Ce nom est déjà pris";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'balances.KeepAlive':
|
||||||
|
{
|
||||||
|
_resultText =
|
||||||
|
"Vous devez garder au moins 2ĞD sur votre compte pour le garder actif";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '1010: Invalid Transaction: Inability to pay some fees , e.g. account balance too low':
|
||||||
|
{
|
||||||
|
_resultText =
|
||||||
|
"Vous devez alimenter ce compte avant\nde pouvoir l'utiliser";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'timeout':
|
||||||
|
{
|
||||||
|
_resultText += "Le délais d'éxecution est dépassé";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
|
@ -156,7 +176,7 @@ class TransactionInProgress extends StatelessWidget {
|
||||||
end: Alignment.bottomCenter,
|
end: Alignment.bottomCenter,
|
||||||
colors: [
|
colors: [
|
||||||
yellowC,
|
yellowC,
|
||||||
const Color(0xfffafafa),
|
backgroundColor,
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
child: Column(children: <Widget>[
|
child: Column(children: <Widget>[
|
||||||
|
@ -209,6 +229,14 @@ class TransactionInProgress extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Visibility(
|
||||||
|
visible: !isLoading,
|
||||||
|
child: Icon(
|
||||||
|
isValid ? Icons.done_all : Icons.close,
|
||||||
|
size: 35,
|
||||||
|
color: isValid ? Colors.greenAccent : Colors.redAccent,
|
||||||
|
),
|
||||||
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
Text(
|
Text(
|
||||||
_resultText,
|
_resultText,
|
||||||
|
|
|
@ -5,7 +5,7 @@ description: Pay with G1.
|
||||||
# pub.dev using `pub publish`. This is preferred for private packages.
|
# pub.dev using `pub publish`. This is preferred for private packages.
|
||||||
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||||
|
|
||||||
version: 0.0.8+2
|
version: 0.0.8+3
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.12.0 <3.0.0'
|
sdk: '>=2.12.0 <3.0.0'
|
||||||
|
|
Loading…
Reference in New Issue