From 22bfd4303f149dda1ddef83b3bb3204812b9b167 Mon Sep 17 00:00:00 2001 From: Adam V <13562139+catenocrypt@users.noreply.github.com> Date: Fri, 7 Oct 2022 12:09:24 +0200 Subject: [PATCH] [Devconsole] Add missing walletXxx utilities to help (#2616) * Add missing wallet* utilities to help * Fix return types (review comment) --- samples/typescript/devconsole.ts/src/index.ts | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/samples/typescript/devconsole.ts/src/index.ts b/samples/typescript/devconsole.ts/src/index.ts index fd994c1f539..f08c79bd6c8 100644 --- a/samples/typescript/devconsole.ts/src/index.ts +++ b/samples/typescript/devconsole.ts/src/index.ts @@ -132,9 +132,9 @@ async function main() { autoFillName(name: string): string { return (name === '') ? `Wallet${(this.storeWallets.length + 1).toString()}` : name; } - async create(strength: number, name: string): Promise { + async create(strength: number, name: string): Promise { this.wallet = null; - if (!this.keystore) { return; } + if (!this.keystore) { return null; } try { if (name === '') { name = this.autoFillName(name); } const hdWallet = WC.HDWallet.create(strength, this.HDWalletPassord); @@ -150,11 +150,12 @@ async function main() { return this.wallet; } catch (err) { console.log(`Exception: ${err}`); + return null; } } - async import(mnemonic: string, name: string): Promise { + async import(mnemonic: string, name: string): Promise { this.wallet = null; - if (!this.keystore) { return; } + if (!this.keystore) { return null; } try { if (!WC.Mnemonic.isValid(mnemonic)) { console.error(`Mnemonic is not valid ${mnemonic}`); @@ -171,16 +172,18 @@ async function main() { return this.wallet; } catch (err) { console.log(`Exception: ${err}`); + return null; } } - async addCoin(coin: string): Promise { + async addCoin(coin: string): Promise { if (this.wallet == null) { console.error('No wallet open, see walletCreate() / walletLoad() / walletsList()'); - return; + return null; } - if (!this.keystore) { return; } + if (!this.keystore) { return null; } const wallet = await this.keystore.addAccounts(this.wallet?.wallet.identifier(), this.StoreFixedPassword, [coin]); this.wallet = new StoredKeyWallet(this.keystore.mapStoredKey(wallet)); + return this.wallet; } // Delete loaded wallet async delete(param: string): Promise { @@ -248,9 +251,9 @@ async function main() { async function walletsList() { await wallets.list(); } async function walletLoad(index: number) { await wallets.load(index); } async function walletsDeleteAll(param: string) { await wallets.deleteAll(param); } - async function walletCreate(strength: number = 256, name: string = ''): Promise { return await wallets.create(strength, name); } - async function walletImport(mnemonic: string, name: string = ''): Promise { return wallets.import(mnemonic, name); } - async function walletAddCoin(coin: string): Promise { return wallets.addCoin(coin); } + async function walletCreate(strength: number = 256, name: string = ''): Promise { return await wallets.create(strength, name); } + async function walletImport(mnemonic: string, name: string = ''): Promise { return await wallets.import(mnemonic, name); } + async function walletAddCoin(coin: string): Promise { return await wallets.addCoin(coin); } function walletDump(): void { wallets.dump(); } async function walletDelete(param: string) { await wallets.delete(param); } @@ -276,6 +279,11 @@ async function main() { console.log(" walletCreate([strength], [name]) walletCreate(128)"); console.log(" walletImport(mnemonic, [name]) walletImport('ripple scissors kick mammal hire column oak again sun offer wealth tomorrow wagon turn fatal', 'Test1')"); console.log(" walletDump() walletDump()"); + console.log(" walletAddCoin(symbol) walletAddCoin(CoinType.solana)"); + console.log(" walletsList() walletsList()"); + console.log(" walletLoad() walletLoad(0)"); + console.log(" walletDelete() walletDelete('delete')"); + console.log(" walletsDeleteAll() walletsDeleteAll('deleteall')"); console.log(); console.log("See examples in samplescripts folder, e.g.: cat samplescripts/protoeth.sampleinput.txt | npm run start"); console.log();