Skip to content

Commit

Permalink
wallet_sign_transaction: Automatically select the address is there is…
Browse files Browse the repository at this point in the history
… only one managed by the selected wallet.
  • Loading branch information
peerchemist committed Nov 14, 2024
1 parent 6e02627 commit 12949cc
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions lib/screens/wallet/wallet_sign_transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,28 @@ 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;
});
_saveSnack(); // Optionally show a snackbar
}
}

void _saveSnack() {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
Expand Down Expand Up @@ -303,8 +318,10 @@ class _WalletSignTransactionScreenState
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
AppLocalizations.instance
.translate('sign_step_1'),
_signingAddress == ''
? AppLocalizations.instance
.translate('sign_step_1')
: 'Address', // TODO: Add translation?
style: Theme.of(context).textTheme.titleLarge,
),
],
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 == '')
PeerButton(
action: () => _showAddressSelector(),
text: AppLocalizations.instance.translate(
_signingAddress == ''
? '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 12949cc

Please sign in to comment.