]> git.codecow.com Git - libnemo.git/commitdiff
Accept wallet id as optional input instead of reassigning after the fact during import.
authorChris Duncan <chris@zoso.dev>
Sat, 2 Aug 2025 19:26:36 +0000 (12:26 -0700)
committerChris Duncan <chris@zoso.dev>
Sat, 2 Aug 2025 19:26:36 +0000 (12:26 -0700)
src/lib/wallet.ts

index 541221d3c58622953d3daa8a05063673ddda3038..9b971a2889baf5e7f391aab7178d89ce0d05a891 100644 (file)
@@ -147,8 +147,7 @@ export class Wallet {
                                throw new Error('Invalid wallet type from database')\r
                        }\r
                        Wallet.#isInternal = true\r
-                       const self = new this(type)\r
-                       self.#id = id\r
+                       const self = new this(type, id)\r
                        return self\r
                } catch (err) {\r
                        throw new Error('Failed to restore wallet', { cause: err })\r
@@ -195,13 +194,13 @@ export class Wallet {
                }\r
        }\r
 \r
-       constructor (type: WalletType) {\r
+       constructor (type: WalletType, id?: string) {\r
                if (!Wallet.#isInternal && type !== 'Ledger') {\r
                        throw new Error(`Wallet cannot be instantiated directly. Use 'await Wallet.create()' instead.`)\r
                }\r
                Wallet.#isInternal = false\r
                this.#accounts = new AccountList()\r
-               this.#id = crypto.randomUUID()\r
+               this.#id = id ?? crypto.randomUUID()\r
                this.#safe = new WorkerQueue(type === 'Ledger' ? '' : SafeWorker)\r
                this.#type = type\r
        }\r