transferKeepAlive for all payments; transferAll to defaultWallet when deleting wallet with non null balance

This commit is contained in:
poka 2022-06-08 02:30:19 +02:00
parent 86467c06f3
commit 55f08dddd6
6 changed files with 55 additions and 9 deletions

View File

@ -372,17 +372,20 @@ class SubstrateSdk with ChangeNotifier {
log.d(keyring.current.address);
log.d(fromAddress);
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(
keyring.current.address,
keyring.current.pubKey,
fromAddress,
fromPubkey.keys.first,
);
final txInfo = TxInfoData('balances', 'transfer', sender);
final txInfo = TxInfoData(
'balances', amount == -1 ? 'transferAll' : 'transferKeepAlive', sender);
try {
final hash = await sdk.api.tx.signAndSend(
txInfo,
[destAddress, amount * 100],
[destAddress, amount == -1 ? false : (amount * 100)],
password,
onStatusChange: (status) {
log.d('Transaction status: ' + status);

View File

@ -66,6 +66,20 @@ class WalletOptionsProvider with ChangeNotifier {
'Êtes-vous sûr de vouloir oublier le portefeuille "${wallet.name}" ?'));
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 _sub.deleteAccounts([wallet.address!]);

View File

@ -49,6 +49,7 @@ class SettingsScreen extends StatelessWidget {
const SizedBox(height: 60),
Row(children: [
Consumer<SubstrateSdk>(builder: (context, _sub, _) {
log.d(_sub.sdk.api.connectedNode?.endpoint);
return Expanded(
child: Row(children: [
Text(' Noeud $currencyName :'),

View File

@ -36,7 +36,7 @@ class SubstrateSandBox extends StatelessWidget {
await _sub.connectNode(context);
},
child: Text(
'Noeud connecté ?: ${_sub.nodeConnected} (${configBox.get('endpoint')})')),
'Noeud connecté ?: ${_sub.nodeConnected} (${_sub.sdk.api.connectedNode?.endpoint})')),
if (_sub.nodeConnected)
Text('Noeud "$currencyName", bloc N°${_sub.blocNumber}'),
const SizedBox(height: 20),

View File

@ -22,6 +22,7 @@ class TransactionInProgress extends StatelessWidget {
Provider.of<WalletsProfilesProvider>(context, listen: false);
MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(context, listen: false);
bool isValid = false;
String _resultText;
bool isLoading = true;
@ -84,8 +85,10 @@ class TransactionInProgress extends StatelessWidget {
// jsonResult = json.decode(_result);
log.d(_result);
if (_result.contains('blockHash: ')) {
isValid = true;
_resultText = '$_actionName validé !';
} else {
isValid = false;
_resultText = "Une erreur s'est produite:\n";
final List _exceptionSplit = _result.split('Exception: ');
String _exception;
@ -94,7 +97,7 @@ class TransactionInProgress extends StatelessWidget {
} else {
_exception = _exceptionSplit[0];
}
// log.d('expection: $_exception');
switch (_exception) {
case 'cert.NotRespectCertPeriod':
case 'identity.CreatorNotAllowedToCreateIdty':
@ -114,6 +117,23 @@ class TransactionInProgress extends StatelessWidget {
_resultText += "Ce nom est déjà pris";
}
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:
{
@ -156,7 +176,7 @@ class TransactionInProgress extends StatelessWidget {
end: Alignment.bottomCenter,
colors: [
yellowC,
const Color(0xfffafafa),
backgroundColor,
],
)),
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),
Text(
_resultText,

View File

@ -5,7 +5,7 @@ description: Pay with G1.
# 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
version: 0.0.8+2
version: 0.0.8+3
environment:
sdk: '>=2.12.0 <3.0.0'