Skip to content

Commit

Permalink
Automatically select signing address is there is only one (#260)
Browse files Browse the repository at this point in the history
* wallet_sign_transaction: Automatically select the address is there is only one managed by the selected wallet.

* smol fixes

---------

Co-authored-by: Willy <11148913+willyfromtheblock@users.noreply.github.com>
  • Loading branch information
peerchemist and willyfromtheblock authored Nov 14, 2024
1 parent 96ce610 commit 305f0c1
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions lib/screens/wallet/wallet_sign_transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,27 @@ class _WalletSignTransactionScreenState
_walletName = args.walletName;
_coinLetterCode = args.coinLetterCode;

// Check the addresses list
_initializeSigningAddress();

setState(() {
_initial = false;
});
}
super.didChangeDependencies();
}

Future<void> _initializeSigningAddress() async {
final addresses = await _walletProvider.getWalletAddresses(_walletName);

if (addresses.length == 1) {
// Automatically set the signing address if only one address exists
setState(() {
_signingAddress = addresses.first.address;
});
}
}

void _saveSnack() {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
Expand Down Expand Up @@ -303,15 +317,18 @@ class _WalletSignTransactionScreenState
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
AppLocalizations.instance
.translate('sign_step_1'),
_signingAddress.isEmpty
? AppLocalizations.instance
.translate('sign_step_1')
: AppLocalizations.instance
.translate('send_address'),
style: Theme.of(context).textTheme.titleLarge,
),
],
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 20),
child: _signingAddress == ''
child: _signingAddress.isEmpty
? Text(
AppLocalizations.instance.translate(
'sign_transaction_step_1_description',
Expand All @@ -323,15 +340,17 @@ class _WalletSignTransactionScreenState
child: SelectableText(_signingAddress),
),
),
PeerButton(
action: () => _showAddressSelector(),
text: AppLocalizations.instance.translate(
_signingAddress == ''
? 'sign_step_1_button'
: 'sign_step_1_button_alt',
if (_signingAddress.isEmpty)
PeerButton(
action: () => _showAddressSelector(),
text: AppLocalizations.instance.translate(
_signingAddress.isEmpty
? 'sign_step_1_button'
: 'sign_step_1_button_alt',
),
small: true,
),
small: true,
),
// else just show address label
if (_signingAddress.isNotEmpty && kIsWeb)
const SizedBox(
height: 20,
Expand Down

0 comments on commit 305f0c1

Please sign in to comment.