diff --git a/package-lock.json b/package-lock.json index af62aa5..2e3a8e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -52,8 +52,8 @@ "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "cmdk": "^1.0.0", - "coco-cashu-core": "1.0.0-rc10", - "coco-cashu-indexeddb": "0.8.0", + "coco-cashu-core": "1.0.0-rc.17", + "coco-cashu-indexeddb": "1.0.0-rc.17", "date-fns": "^3.6.0", "ecpair": "^3.0.0", "embla-carousel-react": "^8.3.0", @@ -115,7 +115,6 @@ "version": "5.2.0", "resolved": "https://registry.npmjs.org/@alloc/quick-lru/-/quick-lru-5.2.0.tgz", "integrity": "sha512-UrcABB+4bUrFABwbluTIBErXwvbsU/V7TZWfmbgJfbkwiBuziS9gxdODUyuiecfdGQ85jglMW6juS3+z5TsKLw==", - "dev": true, "license": "MIT", "engines": { "node": ">=10" @@ -1279,7 +1278,6 @@ "version": "8.0.2", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", "integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==", - "dev": true, "license": "ISC", "dependencies": { "string-width": "^5.1.2", @@ -1407,7 +1405,6 @@ "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", - "dev": true, "license": "MIT", "dependencies": { "@nodelib/fs.stat": "2.0.5", @@ -1421,7 +1418,6 @@ "version": "2.0.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", - "dev": true, "license": "MIT", "engines": { "node": ">= 8" @@ -1431,7 +1427,6 @@ "version": "1.2.8", "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", - "dev": true, "license": "MIT", "dependencies": { "@nodelib/fs.scandir": "2.1.5", @@ -1477,7 +1472,6 @@ "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", - "dev": true, "license": "MIT", "optional": true, "engines": { @@ -3702,7 +3696,6 @@ "version": "22.18.11", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.18.11.tgz", "integrity": "sha512-Gd33J2XIrXurb+eT2ktze3rJAfAp9ZNjlBdh4SVgyrKEOADwCbdUDaK7QgJno8Ue4kcajscsKqu6n8OBG3hhCQ==", - "dev": true, "license": "MIT", "dependencies": { "undici-types": "~6.21.0" @@ -3712,7 +3705,7 @@ "version": "15.7.15", "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.15.tgz", "integrity": "sha512-F6bEyamV9jKGAFBEmlQnesRPGOQqS2+Uwi0Em15xenOxHaf2hv6L8YCVn3rPdPJOiJfPiCnLIRyvwVaqMY3MIw==", - "dev": true, + "devOptional": true, "license": "MIT" }, "node_modules/@types/qrcode": { @@ -3725,11 +3718,21 @@ "@types/node": "*" } }, + "node_modules/@types/randombytes": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@types/randombytes/-/randombytes-2.0.3.tgz", + "integrity": "sha512-+NRgihTfuURllWCiIAhm1wsJqzsocnqXM77V/CalsdJIYSRGEHMnritxh+6EsBklshC+clo1KgnN14qgSGeQdw==", + "license": "MIT", + "peer": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/react": { "version": "18.3.26", "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.26.tgz", "integrity": "sha512-RFA/bURkcKzx/X9oumPG9Vp3D3JUgus/d0b67KB0t5S/raciymilkOa66olh78MUI92QLbEJevO7rvqU/kjwKA==", - "dev": true, + "devOptional": true, "license": "MIT", "dependencies": { "@types/prop-types": "*", @@ -3740,7 +3743,7 @@ "version": "18.3.7", "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.3.7.tgz", "integrity": "sha512-MEe3UeoENYVFXzoXEWsvcpg6ZvlrFNlOQ7EOsvhI3CfAXwzPfO8Qwuxd40nepsYKqyyVQnTdEfv68q91yLcKrQ==", - "dev": true, + "devOptional": true, "license": "MIT", "peerDependencies": { "@types/react": "^18.0.0" @@ -4242,7 +4245,6 @@ "version": "6.2.2", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.2.2.tgz", "integrity": "sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg==", - "dev": true, "license": "MIT", "engines": { "node": ">=12" @@ -4270,14 +4272,12 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz", "integrity": "sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==", - "dev": true, "license": "MIT" }, "node_modules/anymatch": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", - "dev": true, "license": "ISC", "dependencies": { "normalize-path": "^3.0.0", @@ -4291,7 +4291,6 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", - "dev": true, "license": "MIT", "engines": { "node": ">=8.6" @@ -4304,7 +4303,6 @@ "version": "5.0.2", "resolved": "https://registry.npmjs.org/arg/-/arg-5.0.2.tgz", "integrity": "sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==", - "dev": true, "license": "MIT" }, "node_modules/argparse": { @@ -4419,7 +4417,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "dev": true, "license": "MIT" }, "node_modules/base-x": { @@ -4468,7 +4465,6 @@ "version": "2.3.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", "integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -4490,6 +4486,16 @@ "node": ">=18.0.0" } }, + "node_modules/bip174-liquid": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/bip174-liquid/-/bip174-liquid-1.0.3.tgz", + "integrity": "sha512-e69sC0Cq2tBJuhG2+wieXv40DN13YBR/wbIjZp4Mqwpar5vQm8Ldqijdd6N33XG7LtfvQi/zKm5fSzdPY/9mgw==", + "license": "MIT", + "peer": true, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/bip32": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/bip32/-/bip32-4.0.0.tgz", @@ -4585,6 +4591,40 @@ "node": ">=18.0.0" } }, + "node_modules/bitset": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/bitset/-/bitset-5.2.3.tgz", + "integrity": "sha512-uZ7++Z60MC9cZ+7YzQ1v9yPDydcjhmcMjGx2yoGTjjSXBoVMmTr2LCRbkpI19S9P/C75hhP7Bsakj+gVzVUDbQ==", + "license": "MIT", + "peer": true, + "engines": { + "node": "*" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/rawify" + } + }, + "node_modules/blech32": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/blech32/-/blech32-1.1.2.tgz", + "integrity": "sha512-C5qxzoF9KyX88X8Zz18cZ6BOeL0n5/Eg/cDot1frntkArRMwg1djNim5wA6QFWwu0lJ1LN8iiRMN4Lp2kZzdfA==", + "license": "MIT", + "peer": true, + "dependencies": { + "long": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/blech32/node_modules/long": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", + "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==", + "license": "Apache-2.0", + "peer": true + }, "node_modules/bn.js": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.2.2.tgz", @@ -4690,7 +4730,6 @@ "version": "3.0.3", "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", - "dev": true, "license": "MIT", "dependencies": { "fill-range": "^7.1.1" @@ -4856,7 +4895,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/camelcase-css/-/camelcase-css-2.0.1.tgz", "integrity": "sha512-QOSvevhslijgYwRx6Rv7zKdMF8lbRmx+uQGx2+vDc+KI/eBnsy9kit5aj23AgGu3pa4t9AgwbnXWqS+iOY+2aA==", - "dev": true, "license": "MIT", "engines": { "node": ">= 6" @@ -4931,7 +4969,6 @@ "version": "3.6.0", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", - "dev": true, "license": "MIT", "dependencies": { "anymatch": "~3.1.2", @@ -4956,7 +4993,6 @@ "version": "5.1.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", - "dev": true, "license": "ISC", "dependencies": { "is-glob": "^4.0.1" @@ -5083,9 +5119,9 @@ } }, "node_modules/coco-cashu-core": { - "version": "1.0.0-rc10", - "resolved": "https://registry.npmjs.org/coco-cashu-core/-/coco-cashu-core-1.0.0-rc10.tgz", - "integrity": "sha512-EQVVFgkakGqWMloDJR2bJ4d4Skpahz8/UgKwCzjxuyIxhVeSswKBcUQNHCGMZiZR1BxpLjTH8l9wwuPb4xoS8A==", + "version": "1.0.0-rc.17", + "resolved": "https://registry.npmjs.org/coco-cashu-core/-/coco-cashu-core-1.0.0-rc.17.tgz", + "integrity": "sha512-+G3ip1z5PkejhARW4F0djELPNYeUFTKP3shMcCNDLmkK1W3IcGvVlzVf60mbUaM4jl5IidbP9IZkcx7/aaJPYQ==", "dependencies": { "@cashu/cashu-ts": "^2.7.2" }, @@ -5094,14 +5130,14 @@ } }, "node_modules/coco-cashu-indexeddb": { - "version": "0.8.0", - "resolved": "https://registry.npmjs.org/coco-cashu-indexeddb/-/coco-cashu-indexeddb-0.8.0.tgz", - "integrity": "sha512-i86Ff1yXdn3StI9zyNqYp4Hl+7GWsb25/xn5lS72kB8q8VvvUHfdz4qBck2Cwo7Uw5piA9GZghGTlKUmeQ/Yvw==", + "version": "1.0.0-rc.17", + "resolved": "https://registry.npmjs.org/coco-cashu-indexeddb/-/coco-cashu-indexeddb-1.0.0-rc.17.tgz", + "integrity": "sha512-eaKGYMlpdjxn9t40Vynca50VtyPXsPnNg82zjRIMmryf9UC8jJEMccXsVIa3h1BC988KHJwwsz6myAWviu+5jw==", "dependencies": { "dexie": "^4.0.8" }, "peerDependencies": { - "coco-cashu-core": "^1.0.0-rc5", + "coco-cashu-core": "1.0.0-rc.17", "typescript": "^5" } }, @@ -5127,7 +5163,6 @@ "version": "4.1.1", "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", "integrity": "sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==", - "dev": true, "license": "MIT", "engines": { "node": ">= 6" @@ -5165,11 +5200,25 @@ "sha.js": "^2.4.0" } }, + "node_modules/create-hmac": { + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz", + "integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==", + "license": "MIT", + "peer": true, + "dependencies": { + "cipher-base": "^1.0.3", + "create-hash": "^1.1.0", + "inherits": "^2.0.1", + "ripemd160": "^2.0.0", + "safe-buffer": "^5.0.1", + "sha.js": "^2.4.8" + } + }, "node_modules/cross-spawn": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", - "dev": true, "license": "MIT", "dependencies": { "path-key": "^3.1.0", @@ -5191,7 +5240,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz", "integrity": "sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==", - "dev": true, "license": "MIT", "bin": { "cssesc": "bin/cssesc" @@ -5465,7 +5513,6 @@ "version": "1.2.2", "resolved": "https://registry.npmjs.org/didyoumean/-/didyoumean-1.2.2.tgz", "integrity": "sha512-gxtyfqMg7GKyhQmb056K7M3xszy/myH8w+B4RT+QXBQsvAOdc3XymqDDPHx1BgPgsdAA5SIifona89YtRATDzw==", - "dev": true, "license": "Apache-2.0" }, "node_modules/dijkstrajs": { @@ -5478,7 +5525,6 @@ "version": "1.1.3", "resolved": "https://registry.npmjs.org/dlv/-/dlv-1.1.3.tgz", "integrity": "sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==", - "dev": true, "license": "MIT" }, "node_modules/dom-accessibility-api": { @@ -5516,7 +5562,6 @@ "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", - "dev": true, "license": "MIT" }, "node_modules/ecpair": { @@ -5595,7 +5640,6 @@ "version": "9.2.2", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", - "dev": true, "license": "MIT" }, "node_modules/entities": { @@ -5969,7 +6013,6 @@ "version": "3.3.3", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.3.tgz", "integrity": "sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==", - "dev": true, "license": "MIT", "dependencies": { "@nodelib/fs.stat": "^2.0.2", @@ -5986,7 +6029,6 @@ "version": "5.1.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", - "dev": true, "license": "ISC", "dependencies": { "is-glob": "^4.0.1" @@ -6013,7 +6055,6 @@ "version": "1.19.1", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.19.1.tgz", "integrity": "sha512-GwLTyxkCXjXbxqIhTsMI2Nui8huMPtnxg7krajPJAjnEG/iiOS7i+zCtWGZR9G0NBKbXKh6X9m9UIsYX/N6vvQ==", - "dev": true, "license": "ISC", "dependencies": { "reusify": "^1.0.4" @@ -6054,7 +6095,6 @@ "version": "7.1.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", - "dev": true, "license": "MIT", "dependencies": { "to-regex-range": "^5.0.1" @@ -6120,7 +6160,6 @@ "version": "3.3.1", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.1.tgz", "integrity": "sha512-gIXjKqtFuWEgzFRJA9WCQeSJLZDjgJUOMCMzxtvFq/37KojM1BFGufqsCy0r4qSQmYLsZYMeyRqzIWOMup03sw==", - "dev": true, "license": "ISC", "dependencies": { "cross-spawn": "^7.0.6", @@ -6151,7 +6190,6 @@ "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "dev": true, "hasInstallScript": true, "license": "MIT", "optional": true, @@ -6230,7 +6268,6 @@ "version": "10.4.5", "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.5.tgz", "integrity": "sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==", - "dev": true, "license": "ISC", "dependencies": { "foreground-child": "^3.1.0", @@ -6251,7 +6288,6 @@ "version": "6.0.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", - "dev": true, "license": "ISC", "dependencies": { "is-glob": "^4.0.3" @@ -6264,7 +6300,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", - "dev": true, "license": "MIT", "dependencies": { "balanced-match": "^1.0.0" @@ -6274,7 +6309,6 @@ "version": "9.0.5", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", - "dev": true, "license": "ISC", "dependencies": { "brace-expansion": "^2.0.1" @@ -6556,7 +6590,6 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", - "dev": true, "license": "MIT", "dependencies": { "binary-extensions": "^2.0.0" @@ -6581,7 +6614,6 @@ "version": "2.16.1", "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.1.tgz", "integrity": "sha512-UfoeMA6fIJ8wTYFEUjelnaGI67v6+N7qXJEvQuIGa99l4xsCruSYOVSQ0uPANn4dAzm8lkYPaKLrrijLq7x23w==", - "dev": true, "license": "MIT", "dependencies": { "hasown": "^2.0.2" @@ -6597,7 +6629,6 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", - "dev": true, "license": "MIT", "engines": { "node": ">=0.10.0" @@ -6616,7 +6647,6 @@ "version": "4.0.3", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", - "dev": true, "license": "MIT", "dependencies": { "is-extglob": "^2.1.1" @@ -6629,7 +6659,6 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", - "dev": true, "license": "MIT", "engines": { "node": ">=0.12.0" @@ -6667,14 +6696,12 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", - "dev": true, "license": "ISC" }, "node_modules/jackspeak": { "version": "3.4.3", "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.3.tgz", "integrity": "sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw==", - "dev": true, "license": "BlueOak-1.0.0", "dependencies": { "@isaacs/cliui": "^8.0.2" @@ -6690,7 +6717,6 @@ "version": "1.21.7", "resolved": "https://registry.npmjs.org/jiti/-/jiti-1.21.7.tgz", "integrity": "sha512-/imKNG4EbWNrVjoNC/1H5/9GFy+tqjGBHCaSsN+P2RnPqjsLmv6UD3Ej+Kj8nBWaRAwyk7kK5ZUc+OEatnTR3A==", - "dev": true, "license": "MIT", "bin": { "jiti": "bin/jiti.js" @@ -6816,7 +6842,6 @@ "version": "3.1.3", "resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-3.1.3.tgz", "integrity": "sha512-/vlFKAoH5Cgt3Ie+JLhRbwOsCQePABiU3tJ1egGvyQ+33R/vcwM2Zl2QR/LzjsBeItPt3oSVXapn+m4nQDvpzw==", - "dev": true, "license": "MIT", "engines": { "node": ">=14" @@ -6829,9 +6854,166 @@ "version": "1.2.4", "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz", "integrity": "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==", - "dev": true, "license": "MIT" }, + "node_modules/liquidjs-lib": { + "version": "6.0.2-liquid.37", + "resolved": "https://registry.npmjs.org/liquidjs-lib/-/liquidjs-lib-6.0.2-liquid.37.tgz", + "integrity": "sha512-AOPwqg9wtLMNxfqOf8afC+bYYrs3VBsTq/Mq/iOe0F2X3CcbgiLeSAcvOY34jbnUre6U+zmuXKP9bWmxnOG08A==", + "license": "MIT", + "peer": true, + "dependencies": { + "@types/randombytes": "^2.0.0", + "bech32": "^2.0.0", + "bip174-liquid": "^1.0.3", + "bip66": "^1.1.0", + "bitcoinjs-lib": "^6.0.2", + "bitset": "^5.1.1", + "blech32": "^1.0.1", + "bs58check": "^2.0.0", + "create-hash": "^1.2.0", + "ecpair": "^2.1.0", + "slip77": "^0.2.0", + "typeforce": "^1.11.3", + "varuint-bitcoin": "^1.1.2" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/liquidjs-lib/node_modules/base-x": { + "version": "3.0.11", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.11.tgz", + "integrity": "sha512-xz7wQ8xDhdyP7tQxwdteLYeFfS68tSMNCZ/Y37WJ4bhGfKPpqEIlmIyueQHqOyoPhE6xNUqjzRr8ra0eF9VRvA==", + "license": "MIT", + "peer": true, + "dependencies": { + "safe-buffer": "^5.0.1" + } + }, + "node_modules/liquidjs-lib/node_modules/bip174": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/bip174/-/bip174-2.1.1.tgz", + "integrity": "sha512-mdFV5+/v0XyNYXjBS6CQPLo9ekCx4gtKZFnJm5PMto7Fs9hTTDpkkzOB7/FtluRI6JbUUAu+snTYfJRgHLZbZQ==", + "license": "MIT", + "peer": true, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/liquidjs-lib/node_modules/bip66": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/bip66/-/bip66-1.1.5.tgz", + "integrity": "sha512-nemMHz95EmS38a26XbbdxIYj5csHd3RMP3H5bwQknX0WYHF01qhpufP42mLOwVICuH2JmhIhXiWs89MfUGL7Xw==", + "license": "MIT", + "peer": true, + "dependencies": { + "safe-buffer": "^5.0.1" + } + }, + "node_modules/liquidjs-lib/node_modules/bitcoinjs-lib": { + "version": "6.1.7", + "resolved": "https://registry.npmjs.org/bitcoinjs-lib/-/bitcoinjs-lib-6.1.7.tgz", + "integrity": "sha512-tlf/r2DGMbF7ky1MgUqXHzypYHakkEnm0SZP23CJKIqNY/5uNAnMbFhMJdhjrL/7anfb/U8+AlpdjPWjPnAalg==", + "license": "MIT", + "peer": true, + "dependencies": { + "@noble/hashes": "^1.2.0", + "bech32": "^2.0.0", + "bip174": "^2.1.1", + "bs58check": "^3.0.1", + "typeforce": "^1.11.3", + "varuint-bitcoin": "^1.1.2" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/liquidjs-lib/node_modules/bitcoinjs-lib/node_modules/base-x": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-4.0.1.tgz", + "integrity": "sha512-uAZ8x6r6S3aUM9rbHGVOIsR15U/ZSc82b3ymnCPsT45Gk1DDvhDPdIgB5MrhirZWt+5K0EEPQH985kNqZgNPFw==", + "license": "MIT", + "peer": true + }, + "node_modules/liquidjs-lib/node_modules/bitcoinjs-lib/node_modules/bs58": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/bs58/-/bs58-5.0.0.tgz", + "integrity": "sha512-r+ihvQJvahgYT50JD05dyJNKlmmSlMoOGwn1lCcEzanPglg7TxYjioQUYehQ9mAR/+hOSd2jRc/Z2y5UxBymvQ==", + "license": "MIT", + "peer": true, + "dependencies": { + "base-x": "^4.0.0" + } + }, + "node_modules/liquidjs-lib/node_modules/bitcoinjs-lib/node_modules/bs58check": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/bs58check/-/bs58check-3.0.1.tgz", + "integrity": "sha512-hjuuJvoWEybo7Hn/0xOrczQKKEKD63WguEjlhLExYs2wUBcebDC1jDNK17eEAD2lYfw82d5ASC1d7K3SWszjaQ==", + "license": "MIT", + "peer": true, + "dependencies": { + "@noble/hashes": "^1.2.0", + "bs58": "^5.0.0" + } + }, + "node_modules/liquidjs-lib/node_modules/bs58": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz", + "integrity": "sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw==", + "license": "MIT", + "peer": true, + "dependencies": { + "base-x": "^3.0.2" + } + }, + "node_modules/liquidjs-lib/node_modules/bs58check": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/bs58check/-/bs58check-2.1.2.tgz", + "integrity": "sha512-0TS1jicxdU09dwJMNZtVAfzPi6Q6QeN0pM1Fkzrjn+XYHvzMKPU3pHVpva+769iNVSfIYWf7LJ6WR+BuuMf8cA==", + "license": "MIT", + "peer": true, + "dependencies": { + "bs58": "^4.0.0", + "create-hash": "^1.1.0", + "safe-buffer": "^5.1.2" + } + }, + "node_modules/liquidjs-lib/node_modules/ecpair": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/ecpair/-/ecpair-2.1.0.tgz", + "integrity": "sha512-cL/mh3MtJutFOvFc27GPZE2pWL3a3k4YvzUWEOvilnfZVlH3Jwgx/7d6tlD7/75tNk8TG2m+7Kgtz0SI1tWcqw==", + "license": "MIT", + "peer": true, + "dependencies": { + "randombytes": "^2.1.0", + "typeforce": "^1.18.0", + "wif": "^2.0.6" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/liquidjs-lib/node_modules/varuint-bitcoin": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/varuint-bitcoin/-/varuint-bitcoin-1.1.2.tgz", + "integrity": "sha512-4EVb+w4rx+YfVM32HQX42AbbT7/1f5zwAYhIujKXKk8NQK+JfRVl3pqT3hjNn/L+RstigmGGKVwHA/P0wgITZw==", + "license": "MIT", + "peer": true, + "dependencies": { + "safe-buffer": "^5.1.1" + } + }, + "node_modules/liquidjs-lib/node_modules/wif": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/wif/-/wif-2.0.6.tgz", + "integrity": "sha512-HIanZn1zmduSF+BQhkE+YXIbEiH0xPr1012QbFEGB0xsKqJii0/SqJjyn8dFv6y36kOznMgMB+LGcbZTJ1xACQ==", + "license": "MIT", + "peer": true, + "dependencies": { + "bs58check": "<3.0.0" + } + }, "node_modules/locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", @@ -6959,7 +7141,6 @@ "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", - "dev": true, "license": "MIT", "engines": { "node": ">= 8" @@ -6969,7 +7150,6 @@ "version": "4.0.8", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", - "dev": true, "license": "MIT", "dependencies": { "braces": "^3.0.3", @@ -6983,7 +7163,6 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", - "dev": true, "license": "MIT", "engines": { "node": ">=8.6" @@ -7019,7 +7198,6 @@ "version": "7.1.2", "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", "integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==", - "dev": true, "license": "ISC", "engines": { "node": ">=16 || 14 >=14.17" @@ -7048,7 +7226,6 @@ "version": "2.7.0", "resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz", "integrity": "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==", - "dev": true, "license": "MIT", "dependencies": { "any-promise": "^1.0.0", @@ -7060,7 +7237,6 @@ "version": "3.3.11", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.11.tgz", "integrity": "sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==", - "dev": true, "funding": [ { "type": "github", @@ -7093,7 +7269,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", - "dev": true, "license": "MIT", "engines": { "node": ">=0.10.0" @@ -7260,7 +7435,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz", "integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==", - "dev": true, "license": "MIT", "engines": { "node": ">= 6" @@ -7329,7 +7503,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz", "integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==", - "dev": true, "license": "BlueOak-1.0.0" }, "node_modules/parent-module": { @@ -7371,7 +7544,6 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -7381,14 +7553,12 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", - "dev": true, "license": "MIT" }, "node_modules/path-scurry": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz", "integrity": "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==", - "dev": true, "license": "BlueOak-1.0.0", "dependencies": { "lru-cache": "^10.2.0", @@ -7421,7 +7591,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", - "dev": true, "license": "ISC" }, "node_modules/picomatch": { @@ -7440,7 +7609,6 @@ "version": "2.3.0", "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "integrity": "sha512-udgsAY+fTnvv7kI7aaxbqwWNb0AHiB0qBO89PZKPkoTmGOgdbrHDKD+0B2X4uTfJ/FT1R09r9gTsjUjNJotuog==", - "dev": true, "license": "MIT", "engines": { "node": ">=0.10.0" @@ -7450,7 +7618,6 @@ "version": "4.0.7", "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.7.tgz", "integrity": "sha512-TfySrs/5nm8fQJDcBDuUng3VOUKsd7S+zqvbOTiGXHfxX4wK31ard+hoNuvkicM/2YFzlpDgABOevKSsB4G/FA==", - "dev": true, "license": "MIT", "engines": { "node": ">= 6" @@ -7489,7 +7656,6 @@ "version": "8.5.6", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.6.tgz", "integrity": "sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg==", - "dev": true, "funding": [ { "type": "opencollective", @@ -7518,7 +7684,6 @@ "version": "15.1.0", "resolved": "https://registry.npmjs.org/postcss-import/-/postcss-import-15.1.0.tgz", "integrity": "sha512-hpr+J05B2FVYUAXHeK1YyI267J/dDDhMU6B6civm8hSY1jYJnBXxzKDKDswzJmtLHryrjhnDjqqp/49t8FALew==", - "dev": true, "license": "MIT", "dependencies": { "postcss-value-parser": "^4.0.0", @@ -7536,7 +7701,6 @@ "version": "4.1.0", "resolved": "https://registry.npmjs.org/postcss-js/-/postcss-js-4.1.0.tgz", "integrity": "sha512-oIAOTqgIo7q2EOwbhb8UalYePMvYoIeRY2YKntdpFQXNosSu3vLrniGgmH9OKs/qAkfoj5oB3le/7mINW1LCfw==", - "dev": true, "funding": [ { "type": "opencollective", @@ -7562,7 +7726,6 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/postcss-load-config/-/postcss-load-config-6.0.1.tgz", "integrity": "sha512-oPtTM4oerL+UXmx+93ytZVN82RrlY/wPUV8IeDxFrzIjXOLF1pN+EmKPLbubvKHT2HC20xXsCAH2Z+CKV6Oz/g==", - "dev": true, "funding": [ { "type": "opencollective", @@ -7605,7 +7768,6 @@ "version": "6.2.0", "resolved": "https://registry.npmjs.org/postcss-nested/-/postcss-nested-6.2.0.tgz", "integrity": "sha512-HQbt28KulC5AJzG+cZtj9kvKB93CFCdLvog1WFLf1D+xmMvPGlBstkpTEZfK5+AN9hfJocyBFCNiqyS48bpgzQ==", - "dev": true, "funding": [ { "type": "opencollective", @@ -7631,7 +7793,6 @@ "version": "6.1.2", "resolved": "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-6.1.2.tgz", "integrity": "sha512-Q8qQfPiZ+THO/3ZrOrO0cJJKfpYCagtMUkXbnEfmgUjwXg6z/WBeOyS9APBBPCTSiDV+s4SwQGu8yFsiMRIudg==", - "dev": true, "license": "MIT", "dependencies": { "cssesc": "^3.0.0", @@ -7659,7 +7820,6 @@ "version": "4.2.0", "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz", "integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==", - "dev": true, "license": "MIT" }, "node_modules/prelude-ls": { @@ -7771,7 +7931,6 @@ "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", - "dev": true, "funding": [ { "type": "github", @@ -7788,6 +7947,16 @@ ], "license": "MIT" }, + "node_modules/randombytes": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", + "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", + "license": "MIT", + "peer": true, + "dependencies": { + "safe-buffer": "^5.1.0" + } + }, "node_modules/react": { "version": "18.3.1", "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", @@ -8010,7 +8179,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.0.tgz", "integrity": "sha512-Owdv/Ft7IjOgm/i0xvNDZ1LrRANRfew4b2prF3OWMQLxLfu3bS8FVhCsrSCMK4lR56Y9ya+AThoTpDCTxCmpRA==", - "dev": true, "license": "MIT", "dependencies": { "pify": "^2.3.0" @@ -8041,7 +8209,6 @@ "version": "3.6.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", - "dev": true, "license": "MIT", "dependencies": { "picomatch": "^2.2.1" @@ -8054,7 +8221,6 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", - "dev": true, "license": "MIT", "engines": { "node": ">=8.6" @@ -8128,7 +8294,6 @@ "version": "1.22.11", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.11.tgz", "integrity": "sha512-RfqAvLnMl313r7c9oclB1HhUEAezcpLjz95wFH4LVuhk9JF/r22qmVP9AMmOU4vMX7Q8pN8jwNg/CSpdFnMjTQ==", - "dev": true, "license": "MIT", "dependencies": { "is-core-module": "^2.16.1", @@ -8159,7 +8324,6 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.1.0.tgz", "integrity": "sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==", - "dev": true, "license": "MIT", "engines": { "iojs": ">=1.0.0", @@ -8183,7 +8347,7 @@ "version": "4.52.5", "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.52.5.tgz", "integrity": "sha512-3GuObel8h7Kqdjt0gxkEzaifHTqLVW56Y/bjN7PSQtkKr0w3V/QYSdt6QWYtd7A1xUtYQigtdUfgj1RvWVtorw==", - "dev": true, + "devOptional": true, "license": "MIT", "dependencies": { "@types/estree": "1.0.8" @@ -8232,7 +8396,6 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", - "dev": true, "funding": [ { "type": "github", @@ -8361,7 +8524,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", - "dev": true, "license": "MIT", "dependencies": { "shebang-regex": "^3.0.0" @@ -8374,7 +8536,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -8391,7 +8552,6 @@ "version": "4.1.0", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", - "dev": true, "license": "ISC", "engines": { "node": ">=14" @@ -8400,11 +8560,32 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/slip77": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/slip77/-/slip77-0.2.0.tgz", + "integrity": "sha512-LQaxb1Hef10kU36qvk71tlSt5BWph7GM0j+t2n5zs169X4QfnNbb6xqKZ38X3ETzGmCQaVdBwr925HDagHra/Q==", + "license": "MIT", + "peer": true, + "dependencies": { + "@types/node": "^13.9.1", + "create-hmac": "^1.1.7", + "typeforce": "^1.18.0" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/slip77/node_modules/@types/node": { + "version": "13.13.52", + "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.52.tgz", + "integrity": "sha512-s3nugnZumCC//n4moGGe6tkNMyYEdaDBitVjwPxXmR5lnMG5dHePinH2EdxkG3Rh1ghFHHixAG4NJhpJW1rthQ==", + "license": "MIT", + "peer": true + }, "node_modules/source-map-js": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==", - "dev": true, "license": "BSD-3-Clause", "engines": { "node": ">=0.10.0" @@ -8443,7 +8624,6 @@ "version": "5.1.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", - "dev": true, "license": "MIT", "dependencies": { "eastasianwidth": "^0.2.0", @@ -8462,7 +8642,6 @@ "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, "license": "MIT", "dependencies": { "emoji-regex": "^8.0.0", @@ -8477,7 +8656,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -8487,14 +8665,12 @@ "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "dev": true, "license": "MIT" }, "node_modules/string-width-cjs/node_modules/strip-ansi": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, "license": "MIT", "dependencies": { "ansi-regex": "^5.0.1" @@ -8507,7 +8683,6 @@ "version": "7.1.2", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.2.tgz", "integrity": "sha512-gmBGslpoQJtgnMAvOVqGZpEz9dyoKTCzy2nfz/n8aIFhN/jCE/rCmcxabB6jOOHV+0WNnylOxaxBQPSvcWklhA==", - "dev": true, "license": "MIT", "dependencies": { "ansi-regex": "^6.0.1" @@ -8524,7 +8699,6 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, "license": "MIT", "dependencies": { "ansi-regex": "^5.0.1" @@ -8537,7 +8711,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -8593,7 +8766,6 @@ "version": "3.35.0", "resolved": "https://registry.npmjs.org/sucrase/-/sucrase-3.35.0.tgz", "integrity": "sha512-8EbVDiu9iN/nESwxeSxDKe0dunta1GOlHufmSSXxMD2z2/tMZpDMpvXQGsc+ajGo8y2uYUmixaSRUc/QPoQ0GA==", - "dev": true, "license": "MIT", "dependencies": { "@jridgewell/gen-mapping": "^0.3.2", @@ -8629,7 +8801,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -8659,7 +8830,6 @@ "version": "3.4.18", "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.18.tgz", "integrity": "sha512-6A2rnmW5xZMdw11LYjhcI5846rt9pbLSabY5XPxo+XWdxwZaFEn47Go4NzFiHu9sNNmr/kXivP1vStfvMaK1GQ==", - "dev": true, "license": "MIT", "dependencies": { "@alloc/quick-lru": "^5.2.0", @@ -8706,7 +8876,6 @@ "version": "6.1.2", "resolved": "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-6.1.2.tgz", "integrity": "sha512-Q8qQfPiZ+THO/3ZrOrO0cJJKfpYCagtMUkXbnEfmgUjwXg6z/WBeOyS9APBBPCTSiDV+s4SwQGu8yFsiMRIudg==", - "dev": true, "license": "MIT", "dependencies": { "cssesc": "^3.0.0", @@ -8720,7 +8889,6 @@ "version": "3.3.1", "resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.1.tgz", "integrity": "sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==", - "dev": true, "license": "MIT", "dependencies": { "any-promise": "^1.0.0" @@ -8730,7 +8898,6 @@ "version": "1.6.0", "resolved": "https://registry.npmjs.org/thenify-all/-/thenify-all-1.6.0.tgz", "integrity": "sha512-RNxQH/qI8/t3thXJDwcstUO4zeqo64+Uy/+sNVRBx4Xn2OX+OZ9oP+iJnNFqplFra2ZUVeKCSa2oVWi3T4uVmA==", - "dev": true, "license": "MIT", "dependencies": { "thenify": ">= 3.1.0 < 4" @@ -8850,7 +9017,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", - "dev": true, "license": "MIT", "dependencies": { "is-number": "^7.0.0" @@ -8902,7 +9068,6 @@ "version": "0.1.13", "resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz", "integrity": "sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==", - "dev": true, "license": "Apache-2.0" }, "node_modules/tslib": { @@ -8948,7 +9113,6 @@ "version": "5.9.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", - "dev": true, "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", @@ -9001,7 +9165,6 @@ "version": "6.21.0", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", - "dev": true, "license": "MIT" }, "node_modules/unhead": { @@ -9462,7 +9625,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", - "dev": true, "license": "ISC", "dependencies": { "isexe": "^2.0.0" @@ -9541,7 +9703,6 @@ "version": "8.1.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", - "dev": true, "license": "MIT", "dependencies": { "ansi-styles": "^6.1.0", @@ -9560,7 +9721,6 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", - "dev": true, "license": "MIT", "dependencies": { "ansi-styles": "^4.0.0", @@ -9578,7 +9738,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -9588,14 +9747,12 @@ "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "dev": true, "license": "MIT" }, "node_modules/wrap-ansi-cjs/node_modules/string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, "license": "MIT", "dependencies": { "emoji-regex": "^8.0.0", @@ -9610,7 +9767,6 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, "license": "MIT", "dependencies": { "ansi-regex": "^5.0.1" @@ -9623,7 +9779,6 @@ "version": "6.2.3", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.3.tgz", "integrity": "sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg==", - "dev": true, "license": "MIT", "engines": { "node": ">=12" diff --git a/package.json b/package.json index e8f1493..be1b316 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,10 @@ "version": "0.0.0", "type": "module", "scripts": { - "dev": "npm i --legacy-peer-deps --silent && vite", - "build": "npm i --legacy-peer-deps --silent && vite build -l error && cp dist/index.html dist/404.html && echo 'Project built successfully!'", - "test": "npm i --legacy-peer-deps --silent && tsc --noEmit && eslint && vitest run --reporter=dot --silent && vite build -l error && cp dist/index.html dist/404.html && echo 'All tests passed!'", - "deploy": "npm i --legacy-peer-deps --silent && npm run build && npx -y nostr-deploy-cli deploy --skip-setup" + "dev": "npm i --silent && vite", + "build": "npm i --silent && vite build -l error && cp dist/index.html dist/404.html && echo 'Project built successfully!'", + "test": "npm i --silent && tsc --noEmit && eslint && vitest run --reporter=dot --silent && vite build -l error && cp dist/index.html dist/404.html && echo 'All tests passed!'", + "deploy": "npm i --silent && npm run build && npx -y nostr-deploy-cli deploy --skip-setup" }, "dependencies": { "@bitcoinerlab/secp256k1": "^1.2.0", @@ -54,8 +54,8 @@ "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "cmdk": "^1.0.0", - "coco-cashu-core": "1.0.0-rc10", - "coco-cashu-indexeddb": "0.8.0", + "coco-cashu-core": "1.0.0-rc.17", + "coco-cashu-indexeddb": "1.0.0-rc.17", "date-fns": "^3.6.0", "ecpair": "^3.0.0", "embla-carousel-react": "^8.3.0", diff --git a/src/components/wallet/CashuWallet.tsx b/src/components/wallet/CashuWallet.tsx index fa008d9..96a7c0f 100644 --- a/src/components/wallet/CashuWallet.tsx +++ b/src/components/wallet/CashuWallet.tsx @@ -8,7 +8,10 @@ import { useToast } from '@/hooks/useToast'; import { useQRCode, type QRScanResult } from '@/hooks/useQRCode'; import { useCopyToClipboard } from '@/hooks/useCopyToClipboard'; import { useMintManager } from '@/hooks/cashu/useMintManager'; -import { useWalletTransactions } from '@/hooks/cashu/useWalletTransactions'; +import { useTokenOperations } from '@/hooks/cashu/useTokenOperations'; +import { useLightningOperations } from '@/hooks/cashu/useLightningOperations'; +import { useReverseSwapOperations } from '@/hooks/cashu/useReverseSwapOperations'; +import { useSeedPhraseRestore } from '@/hooks/cashu/useSeedPhraseRestore'; import { useHistoryManager } from '@/hooks/cashu/useHistoryManager'; import { useBitcoinBalance, useBitcoinTransactionHistory, useBitcoinOperations } from '@/hooks/useBitcoinBalance'; import { useNsecAccess } from '@/hooks/useNsecAccess'; @@ -118,13 +121,42 @@ export function CashuWallet() { setActiveMintUrl(url); }; + // Transaction operation hooks + const tokenOps = useTokenOperations({ + coco, + activeMintUrl, + generateQRCode, + getEncodedToken, + }); + + const lightningOps = useLightningOperations({ + coco, + activeMintUrl, + generateQRCode, + getLightningInvoice, + }); + + const reverseSwapOps = useReverseSwapOperations({ + coco, + activeMintUrl, + }); + + const restore = useSeedPhraseRestore({ coco }); + + // Extract all needed values const { tokenInput, setTokenInput, - quoteAmount, - setQuoteAmount, sendAmount, setSendAmount, + sentToken, + setSentToken, + sentTokenQRCode, + } = tokenOps; + + const { + quoteAmount, + setQuoteAmount, lightningInvoice, setLightningInvoice, lightningAddressInput, @@ -137,30 +169,66 @@ export function CashuWallet() { setDecodedInvoiceAmount, pendingInvoice, setPendingInvoice, + showInvoiceModal, + setShowInvoiceModal, + currentInvoice, + handleConfirmInvoicePayment, + mintQuoteUnsubscribeRef, + } = lightningOps; + + const { pendingBitcoinSwapAddress, setPendingBitcoinSwapAddress, bitcoinSwapAmount, setBitcoinSwapAmount, swapStatus, - sentToken, - setSentToken, - sentTokenQRCode, - showInvoiceModal, - setShowInvoiceModal, - currentInvoice, - handleReceive, - handleSend, - handleConfirmInvoicePayment, + } = reverseSwapOps; + + const { handleRestoreFromSeedPhrase, isRestoring, - mintQuoteUnsubscribeRef, - } = useWalletTransactions({ - coco, - activeMintUrl, - generateQRCode, - getEncodedToken, - getLightningInvoice, - }); + } = restore; + + // Combined receive handler that routes to appropriate operation + const handleReceive = async () => { + if (tokenInput) { + return tokenOps.handleTokenReceive(); + } else if (quoteAmount) { + return lightningOps.handleLightningReceive(); + } + }; + + // Combined send handler that routes to appropriate operation + const handleSend = async () => { + // Check for token send first + if (sendAmount && activeMintUrl) { + return tokenOps.handleTokenSend(); + } + + // Check for reverse swap + if (pendingBitcoinSwapAddress && bitcoinSwapAmount) { + return reverseSwapOps.handleReverseSwap(); + } + + // Check for Lightning address payment + if (pendingLightningAddress) { + return lightningOps.handleLightningAddressPayment(); + } + + // Handle Lightning invoice/address input detection + const input = lightningInvoice.trim() || lightningAddressInput.trim(); + if (!input) return; + + // First check if it's a Bitcoin address for reverse swap + if (reverseSwapOps.detectBitcoinAddress(input)) { + setLightningInvoice(''); + setLightningAddressInput(''); + return; + } + + // Then check for Lightning address or invoice + lightningOps.detectAndHandleLightningInput(input); + }; const { historyEntries, diff --git a/src/components/wallet/PaymentCard.tsx b/src/components/wallet/PaymentCard.tsx index ed0d0c3..88fc5d4 100644 --- a/src/components/wallet/PaymentCard.tsx +++ b/src/components/wallet/PaymentCard.tsx @@ -1,6 +1,5 @@ import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; -import { Slider } from '@/components/ui/slider'; import { Send, Download, ArrowRight, Zap, X } from 'lucide-react'; import { useState, useEffect } from 'react'; @@ -115,43 +114,9 @@ export function TransactionCard({ setBitcoinSwapAmount, swapStatus, }: TransactionCardProps) { - // Slider state for confirmation - const [invoiceSliderValue, setInvoiceSliderValue] = useState([0]); - const [addressSliderValue, setAddressSliderValue] = useState([0]); - const [bitcoinSliderValue, setBitcoinSliderValue] = useState([0]); - const [swapSliderValue, setSwapSliderValue] = useState([0]); const [sendMaxEnabled, setSendMaxEnabled] = useState(false); const [swapAmountError, setSwapAmountError] = useState(null); - // Handle slider value changes and auto-submit at 100% - const handleInvoiceSliderChange = (value: number[]) => { - setInvoiceSliderValue(value); - if (value[0] === 100 && onConfirmInvoice) { - onConfirmInvoice(); - } - }; - - const handleAddressSliderChange = (value: number[]) => { - setAddressSliderValue(value); - if (value[0] === 100) { - onSend(); - } - }; - - const handleBitcoinSliderChange = (value: number[]) => { - setBitcoinSliderValue(value); - if (value[0] === 100) { - onSend(); - } - }; - - const handleSwapSliderChange = (value: number[]) => { - setSwapSliderValue(value); - if (value[0] === 100) { - onSend(); - } - }; - const handleSendMaxToggle = () => { const newState = !sendMaxEnabled; setSendMaxEnabled(newState); @@ -160,42 +125,16 @@ export function TransactionCard({ } }; - const handleSliderMouseUp = (sliderId: string) => { - // Reset the slider if it hasn't reached 100 - if (sliderId === 'invoice' && invoiceSliderValue[0] !== 100) { - setInvoiceSliderValue([0]); - } else if (sliderId === 'address' && addressSliderValue[0] !== 100) { - setAddressSliderValue([0]); - } else if (sliderId === 'bitcoin' && bitcoinSliderValue[0] !== 100) { - setBitcoinSliderValue([0]); - } else if (sliderId === 'swap' && swapSliderValue[0] !== 100) { - setSwapSliderValue([0]); - } - }; - - // Reset sliders when states change - useEffect(() => { - if (!pendingInvoice) { - setInvoiceSliderValue([0]); - } - }, [pendingInvoice]); - - useEffect(() => { - if (!pendingLightningAddress) { - setAddressSliderValue([0]); - } - }, [pendingLightningAddress]); - + // Reset send max toggle when bitcoin recipient changes useEffect(() => { if (!pendingBitcoinRecipient) { - setBitcoinSliderValue([0]); setSendMaxEnabled(false); } }, [pendingBitcoinRecipient]); + // Reset swap amount error when swap address changes useEffect(() => { if (!pendingBitcoinSwapAddress) { - setSwapSliderValue([0]); setSwapAmountError(null); } }, [pendingBitcoinSwapAddress]); @@ -329,7 +268,7 @@ export function TransactionCard({ ) : pendingBitcoinRecipient ? ( - // Step 2: Amount Input with Slider + // Step 2: Amount Input
-
-
-
handleSliderMouseUp('bitcoin')} - onMouseLeave={() => handleSliderMouseUp('bitcoin')} - onTouchEnd={() => handleSliderMouseUp('bitcoin')} - > - -
-
- - {bitcoinSliderValue[0] === 100 ? 'Confirmed!' : 'Slide to Confirm'} - -
-
+
+
) : ( @@ -440,34 +366,21 @@ export function TransactionCard({
) : pendingInvoice && decodedInvoiceAmount ? ( - // Lightning Invoice Confirmation (with slider) + // Lightning Invoice Confirmation
-
-
-
handleSliderMouseUp('invoice')} - onMouseLeave={() => handleSliderMouseUp('invoice')} - onTouchEnd={() => handleSliderMouseUp('invoice')} - > - -
-
- - {invoiceSliderValue[0] === 100 ? 'Confirmed!' : 'Slide to Confirm'} - -
-
+
+
) : pendingBitcoinSwapAddress ? ( - // Reverse Swap Amount Input with Slider + // Reverse Swap Amount Input
{swapStatus}

)}
-
-
-
handleSliderMouseUp('swap')} - onMouseLeave={() => handleSliderMouseUp('swap')} - onTouchEnd={() => handleSliderMouseUp('swap')} - > - -
-
- - {swapSliderValue[0] === 100 ? 'Confirmed!' : 'Slide to Confirm'} - -
-
+
+
) : pendingLightningAddress ? ( - // Lightning Address Amount Input with Slider + // Lightning Address Amount Input
-
-
-
handleSliderMouseUp('address')} - onMouseLeave={() => handleSliderMouseUp('address')} - onTouchEnd={() => handleSliderMouseUp('address')} - > - -
-
- - {addressSliderValue[0] === 100 ? 'Confirmed!' : 'Slide to Confirm'} - -
-
+
+
) : ( diff --git a/src/components/wallet/WalletHeader.tsx b/src/components/wallet/WalletHeader.tsx index 2f70397..d49732b 100644 --- a/src/components/wallet/WalletHeader.tsx +++ b/src/components/wallet/WalletHeader.tsx @@ -1,7 +1,6 @@ import { useState, useEffect } from 'react'; import { Zap, Coins, Copy, Check, QrCode, Link, Key } from 'lucide-react'; import { exchangeRateService } from '@/lib/exchangeRateService'; -import { useToast } from '@/hooks/useToast'; import { LoginIcon } from '@/components/auth/LoginIcon'; import { MintSelector } from './MintSelector'; import { UTXOSelector } from './UTXOSelector'; @@ -76,24 +75,6 @@ const getToggleTitle = (showSats: boolean): string => { return `Click to show in ${showSats ? 'USD' : 'sats'}`; }; -const getModeTitle = (mode: string): string => { - switch (mode) { - case 'tokens': return 'Cashu'; - case 'lightning': return 'Lightning'; - case 'bitcoin': return 'Bitcoin'; - default: return 'Unknown'; - } -}; - -const getModeDescription = (mode: string): string => { - switch (mode) { - case 'tokens': return 'Send and receive with Cashu eCash'; - case 'lightning': return 'Send and receive with Lightning'; - case 'bitcoin': return 'Send and receive with on-chain Bitcoin'; - default: return ''; - } -}; - const getButtonTitle = (mode: string): string => { switch (mode) { case 'tokens': return 'Switch to On-Chain'; @@ -141,7 +122,6 @@ export function WalletHeader({ const [bitcoinAddressCopied, setBitcoinAddressCopied] = useState(false); const [mnemonicCopied, setMnemonicCopied] = useState(false); const [btcUsdRate, setBtcUsdRate] = useState(null); - const { toast } = useToast(); useEffect(() => { exchangeRateService.getBtcUsdRate() @@ -160,11 +140,6 @@ export function WalletHeader({ } setMode(newMode); - - toast({ - title: `${getModeTitle(newMode)} Enabled!`, - description: getModeDescription(newMode) - }); }; diff --git a/src/hooks/cashu/useLightningOperations.ts b/src/hooks/cashu/useLightningOperations.ts new file mode 100644 index 0000000..639f9fa --- /dev/null +++ b/src/hooks/cashu/useLightningOperations.ts @@ -0,0 +1,305 @@ +import { useState, useCallback, useEffect, useRef } from 'react'; +import { decodeBolt11Amount, isValidBolt11Invoice } from '@/lib/bolt11Decoder'; +import type { Manager } from 'coco-cashu-core'; +import { useToast } from '@/hooks/useToast'; + +interface UseLightningOperationsProps { + coco: Manager | null; + activeMintUrl: string | null; + generateQRCode: (text: string) => Promise; + getLightningInvoice: (params: { + lightningAddress: string; + amountSats: number; + }) => Promise; +} + +export function useLightningOperations({ + coco, + activeMintUrl, + generateQRCode, + getLightningInvoice, +}: UseLightningOperationsProps) { + const { toast } = useToast(); + + // Receive state + const [quoteAmount, setQuoteAmount] = useState(''); + + // Send state + const [lightningInvoice, setLightningInvoice] = useState(''); + const [lightningAddressInput, setLightningAddressInput] = useState(''); + const [lightningAddressAmount, setLightningAddressAmount] = useState(''); + const [pendingLightningAddress, setPendingLightningAddress] = useState(null); + const [decodedInvoiceAmount, setDecodedInvoiceAmount] = useState(null); + const [pendingInvoice, setPendingInvoice] = useState(null); + + // Processing state to prevent concurrent executions + const [isProcessingPayment, setIsProcessingPayment] = useState(false); + + // Invoice modal state + const [showInvoiceModal, setShowInvoiceModal] = useState(false); + const [currentInvoice, setCurrentInvoice] = useState<{ + quoteId: string; + mintUrl: string; + amount: number; + invoice: string; + qrCodeUrl: string; + expiry: number; + } | null>(null); + + // Ref to store the mint quote redeemed event unsubscribe function + const mintQuoteUnsubscribeRef = useRef<(() => void) | null>(null); + + // Handle receive (Lightning quote/invoice creation) + const handleLightningReceive = useCallback(async () => { + if (!coco || !quoteAmount || !activeMintUrl) { + return; + } + + try { + const amount = parseInt(quoteAmount); + if (isNaN(amount) || amount <= 0) { + toast({ + variant: 'destructive', + title: 'Invalid Amount', + description: 'Please enter a valid amount', + }); + return; + } + + const quote = await coco.quotes.createMintQuote(activeMintUrl, amount); + + // Generate QR code for the Lightning invoice + const qrCodeUrl = await generateQRCode(quote.request); + + // Set the invoice data and show modal + setCurrentInvoice({ + quoteId: quote.quote, + mintUrl: activeMintUrl, + amount, + invoice: quote.request, + qrCodeUrl, + expiry: quote.expiry, + }); + + setShowInvoiceModal(true); + setQuoteAmount(''); + + // Clean up any previous listener + if (mintQuoteUnsubscribeRef.current) { + mintQuoteUnsubscribeRef.current(); + mintQuoteUnsubscribeRef.current = null; + } + + // Listen for payment notification via mint-quote:redeemed event + const quoteId = quote.quote; + const invoiceAmount = amount; + + const unsubscribe = coco.on('mint-quote:redeemed', (payload: unknown) => { + const redeemedQuote = payload as { quoteId?: string }; + + // Check if this is the quote we're waiting for + if (redeemedQuote.quoteId === quoteId) { + toast({ + title: 'Payment Received', + description: `Successfully received ${invoiceAmount} sats! Tokens have been added to your wallet.`, + }); + setShowInvoiceModal(false); + setCurrentInvoice(null); + + // Clean up the event listener + mintQuoteUnsubscribeRef.current = null; + unsubscribe(); + } + }); + + // Store unsubscribe function for cleanup + mintQuoteUnsubscribeRef.current = unsubscribe; + } catch (err) { + toast({ + variant: 'destructive', + title: 'Quote Creation Failed', + description: err instanceof Error ? err.message : 'Unknown error', + }); + } + }, [coco, quoteAmount, activeMintUrl, toast, generateQRCode]); + + // Detect input type and handle Lightning address/invoice parsing + const detectAndHandleLightningInput = useCallback((input: string): 'lightning_address' | 'invoice' | null => { + const trimmed = input.trim(); + if (!trimmed) return null; + + // Check if it's a Lightning address (contains @) + if (trimmed.includes('@')) { + setPendingLightningAddress(trimmed); + setLightningAddressInput(''); + return 'lightning_address'; + } + + // Check if it's a Lightning invoice + if (isValidBolt11Invoice(trimmed)) { + const amount = decodeBolt11Amount(trimmed); + if (amount) { + // Show amount confirmation screen + setPendingInvoice(trimmed); + setDecodedInvoiceAmount(amount); + setLightningInvoice(''); + return 'invoice'; + } else { + // Failed to decode amount - show error + toast({ + variant: 'destructive', + title: 'Invalid Invoice', + description: 'Unable to decode the lightning invoice amount. Please check the invoice format.', + }); + setLightningInvoice(''); + return null; + } + } else { + // Not a valid BOLT11 invoice - show error + toast({ + variant: 'destructive', + title: 'Invalid Invoice', + description: 'This does not appear to be a valid lightning invoice. Please check the format.', + }); + setLightningInvoice(''); + return null; + } + }, [toast]); + + // Handle Lightning address payment + const handleLightningAddressPayment = useCallback(async () => { + // Prevent concurrent executions + if (isProcessingPayment) { + return; + } + + if (!coco || !pendingLightningAddress || !lightningAddressAmount || !activeMintUrl) { + return; + } + + setIsProcessingPayment(true); + + try { + const amount = parseInt(lightningAddressAmount); + if (isNaN(amount) || amount <= 0) { + toast({ + variant: 'destructive', + title: 'Invalid Amount', + description: 'Please enter a valid amount', + }); + setIsProcessingPayment(false); + return; + } + + const invoice = await getLightningInvoice({ + lightningAddress: pendingLightningAddress, + amountSats: amount, + }); + + const meltQuote = await coco.quotes.createMeltQuote( + activeMintUrl, + invoice + ); + await coco.quotes.payMeltQuote(activeMintUrl, meltQuote.quote); + + toast({ + title: 'Payment Sent', + description: `Successfully sent ${amount} sats to ${pendingLightningAddress}!`, + }); + + // Reset state + setPendingLightningAddress(null); + setLightningAddressInput(''); + setLightningAddressAmount(''); + } catch (err) { + console.error('Payment error:', err); + toast({ + variant: 'destructive', + title: 'Payment Failed', + description: err instanceof Error ? err.message : 'Unknown error', + }); + } finally { + setIsProcessingPayment(false); + } + }, [coco, pendingLightningAddress, lightningAddressAmount, activeMintUrl, getLightningInvoice, toast, isProcessingPayment]); + + // Handle confirmed invoice payment + const handleConfirmInvoicePayment = useCallback(async () => { + // Prevent concurrent executions + if (isProcessingPayment) { + return; + } + + if (!coco || !pendingInvoice || !activeMintUrl) return; + + setIsProcessingPayment(true); + + try { + const meltQuote = await coco.quotes.createMeltQuote( + activeMintUrl, + pendingInvoice + ); + await coco.quotes.payMeltQuote(activeMintUrl, meltQuote.quote); + + toast({ + title: 'Invoice Paid', + description: `Lightning invoice paid successfully for ${decodedInvoiceAmount} sats!`, + }); + + // Reset state + setPendingInvoice(null); + setDecodedInvoiceAmount(null); + } catch (err) { + toast({ + variant: 'destructive', + title: 'Invoice Payment Failed', + description: err instanceof Error ? err.message : 'Unknown error', + }); + } finally { + setIsProcessingPayment(false); + } + }, [coco, pendingInvoice, activeMintUrl, decodedInvoiceAmount, toast, isProcessingPayment]); + + // Cleanup mint quote listener on component unmount + useEffect(() => { + return () => { + if (mintQuoteUnsubscribeRef.current) { + mintQuoteUnsubscribeRef.current(); + mintQuoteUnsubscribeRef.current = null; + } + }; + }, []); + + return { + // Receive state + quoteAmount, + setQuoteAmount, + // Send state + lightningInvoice, + setLightningInvoice, + lightningAddressInput, + setLightningAddressInput, + lightningAddressAmount, + setLightningAddressAmount, + pendingLightningAddress, + setPendingLightningAddress, + decodedInvoiceAmount, + setDecodedInvoiceAmount, + pendingInvoice, + setPendingInvoice, + // Invoice modal state + showInvoiceModal, + setShowInvoiceModal, + currentInvoice, + setCurrentInvoice, + // Processing state + isProcessingPayment, + // Handlers + handleLightningReceive, + detectAndHandleLightningInput, + handleLightningAddressPayment, + handleConfirmInvoicePayment, + // Refs + mintQuoteUnsubscribeRef, + }; +} diff --git a/src/hooks/cashu/useReverseSwapOperations.ts b/src/hooks/cashu/useReverseSwapOperations.ts new file mode 100644 index 0000000..7c9eb14 --- /dev/null +++ b/src/hooks/cashu/useReverseSwapOperations.ts @@ -0,0 +1,189 @@ +import { useState, useCallback, useEffect } from 'react'; +import { nip19 } from 'nostr-tools'; +import { createReverseSwap, type SwapStatusUpdate } from '@/hooks/useReverseSwap'; +import { isValidBitcoinAddress, npubToBitcoinAddress } from '@/lib/bitcoin'; +import type { Manager } from 'coco-cashu-core'; +import { useToast } from '@/hooks/useToast'; + +interface UseReverseSwapOperationsProps { + coco: Manager | null; + activeMintUrl: string | null; +} + +export function useReverseSwapOperations({ coco, activeMintUrl }: UseReverseSwapOperationsProps) { + const { toast } = useToast(); + + // Reverse swap state (Lightning -> Bitcoin) + const [pendingBitcoinSwapAddress, setPendingBitcoinSwapAddress] = useState(null); + const [bitcoinSwapAmount, setBitcoinSwapAmount] = useState(''); + const [swapStatus, setSwapStatus] = useState(null); + const [reverseSwapClose, setReverseSwapClose] = useState<(() => void) | null>(null); + + // Detect if input is a Bitcoin address or npub for reverse swap + const detectBitcoinAddress = useCallback((input: string): boolean => { + // Check if it's a Bitcoin address + if (isValidBitcoinAddress(input)) { + setPendingBitcoinSwapAddress(input); + return true; + } + + // Check if it's an npub (can be converted to Bitcoin address) + try { + const decoded = nip19.decode(input); + if (decoded.type === 'npub') { + const bitcoinAddr = npubToBitcoinAddress(input); + if (bitcoinAddr) { + setPendingBitcoinSwapAddress(input); // Store npub, will convert later + return true; + } + } + } catch { + // Not an npub, continue + } + + return false; + }, []); + + // Handle reverse swap execution + const handleReverseSwap = useCallback(async () => { + if (!coco || !pendingBitcoinSwapAddress || !bitcoinSwapAmount || !activeMintUrl) { + return; + } + + try { + const amount = parseInt(bitcoinSwapAmount); + if (isNaN(amount) || amount <= 0) { + toast({ + variant: 'destructive', + title: 'Invalid Amount', + description: 'Please enter a valid amount', + }); + return; + } + + // Validate reverse swap amount limits (25,000 - 25,000,000 sats) + if (amount < 25_000 || amount > 25_000_000) { + toast({ + variant: 'destructive', + title: 'Invalid Amount', + description: 'Reverse swap amount must be between 25,000 and 25,000,000 sats', + }); + return; + } + + // Determine destination address (could be Bitcoin address or npub) + let destinationAddress = pendingBitcoinSwapAddress; + try { + // Try to decode as npub first + const decoded = nip19.decode(pendingBitcoinSwapAddress); + if (decoded.type === 'npub') { + destinationAddress = npubToBitcoinAddress(pendingBitcoinSwapAddress); + } + } catch { + // Not an npub, assume it's already a Bitcoin address + } + + // Initiate reverse swap + setSwapStatus('Creating reverse swap...'); + const swapResult = await createReverseSwap({ + invoiceAmount: amount, + destinationAddress, + onStatusUpdate: (update: SwapStatusUpdate) => { + switch (update.status) { + case 'swap.created': + setSwapStatus('Waiting for invoice payment...'); + break; + case 'transaction.mempool': + setSwapStatus('Swap transaction sent to blockchain...'); + break; + case 'invoice.settled': + case 'transaction.confirmed': + setSwapStatus('Swap completed!'); + break; + } + }, + onSuccess: () => { + const displayAddress = destinationAddress.length > 26 + ? destinationAddress.slice(0, 12) + '...' + destinationAddress.slice(-12) + : destinationAddress; + toast({ + title: 'Reverse Swap Completed', + description: `Successfully swapped ${amount} sats to Bitcoin address ${displayAddress}!`, + }); + setSwapStatus(null); + setPendingBitcoinSwapAddress(null); + setBitcoinSwapAmount(''); + if (reverseSwapClose) { + reverseSwapClose(); + setReverseSwapClose(null); + } + }, + onError: (error: Error) => { + toast({ + variant: 'destructive', + title: 'Reverse Swap Failed', + description: error.message, + }); + setSwapStatus(null); + setPendingBitcoinSwapAddress(null); + setBitcoinSwapAmount(''); + if (reverseSwapClose) { + reverseSwapClose(); + setReverseSwapClose(null); + } + }, + }); + + // Store close function for cleanup + setReverseSwapClose(() => swapResult.close); + + // Pay the Lightning invoice from the swap using the active mint + setSwapStatus('Paying Lightning invoice...'); + const meltQuote = await coco.quotes.createMeltQuote( + activeMintUrl, + swapResult.invoice + ); + await coco.quotes.payMeltQuote(activeMintUrl, meltQuote.quote); + + toast({ + title: 'Invoice Paid', + description: `Lightning invoice paid. Swap in progress...`, + }); + } catch (err) { + console.error('Reverse swap error:', err); + toast({ + variant: 'destructive', + title: 'Reverse Swap Failed', + description: err instanceof Error ? err.message : 'Unknown error', + }); + setSwapStatus(null); + setPendingBitcoinSwapAddress(null); + setBitcoinSwapAmount(''); + if (reverseSwapClose) { + reverseSwapClose(); + setReverseSwapClose(null); + } + } + }, [coco, pendingBitcoinSwapAddress, bitcoinSwapAmount, activeMintUrl, toast, reverseSwapClose]); + + // Cleanup reverse swap WebSocket on unmount + useEffect(() => { + return () => { + if (reverseSwapClose) { + reverseSwapClose(); + } + }; + }, [reverseSwapClose]); + + return { + // State + pendingBitcoinSwapAddress, + setPendingBitcoinSwapAddress, + bitcoinSwapAmount, + setBitcoinSwapAmount, + swapStatus, + // Functions + detectBitcoinAddress, + handleReverseSwap, + }; +} diff --git a/src/hooks/cashu/useSeedPhraseRestore.ts b/src/hooks/cashu/useSeedPhraseRestore.ts new file mode 100644 index 0000000..8ba7d97 --- /dev/null +++ b/src/hooks/cashu/useSeedPhraseRestore.ts @@ -0,0 +1,116 @@ +import { useState, useCallback } from 'react'; +import * as bip39 from '@scure/bip39'; +import { wordlist } from '@scure/bip39/wordlists/english.js'; +import { initializeCoco, ConsoleLogger } from 'coco-cashu-core'; +import { IndexedDbRepositories } from 'coco-cashu-indexeddb'; +import type { Manager } from 'coco-cashu-core'; +import { useToast } from '@/hooks/useToast'; + +interface UseSeedPhraseRestoreProps { + coco: Manager | null; +} + +export function useSeedPhraseRestore({ coco }: UseSeedPhraseRestoreProps) { + const { toast } = useToast(); + const [isRestoring, setIsRestoring] = useState(false); + + const handleRestoreFromSeedPhrase = useCallback(async (seedPhrase: string, mintUrl: string) => { + if (!coco) { + throw new Error('Wallet not initialized'); + } + + setIsRestoring(true); + + try { + // Clean and validate the seed phrase + const cleanedSeedPhrase = seedPhrase.trim().toLowerCase(); + + // Check if it's a valid mnemonic format + if (!bip39.validateMnemonic(cleanedSeedPhrase, wordlist)) { + // Try to provide more specific error information + const words = cleanedSeedPhrase.split(/\s+/); + if (words.length !== 12) { + throw new Error(`Seed phrase must have exactly 12 words, but found ${words.length} words`); + } + + // Check if all words are valid + const invalidWords = words.filter(word => !wordlist.includes(word)); + if (invalidWords.length > 0) { + throw new Error(`Invalid words found: ${invalidWords.join(', ')}`); + } + + throw new Error('Invalid seed phrase format. Please check that all words are spelled correctly.'); + } + + // Verify this is a different seed from the current wallet + const currentMnemonic = localStorage.getItem('cashu-mnemonic'); + if (currentMnemonic && currentMnemonic.toLowerCase() === cleanedSeedPhrase) { + throw new Error('This is the same seed phrase as your current wallet. Please enter a different seed phrase to restore from.'); + } + + // Convert seed phrase to seed + const restoredSeed = bip39.mnemonicToSeedSync(cleanedSeedPhrase); + + // Get current balance before restore + const balancesBefore = await coco.wallet.getBalances(); + const balanceBefore = balancesBefore[mintUrl] || 0; + + // Create a temporary coco instance with the restored seed to fetch proofs + const tempRepo = new IndexedDbRepositories({ name: `cashu-wallet-restore-${Date.now()}` }); + await tempRepo.init(); + + const tempCoco = await initializeCoco({ + repo: tempRepo, + seedGetter: async () => restoredSeed, + logger: new ConsoleLogger(`restore-${Date.now()}`, { level: "debug" }) + }); + + try { + // Restore the proofs in the temporary wallet + await tempCoco.wallet.restore(mintUrl); + + // Get the restored balance from the temporary wallet + const tempBalances = await tempCoco.wallet.getBalances(); + const restoredAmount = tempBalances[mintUrl] || 0; + + if (restoredAmount <= 0) { + toast({ + title: "No Tokens Found", + description: "No tokens were found for this seed phrase on the selected mint.", + }); + return; + } + + // Send the restored tokens from the temporary wallet + const token = await tempCoco.wallet.send(mintUrl, restoredAmount); + + // Receive the token in the main wallet + await coco.wallet.receive(token); + + // Verify the transfer + const balancesAfter = await coco.wallet.getBalances(); + const balanceAfter = balancesAfter[mintUrl] || 0; + const actualRestored = balanceAfter - balanceBefore; + + toast({ + title: "Restore Successful", + description: `Restored ${actualRestored} sats from the seed phrase and added to your current wallet.`, + }); + } finally { + // Clean up temporary database (optional - happens automatically on next session) + // The temporary IndexedDB will be isolated to the unique name we provided + } + + } catch (error) { + console.error('Restore failed:', error); + throw error; + } finally { + setIsRestoring(false); + } + }, [coco, toast]); + + return { + handleRestoreFromSeedPhrase, + isRestoring, + }; +} diff --git a/src/hooks/cashu/useTokenOperations.ts b/src/hooks/cashu/useTokenOperations.ts new file mode 100644 index 0000000..bdf4bd2 --- /dev/null +++ b/src/hooks/cashu/useTokenOperations.ts @@ -0,0 +1,156 @@ +import { useState, useCallback } from 'react'; +import { isUnknownMintError, extractMintUrlFromError } from './walletUtils'; +import type { Manager } from 'coco-cashu-core'; +import type { Token } from '@cashu/cashu-ts'; +import { useToast } from '@/hooks/useToast'; + +interface UseTokenOperationsProps { + coco: Manager | null; + activeMintUrl: string | null; + generateQRCode: (text: string) => Promise; + getEncodedToken: (token: Token | string) => string; +} + +export function useTokenOperations({ + coco, + activeMintUrl, + generateQRCode, + getEncodedToken, +}: UseTokenOperationsProps) { + const { toast } = useToast(); + + // Receive state + const [tokenInput, setTokenInput] = useState(''); + + // Send state + const [sendAmount, setSendAmount] = useState(''); + + // Transaction output state + const [sentToken, setSentToken] = useState(null); + const [sentTokenQRCode, setSentTokenQRCode] = useState(''); + + // Generate QR code for sent token + const generateSentTokenQRCode = useCallback(async (token: string) => { + try { + const qrCodeUrl = await generateQRCode(token); + setSentTokenQRCode(qrCodeUrl); + } catch (err) { + console.error('Failed to generate sent token QR code:', err); + } + }, [generateQRCode]); + + // Handle unknown mint error by adding the mint and retrying + const handleUnknownMintError = useCallback( + async (mintUrl: string) => { + if (!coco) return; + + try { + console.log('Adding unknown mint:', mintUrl); + + // Add the mint + await coco.mint.addMint(mintUrl); + + // Retry receiving the token + await coco.wallet.receive(tokenInput); + setTokenInput(''); + + toast({ + title: 'Token Received', + description: `Cashu token redeemed successfully! Added new mint: ${mintUrl}`, + }); + } catch (retryErr) { + console.error('Failed to add mint and retry receive:', retryErr); + toast({ + variant: 'destructive', + title: 'Receive Failed', + description: `Failed to add mint and receive token: ${retryErr instanceof Error ? retryErr.message : 'Unknown error'}`, + }); + } + }, + [coco, tokenInput, toast] + ); + + // Handle receive (token) + const handleTokenReceive = useCallback(async () => { + if (!coco || !tokenInput) { + return; + } + + try { + console.log( + 'Attempting to receive token:', + tokenInput.substring(0, 20) + '...' + ); + await coco.wallet.receive(tokenInput); + setTokenInput(''); + toast({ + title: 'Token Received', + description: 'Cashu token redeemed successfully!', + }); + } catch (err) { + console.error('Token receive error:', err); + + // Handle UnknownMintError by automatically adding the mint + if (isUnknownMintError(err)) { + const mintUrl = extractMintUrlFromError(err); + if (mintUrl) { + await handleUnknownMintError(mintUrl); + return; + } + } + + toast({ + variant: 'destructive', + title: 'Receive Failed', + description: err instanceof Error ? err.message : 'Unknown error', + }); + } + }, [coco, tokenInput, toast, handleUnknownMintError]); + + // Handle send (token) + const handleTokenSend = useCallback(async () => { + if (!coco || !sendAmount || !activeMintUrl) { + return; + } + + try { + const amount = parseInt(sendAmount); + if (isNaN(amount) || amount <= 0) { + toast({ + variant: 'destructive', + title: 'Invalid Amount', + description: 'Please enter a valid amount', + }); + return; + } + + const token = await coco.wallet.send(activeMintUrl, amount); + const encodedToken = getEncodedToken(token); + setSentToken(encodedToken); + await generateSentTokenQRCode(encodedToken); + setSendAmount(''); + } catch (err) { + toast({ + variant: 'destructive', + title: 'Send Failed', + description: err instanceof Error ? err.message : 'Unknown error', + }); + } + }, [coco, sendAmount, activeMintUrl, getEncodedToken, generateSentTokenQRCode, toast]); + + return { + // Receive state + tokenInput, + setTokenInput, + // Send state + sendAmount, + setSendAmount, + // Transaction output state + sentToken, + setSentToken, + sentTokenQRCode, + // Handlers + handleTokenReceive, + handleTokenSend, + }; +} diff --git a/src/hooks/cashu/useWalletTransactions.ts b/src/hooks/cashu/useWalletTransactions.ts deleted file mode 100644 index 94cc974..0000000 --- a/src/hooks/cashu/useWalletTransactions.ts +++ /dev/null @@ -1,741 +0,0 @@ -import { useState, useCallback, useRef, useEffect } from 'react'; -import { isUnknownMintError, extractMintUrlFromError } from './walletUtils'; -import { decodeBolt11Amount, isValidBolt11Invoice } from '@/lib/bolt11Decoder'; -import { isValidBitcoinAddress, npubToBitcoinAddress } from '@/lib/bitcoin'; -import { createReverseSwap, type SwapStatusUpdate } from '@/hooks/useReverseSwap'; -import { nip19 } from 'nostr-tools'; -import type { Manager } from 'coco-cashu-core'; -import type { Token } from '@cashu/cashu-ts'; -import { useToast } from '@/hooks/useToast'; -import * as bip39 from '@scure/bip39'; -import { wordlist } from '@scure/bip39/wordlists/english.js'; -import { initializeCoco, ConsoleLogger } from 'coco-cashu-core'; -import { IndexedDbRepositories } from 'coco-cashu-indexeddb'; - -interface UseWalletTransactionsProps { - coco: Manager | null; - activeMintUrl: string | null; - generateQRCode: (text: string) => Promise; - getEncodedToken: (token: Token | string) => string; - getLightningInvoice: (params: { - lightningAddress: string; - amountSats: number; - }) => Promise; -} - -export function useWalletTransactions({ - coco, - activeMintUrl, - generateQRCode, - getEncodedToken, - getLightningInvoice, -}: UseWalletTransactionsProps) { - const { toast } = useToast(); - // Receive state - const [tokenInput, setTokenInput] = useState(''); - const [quoteAmount, setQuoteAmount] = useState(''); - - // Send state - const [sendAmount, setSendAmount] = useState(''); - const [lightningInvoice, setLightningInvoice] = useState(''); - const [lightningAddressInput, setLightningAddressInput] = useState(''); - const [lightningAddressAmount, setLightningAddressAmount] = useState(''); - const [pendingLightningAddress, setPendingLightningAddress] = useState< - string | null - >(null); - const [decodedInvoiceAmount, setDecodedInvoiceAmount] = useState(null); - const [pendingInvoice, setPendingInvoice] = useState(null); - - // Reverse swap state (Lightning -> Bitcoin) - const [pendingBitcoinSwapAddress, setPendingBitcoinSwapAddress] = useState(null); - const [bitcoinSwapAmount, setBitcoinSwapAmount] = useState(''); - const [swapStatus, setSwapStatus] = useState(null); - const [reverseSwapClose, setReverseSwapClose] = useState<(() => void) | null>(null); - - // Transaction output state - const [sentToken, setSentToken] = useState(null); - const [sentTokenQRCode, setSentTokenQRCode] = useState(''); - - // Invoice modal state - const [showInvoiceModal, setShowInvoiceModal] = useState(false); - const [currentInvoice, setCurrentInvoice] = useState<{ - quoteId: string; - mintUrl: string; - amount: number; - invoice: string; - qrCodeUrl: string; - expiry: number; - } | null>(null); - - // Restore state - const [isRestoring, setIsRestoring] = useState(false); - - // Ref to store the mint quote redeemed event unsubscribe function - const mintQuoteUnsubscribeRef = useRef<(() => void) | null>(null); - - // Generate QR code for sent token - const generateSentTokenQRCode = useCallback(async (token: string) => { - try { - const qrCodeUrl = await generateQRCode(token); - setSentTokenQRCode(qrCodeUrl); - } catch (err) { - console.error('Failed to generate sent token QR code:', err); - } - }, [generateQRCode]); - - // Handle unknown mint error by adding the mint and retrying - const handleUnknownMintError = useCallback( - async (mintUrl: string) => { - if (!coco) return; - - try { - console.log('Adding unknown mint:', mintUrl); - - // Add the mint - await coco.mint.addMint(mintUrl); - - // Retry receiving the token - await coco.wallet.receive(tokenInput); - setTokenInput(''); - - toast({ - title: 'Token Received', - description: `Cashu token redeemed successfully! Added new mint: ${mintUrl}`, - }); - } catch (retryErr) { - console.error('Failed to add mint and retry receive:', retryErr); - toast({ - variant: 'destructive', - title: 'Receive Failed', - description: `Failed to add mint and receive token: ${retryErr instanceof Error ? retryErr.message : 'Unknown error'}`, - }); - } - }, - [coco, tokenInput, toast] - ); - - // Handle receive (token or Lightning) - const handleReceive = useCallback(async () => { - if (!coco) return; - - // Receive Cashu token mode - if (!tokenInput && !quoteAmount) { - return; - } - - if (tokenInput) { - // Receive token mode - try { - console.log( - 'Attempting to receive token:', - tokenInput.substring(0, 20) + '...' - ); - await coco.wallet.receive(tokenInput); - setTokenInput(''); - toast({ - title: 'Token Received', - description: 'Cashu token redeemed successfully!', - }); - } catch (err) { - console.error('Token receive error:', err); - - // Handle UnknownMintError by automatically adding the mint - if (isUnknownMintError(err)) { - const mintUrl = extractMintUrlFromError(err); - if (mintUrl) { - await handleUnknownMintError(mintUrl); - return; - } - } - - toast({ - variant: 'destructive', - title: 'Receive Failed', - description: err instanceof Error ? err.message : 'Unknown error', - }); - } - } else if (quoteAmount && activeMintUrl) { - // Lightning quote mode - try { - const amount = parseInt(quoteAmount); - if (isNaN(amount) || amount <= 0) { - toast({ - variant: 'destructive', - title: 'Invalid Amount', - description: 'Please enter a valid amount', - }); - return; - } - const quote = await coco.quotes.createMintQuote(activeMintUrl, amount); - - // Generate QR code for the Lightning invoice - const qrCodeUrl = await generateQRCode(quote.request); - - // Set the invoice data and show modal - setCurrentInvoice({ - quoteId: quote.quote, - mintUrl: activeMintUrl, - amount, - invoice: quote.request, - qrCodeUrl, - expiry: quote.expiry, - }); - - setShowInvoiceModal(true); - setQuoteAmount(''); - - // Clean up any previous listener - if (mintQuoteUnsubscribeRef.current) { - mintQuoteUnsubscribeRef.current(); - mintQuoteUnsubscribeRef.current = null; - } - - // Listen for payment notification via mint-quote:redeemed event - const quoteId = quote.quote; - const invoiceAmount = amount; - - const unsubscribe = coco.on('mint-quote:redeemed', (payload: unknown) => { - const redeemedQuote = payload as { quoteId?: string }; - - // Check if this is the quote we're waiting for - if (redeemedQuote.quoteId === quoteId) { - toast({ - title: 'Payment Received', - description: `Successfully received ${invoiceAmount} sats! Tokens have been added to your wallet.`, - }); - setShowInvoiceModal(false); - setCurrentInvoice(null); - - // Clean up the event listener - mintQuoteUnsubscribeRef.current = null; - unsubscribe(); - } - }); - - // Store unsubscribe function for cleanup - mintQuoteUnsubscribeRef.current = unsubscribe; - } catch (err) { - toast({ - variant: 'destructive', - title: 'Quote Creation Failed', - description: err instanceof Error ? err.message : 'Unknown error', - }); - } - } - }, [ - coco, - tokenInput, - quoteAmount, - activeMintUrl, - toast, - generateQRCode, - handleUnknownMintError, - ]); - - // Handle send (token or Lightning) - const handleSend = useCallback(async () => { - console.log('[handleSend] Called with state:', { - hasCoco: !!coco, - sendAmount, - lightningInvoice, - lightningAddressInput, - pendingLightningAddress, - pendingBitcoinSwapAddress, - bitcoinSwapAmount, - activeMintUrl, - mode: 'lightning' // We're in Lightning mode when this is called - }); - - if (!coco) { - console.log('[handleSend] No coco instance'); - return; - } - - // Check for reverse swap first (this takes priority in Lightning mode) - if (pendingBitcoinSwapAddress && bitcoinSwapAmount) { - console.log('[handleSend] Reverse swap detected:', { pendingBitcoinSwapAddress, bitcoinSwapAmount }); - // Don't return early - continue to reverse swap logic below - } else if (!sendAmount && !lightningInvoice && !lightningAddressInput && !pendingLightningAddress && !pendingBitcoinSwapAddress) { - console.log('[handleSend] No input provided - returning early'); - return; - } - - // Send Cashu token mode - if (sendAmount && activeMintUrl) { - console.log('[handleSend] Handling token send mode'); - try { - const amount = parseInt(sendAmount); - if (isNaN(amount) || amount <= 0) { - toast({ - variant: 'destructive', - title: 'Invalid Amount', - description: 'Please enter a valid amount', - }); - return; - } - const token = await coco.wallet.send(activeMintUrl, amount); - const encodedToken = getEncodedToken(token); - setSentToken(encodedToken); - await generateSentTokenQRCode(encodedToken); - setSendAmount(''); - } catch (err) { - toast({ - variant: 'destructive', - title: 'Send Failed', - description: err instanceof Error ? err.message : 'Unknown error', - }); - } - } else if (activeMintUrl) { - // Lightning mode - console.log('[handleSend] Entering Lightning mode branch, activeMintUrl:', activeMintUrl); - // Step 1: Check if we have a pending Bitcoin swap address awaiting amount - if (pendingBitcoinSwapAddress) { - console.log('[handleSend] Found pendingBitcoinSwapAddress:', pendingBitcoinSwapAddress); - // Step 2: User entered amount, now initiate reverse swap - if (!bitcoinSwapAmount) { - console.log('[handleSend] Reverse swap pending but no amount provided'); - return; - } - - console.log('[handleSend] Starting reverse swap with:', { - address: pendingBitcoinSwapAddress, - amount: bitcoinSwapAmount, - activeMintUrl - }); - - try { - const amount = parseInt(bitcoinSwapAmount); - if (isNaN(amount) || amount <= 0) { - toast({ - variant: 'destructive', - title: 'Invalid Amount', - description: 'Please enter a valid amount', - }); - return; - } - - // Validate reverse swap amount limits (25,000 - 25,000,000 sats) - if (amount < 25_000 || amount > 25_000_000) { - toast({ - variant: 'destructive', - title: 'Invalid Amount', - description: 'Reverse swap amount must be between 25,000 and 25,000,000 sats', - }); - return; - } - - // Determine destination address (could be Bitcoin address or npub) - let destinationAddress = pendingBitcoinSwapAddress; - try { - // Try to decode as npub first - const decoded = nip19.decode(pendingBitcoinSwapAddress); - if (decoded.type === 'npub') { - destinationAddress = npubToBitcoinAddress(pendingBitcoinSwapAddress); - } - } catch { - // Not an npub, assume it's already a Bitcoin address - } - - // Initiate reverse swap - console.log('[handleSend] Creating reverse swap...'); - setSwapStatus('Creating reverse swap...'); - const swapResult = await createReverseSwap({ - invoiceAmount: amount, - destinationAddress, - onStatusUpdate: (update: SwapStatusUpdate) => { - switch (update.status) { - case 'swap.created': - setSwapStatus('Waiting for invoice payment...'); - break; - case 'transaction.mempool': - setSwapStatus('Swap transaction sent to blockchain...'); - break; - case 'invoice.settled': - case 'transaction.confirmed': - setSwapStatus('Swap completed!'); - break; - } - }, - onSuccess: () => { - const displayAddress = destinationAddress.length > 26 - ? destinationAddress.slice(0, 12) + '...' + destinationAddress.slice(-12) - : destinationAddress; - toast({ - title: 'Reverse Swap Completed', - description: `Successfully swapped ${amount} sats to Bitcoin address ${displayAddress}!`, - }); - setSwapStatus(null); - setPendingBitcoinSwapAddress(null); - setBitcoinSwapAmount(''); - if (reverseSwapClose) { - reverseSwapClose(); - setReverseSwapClose(null); - } - }, - onError: (error: Error) => { - toast({ - variant: 'destructive', - title: 'Reverse Swap Failed', - description: error.message, - }); - setSwapStatus(null); - setPendingBitcoinSwapAddress(null); - setBitcoinSwapAmount(''); - if (reverseSwapClose) { - reverseSwapClose(); - setReverseSwapClose(null); - } - }, - }); - - // Store close function for cleanup - setReverseSwapClose(() => swapResult.close); - - // Pay the Lightning invoice from the swap using the active mint - console.log('[handleSend] Paying Lightning invoice:', swapResult.invoice); - setSwapStatus('Paying Lightning invoice...'); - const meltQuote = await coco.quotes.createMeltQuote( - activeMintUrl, - swapResult.invoice - ); - console.log('[handleSend] Melt quote created, paying...'); - await coco.quotes.payMeltQuote(activeMintUrl, meltQuote.quote); - console.log('[handleSend] Invoice paid successfully'); - - toast({ - title: 'Invoice Paid', - description: `Lightning invoice paid. Swap in progress...`, - }); - } catch (err) { - console.error('Reverse swap error:', err); - toast({ - variant: 'destructive', - title: 'Reverse Swap Failed', - description: err instanceof Error ? err.message : 'Unknown error', - }); - setSwapStatus(null); - setPendingBitcoinSwapAddress(null); - setBitcoinSwapAmount(''); - if (reverseSwapClose) { - reverseSwapClose(); - setReverseSwapClose(null); - } - } - } else if (pendingLightningAddress) { - console.log('[handleSend] Handling Lightning address payment'); - // Step 2: User entered amount, now resolve address and pay - if (!lightningAddressAmount) return; - - try { - const amount = parseInt(lightningAddressAmount); - if (isNaN(amount) || amount <= 0) { - toast({ - variant: 'destructive', - title: 'Invalid Amount', - description: 'Please enter a valid amount', - }); - return; - } - - const invoice = await getLightningInvoice({ - lightningAddress: pendingLightningAddress, - amountSats: amount, - }); - - const meltQuote = await coco.quotes.createMeltQuote( - activeMintUrl, - invoice - ); - await coco.quotes.payMeltQuote(activeMintUrl, meltQuote.quote); - - toast({ - title: 'Payment Sent', - description: `Successfully sent ${amount} sats to ${pendingLightningAddress}!`, - }); - - // Reset state - setPendingLightningAddress(null); - setLightningAddressInput(''); - setLightningAddressAmount(''); - } catch (err) { - console.error('Payment error:', err); - toast({ - variant: 'destructive', - title: 'Payment Failed', - description: err instanceof Error ? err.message : 'Unknown error', - }); - } - } else { - // Step 1: Check if input is a Bitcoin address, Lightning address, or invoice - const input = lightningInvoice.trim() || lightningAddressInput.trim(); - if (!input) return; - - // Check if it's a Bitcoin address (for reverse swap) - if (isValidBitcoinAddress(input)) { - setPendingBitcoinSwapAddress(input); - setLightningInvoice(''); - setLightningAddressInput(''); - return; - } - - // Check if it's an npub (can be converted to Bitcoin address) - try { - const decoded = nip19.decode(input); - if (decoded.type === 'npub') { - const bitcoinAddr = npubToBitcoinAddress(input); - if (bitcoinAddr) { - setPendingBitcoinSwapAddress(input); // Store npub, will convert later - setLightningInvoice(''); - setLightningAddressInput(''); - return; - } - } - } catch { - // Not an npub, continue to check other formats - } - - // Check if it's a Lightning address (contains @) - if (input.includes('@')) { - setPendingLightningAddress(input); - setLightningAddressInput(''); - } else { - // It's a regular Lightning invoice - decode to show amount first - if (isValidBolt11Invoice(input)) { - const amount = decodeBolt11Amount(input); - if (amount) { - // Show amount confirmation screen - setPendingInvoice(input); - setDecodedInvoiceAmount(amount); - setLightningInvoice(''); - return; - } else { - // Failed to decode amount - show error and don't attempt payment - toast({ - variant: 'destructive', - title: 'Invalid Invoice', - description: 'Unable to decode the lightning invoice amount. Please check the invoice format.', - }); - setLightningInvoice(''); - return; - } - } else { - // Not a valid BOLT11 invoice - show error and don't attempt payment - toast({ - variant: 'destructive', - title: 'Invalid Invoice', - description: 'This does not appear to be a valid lightning invoice. Please check the format.', - }); - setLightningInvoice(''); - return; - } - } - } - } - }, [ - coco, - sendAmount, - lightningInvoice, - lightningAddressInput, - lightningAddressAmount, - pendingLightningAddress, - pendingBitcoinSwapAddress, - bitcoinSwapAmount, - activeMintUrl, - toast, - getEncodedToken, - generateSentTokenQRCode, - getLightningInvoice, - reverseSwapClose, - npubToBitcoinAddress, - ]); - - // Handle confirmed invoice payment - const handleConfirmInvoicePayment = useCallback(async () => { - if (!coco || !pendingInvoice || !activeMintUrl) return; - - try { - const meltQuote = await coco.quotes.createMeltQuote( - activeMintUrl, - pendingInvoice - ); - await coco.quotes.payMeltQuote(activeMintUrl, meltQuote.quote); - - toast({ - title: 'Invoice Paid', - description: `Lightning invoice paid successfully for ${decodedInvoiceAmount} sats!`, - }); - - // Reset state - setPendingInvoice(null); - setDecodedInvoiceAmount(null); - } catch (err) { - toast({ - variant: 'destructive', - title: 'Invoice Payment Failed', - description: err instanceof Error ? err.message : 'Unknown error', - }); - } - }, [coco, pendingInvoice, activeMintUrl, decodedInvoiceAmount, toast]); - - // Handle restore from seed phrase - const handleRestoreFromSeedPhrase = useCallback(async (seedPhrase: string, mintUrl: string) => { - if (!coco) { - throw new Error('Wallet not initialized'); - } - - setIsRestoring(true); - - try { - // Clean and validate the seed phrase - const cleanedSeedPhrase = seedPhrase.trim().toLowerCase(); - - // Check if it's a valid mnemonic format - if (!bip39.validateMnemonic(cleanedSeedPhrase, wordlist)) { - // Try to provide more specific error information - const words = cleanedSeedPhrase.split(/\s+/); - if (words.length !== 12) { - throw new Error(`Seed phrase must have exactly 12 words, but found ${words.length} words`); - } - - // Check if all words are valid - const invalidWords = words.filter(word => !wordlist.includes(word)); - if (invalidWords.length > 0) { - throw new Error(`Invalid words found: ${invalidWords.join(', ')}`); - } - - throw new Error('Invalid seed phrase format. Please check that all words are spelled correctly.'); - } - - // Verify this is a different seed from the current wallet - const currentMnemonic = localStorage.getItem('cashu-mnemonic'); - if (currentMnemonic && currentMnemonic.toLowerCase() === cleanedSeedPhrase) { - throw new Error('This is the same seed phrase as your current wallet. Please enter a different seed phrase to restore from.'); - } - - // Convert seed phrase to seed - const restoredSeed = bip39.mnemonicToSeedSync(cleanedSeedPhrase); - - // Get current balance before restore - const balancesBefore = await coco.wallet.getBalances(); - const balanceBefore = balancesBefore[mintUrl] || 0; - - // Create a temporary coco instance with the restored seed to fetch proofs - const tempRepo = new IndexedDbRepositories({ name: `cashu-wallet-restore-${Date.now()}` }); - await tempRepo.init(); - - const tempCoco = await initializeCoco({ - repo: tempRepo, - seedGetter: async () => restoredSeed, - logger: new ConsoleLogger(`restore-${Date.now()}`, { level: "debug" }) - }); - - try { - // Restore the proofs in the temporary wallet - await tempCoco.wallet.restore(mintUrl); - - // Get the restored balance from the temporary wallet - const tempBalances = await tempCoco.wallet.getBalances(); - const restoredAmount = tempBalances[mintUrl] || 0; - - if (restoredAmount <= 0) { - toast({ - title: "No Tokens Found", - description: "No tokens were found for this seed phrase on the selected mint.", - }); - return; - } - - // Send the restored tokens from the temporary wallet - const token = await tempCoco.wallet.send(mintUrl, restoredAmount); - - // Receive the token in the main wallet - await coco.wallet.receive(token); - - // Verify the transfer - const balancesAfter = await coco.wallet.getBalances(); - const balanceAfter = balancesAfter[mintUrl] || 0; - const actualRestored = balanceAfter - balanceBefore; - - toast({ - title: "Restore Successful", - description: `Restored ${actualRestored} sats from the seed phrase and added to your current wallet.`, - }); - } finally { - // Clean up temporary database (optional - happens automatically on next session) - // The temporary IndexedDB will be isolated to the unique name we provided - } - - } catch (error) { - console.error('Restore failed:', error); - throw error; - } finally { - setIsRestoring(false); - } - }, [coco, toast]); - - // Cleanup mint quote listener on component unmount - useEffect(() => { - return () => { - if (mintQuoteUnsubscribeRef.current) { - mintQuoteUnsubscribeRef.current(); - mintQuoteUnsubscribeRef.current = null; - } - }; - }, []); - - // Cleanup reverse swap WebSocket on unmount - useEffect(() => { - return () => { - if (reverseSwapClose) { - reverseSwapClose(); - } - }; - }, [reverseSwapClose]); - - return { - // Receive state - tokenInput, - setTokenInput, - quoteAmount, - setQuoteAmount, - // Send state - sendAmount, - setSendAmount, - lightningInvoice, - setLightningInvoice, - lightningAddressInput, - setLightningAddressInput, - lightningAddressAmount, - setLightningAddressAmount, - pendingLightningAddress, - setPendingLightningAddress, - decodedInvoiceAmount, - setDecodedInvoiceAmount, - pendingInvoice, - setPendingInvoice, - // Reverse swap state - pendingBitcoinSwapAddress, - setPendingBitcoinSwapAddress, - bitcoinSwapAmount, - setBitcoinSwapAmount, - swapStatus, - // Transaction output state - sentToken, - setSentToken, - sentTokenQRCode, - // Invoice modal state - showInvoiceModal, - setShowInvoiceModal, - currentInvoice, - setCurrentInvoice, - // Handlers - handleReceive, - handleSend, - handleConfirmInvoicePayment, - // Restore functionality - handleRestoreFromSeedPhrase, - isRestoring, - // Refs - mintQuoteUnsubscribeRef, - }; -}