Skip to content

Commit

Permalink
Generic fixes (#1427)
Browse files Browse the repository at this point in the history
* fix for private key solana

* Fix Solana wallet open
  • Loading branch information
OmarHatem28 authored May 4, 2024
1 parent d5543ce commit 043d7d7
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions cw_solana/lib/solana_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,17 @@ abstract class SolanaWalletBase
Future<Wallet> getWalletPair({String? mnemonic, String? privateKey}) async {
assert(mnemonic != null || privateKey != null);

if (privateKey != null) {
final privateKeyBytes = base58decode(privateKey);
return await Wallet.fromPrivateKeyBytes(privateKey: privateKeyBytes.take(32).toList());
if (mnemonic != null) {
return Wallet.fromMnemonic(mnemonic, account: 0, change: 0);
}

return Wallet.fromMnemonic(mnemonic!, account: 0, change: 0);
try {
final privateKeyBytes = base58decode(privateKey!);
return await Wallet.fromPrivateKeyBytes(privateKey: privateKeyBytes.take(32).toList());
} catch (_) {
final privateKeyBytes = HEX.decode(privateKey!);
return await Wallet.fromPrivateKeyBytes(privateKey: privateKeyBytes);
}
}

@override
Expand Down Expand Up @@ -360,7 +365,7 @@ abstract class SolanaWalletBase

String toJSON() => json.encode({
'mnemonic': _mnemonic,
'private_key': privateKey,
'private_key': _hexPrivateKey,
'balance': balance[currency]!.toJSON(),
});

Expand Down

0 comments on commit 043d7d7

Please sign in to comment.