From f39a93df118729330f3c51b41e3b30f242842cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduard=20Bardaj=C3=AD=20Puig?= Date: Mon, 9 Sep 2024 16:34:29 +0200 Subject: [PATCH 01/10] Add disconnect events --- example/package-lock.json | 2 +- example/src/App.tsx | 13 ++++++++++--- package-lock.json | 36 +++++++++++++++++++++++------------- package.json | 2 +- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/example/package-lock.json b/example/package-lock.json index 1ba6668..16833a7 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -45,7 +45,7 @@ "version": "2.8.0", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.2.2", + "@sats-connect/core": "0.3.0-580becb", "@sats-connect/make-default-provider-config": "0.0.5", "@sats-connect/ui": "0.0.6" }, diff --git a/example/src/App.tsx b/example/src/App.tsx index 4835074..3c9cd7a 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -63,12 +63,19 @@ function AppWithProviders({ children }: React.PropsWithChildren<{}>) { useEffect(() => { if (btcAddressInfo.length < 1) return; - const removeListener = Wallet.addListener('accountChange', (ev) => { + const removeListenerAccountChange = Wallet.addListener('accountChange', (ev) => { console.log('The account has changed.', ev); }); - return removeListener; - }); + const removeListenerDisconnect = Wallet.addListener('disconnect', (ev) => { + console.log('The wallet has disconnected.', ev); + }); + + return () => { + removeListenerAccountChange(); + removeListenerDisconnect(); + }; + }, [btcAddressInfo]); const onConnectLegacy = useCallback(() => { (async () => { diff --git a/package-lock.json b/package-lock.json index e2c5846..9c06093 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.8.0", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.2.2", + "@sats-connect/core": "0.3.0-580becb", "@sats-connect/make-default-provider-config": "0.0.5", "@sats-connect/ui": "0.0.6" }, @@ -1441,12 +1441,12 @@ } }, "node_modules/@noble/hashes": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.4.0.tgz", - "integrity": "sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg==", + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.5.0.tgz", + "integrity": "sha512-1j6kQFb7QRru7eKN3ZDvRcP13rugwdxZqCjbiAVZfIJwgj2A65UmT4TgARXGlXgnRkORLTDTrO19ZErt7+QXgA==", "license": "MIT", "engines": { - "node": ">= 16" + "node": "^14.21.3 || >=16" }, "funding": { "url": "https://paulmillr.com/funding/" @@ -1718,9 +1718,10 @@ ] }, "node_modules/@sats-connect/core": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.2.2.tgz", - "integrity": "sha512-nl3zPnV1UBllYAniDfhM/oSFGQ2qy4cCg1YwxJZ+RQMwlTMrVh2f3lJ//dIIo9RgQPrtHpwrAaaWW0VpfqDQbg==", + "version": "0.3.0-580becb", + "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.3.0-580becb.tgz", + "integrity": "sha512-UICC2rlQbQi+U0Vgt/aF0oZcDD00Uacax4Yc7vapGibtskMVkNy6D2PgE2C1rhwKdRyEGSZY+bvepLX+JcHaiA==", + "license": "ISC", "dependencies": { "axios": "1.7.4", "bitcoin-address-validation": "2.2.3", @@ -1992,12 +1993,14 @@ "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "license": "MIT" }, "node_modules/axios": { "version": "1.7.4", "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.4.tgz", "integrity": "sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==", + "license": "MIT", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -2561,6 +2564,7 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", "dependencies": { "delayed-stream": "~1.0.0" }, @@ -2672,6 +2676,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", "engines": { "node": ">=0.4.0" } @@ -2940,15 +2945,16 @@ } }, "node_modules/follow-redirects": { - "version": "1.15.6", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", - "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", + "version": "1.15.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", "funding": [ { "type": "individual", "url": "https://github.com/sponsors/RubenVerborgh" } ], + "license": "MIT", "engines": { "node": ">=4.0" }, @@ -2990,6 +2996,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "license": "MIT", "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -4626,6 +4633,7 @@ "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", "engines": { "node": ">= 0.6" } @@ -4634,6 +4642,7 @@ "version": "2.1.35", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", "dependencies": { "mime-db": "1.52.0" }, @@ -5110,7 +5119,8 @@ "node_modules/proxy-from-env": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "license": "MIT" }, "node_modules/punycode": { "version": "2.3.1", diff --git a/package.json b/package.json index 570c961..e0b3427 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ ] }, "dependencies": { - "@sats-connect/core": "0.2.2", + "@sats-connect/core": "0.3.0-580becb", "@sats-connect/make-default-provider-config": "0.0.5", "@sats-connect/ui": "0.0.6" }, From 4ecf4c6f3331f09eb5370aca3ca59a95074f7f78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduard=20Bardaj=C3=AD=20Puig?= Date: Mon, 9 Sep 2024 18:16:04 +0200 Subject: [PATCH 02/10] Update example app to handle disconnection events --- example/src/App.tsx | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/example/src/App.tsx b/example/src/App.tsx index 3c9cd7a..0f71dea 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -60,6 +60,19 @@ function AppWithProviders({ children }: React.PropsWithChildren<{}>) { const isConnected = btcAddressInfo.length + stxAddressInfo.length > 0; + const clearAppData = useCallback(() => { + setBtcAddressInfo([]); + setStxAddressInfo([]); + queryClient.clear(); + }, [queryClient, setBtcAddressInfo, setStxAddressInfo]); + + const onDisconnect = useCallback(() => { + (async () => { + await Wallet.disconnect(); + clearAppData(); + })().catch(console.error); + }, [queryClient, setBtcAddressInfo, setStxAddressInfo]); + useEffect(() => { if (btcAddressInfo.length < 1) return; @@ -68,7 +81,8 @@ function AppWithProviders({ children }: React.PropsWithChildren<{}>) { }); const removeListenerDisconnect = Wallet.addListener('disconnect', (ev) => { - console.log('The wallet has disconnected.', ev); + console.log('The wallet has been disconnected. Event:', ev); + clearAppData(); }); return () => { @@ -119,15 +133,6 @@ function AppWithProviders({ children }: React.PropsWithChildren<{}>) { })().catch(console.error); }, [setBtcAddressInfo, setStxAddressInfo]); - const onDisconnect = useCallback(() => { - (async () => { - await Wallet.disconnect(); - setBtcAddressInfo([]); - setStxAddressInfo([]); - queryClient.clear(); - })().catch(console.error); - }, [queryClient, setBtcAddressInfo, setStxAddressInfo]); - const connectionContextValue = useMemo( () => ({ network, btcAddressInfo, stxAddressInfo, onDisconnect }), [network, btcAddressInfo, stxAddressInfo, onDisconnect], From 673359fd33e0ae201d92714f3b7959d1a1c9ddf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduard=20Bardaj=C3=AD=20Puig?= Date: Tue, 10 Sep 2024 13:15:41 +0200 Subject: [PATCH 03/10] wip --- example/package-lock.json | 6 +- example/package.json | 2 +- package-lock.json | 289 +++++--------------------------------- package.json | 2 +- 4 files changed, 39 insertions(+), 260 deletions(-) diff --git a/example/package-lock.json b/example/package-lock.json index 16833a7..60b4fd6 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -1,12 +1,12 @@ { "name": "dapp-cookie-cutter", - "version": "0.1.0", + "version": "0.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "dapp-cookie-cutter", - "version": "0.1.0", + "version": "0.2.0", "dependencies": { "@mantine/core": "^7.11.2", "@mantine/hooks": "^7.11.2", @@ -45,7 +45,7 @@ "version": "2.8.0", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.3.0-580becb", + "@sats-connect/core": "file:../sats-connect-core", "@sats-connect/make-default-provider-config": "0.0.5", "@sats-connect/ui": "0.0.6" }, diff --git a/example/package.json b/example/package.json index a26f996..0ce2de8 100644 --- a/example/package.json +++ b/example/package.json @@ -1,7 +1,7 @@ { "name": "dapp-cookie-cutter", "private": false, - "version": "0.1.0", + "version": "0.2.0", "type": "module", "repository": { "type": "git", diff --git a/package-lock.json b/package-lock.json index 9c06093..247e7e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.8.0", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.3.0-580becb", + "@sats-connect/core": "file:../sats-connect-core", "@sats-connect/make-default-provider-config": "0.0.5", "@sats-connect/ui": "0.0.6" }, @@ -24,6 +24,37 @@ "typescript": "5" } }, + "../sats-connect-core": { + "name": "@sats-connect/core", + "version": "0.2.2", + "license": "ISC", + "dependencies": { + "axios": "1.7.4", + "bitcoin-address-validation": "2.2.3", + "buffer": "6.0.3", + "jsontokens": "4.0.1", + "lodash.omit": "4.5.0", + "valibot": "0.33.2" + }, + "devDependencies": { + "@types/jest": "^29.2.6", + "@types/lodash.omit": "4.5.9", + "husky": "^8.0.3", + "lint-staged": "^13.2.3", + "prettier": "3.3.3", + "process": "^0.11.10", + "rimraf": "^3.0.2", + "stream-browserify": "^3.0.0", + "ts-jest": "^29.0.5", + "ts-loader": "^9.4.1", + "tsup": "^8.0.2", + "typescript": "5.4.5", + "util": "^0.12.4", + "vm-browserify": "^1.1.2", + "webpack": "^5.74.0", + "webpack-cli": "^4.10.0" + } + }, "node_modules/@ampproject/remapping": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", @@ -1440,30 +1471,6 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, - "node_modules/@noble/hashes": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.5.0.tgz", - "integrity": "sha512-1j6kQFb7QRru7eKN3ZDvRcP13rugwdxZqCjbiAVZfIJwgj2A65UmT4TgARXGlXgnRkORLTDTrO19ZErt7+QXgA==", - "license": "MIT", - "engines": { - "node": "^14.21.3 || >=16" - }, - "funding": { - "url": "https://paulmillr.com/funding/" - } - }, - "node_modules/@noble/secp256k1": { - "version": "1.7.1", - "resolved": "https://registry.npmjs.org/@noble/secp256k1/-/secp256k1-1.7.1.tgz", - "integrity": "sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw==", - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ], - "license": "MIT" - }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -1718,18 +1725,8 @@ ] }, "node_modules/@sats-connect/core": { - "version": "0.3.0-580becb", - "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.3.0-580becb.tgz", - "integrity": "sha512-UICC2rlQbQi+U0Vgt/aF0oZcDD00Uacax4Yc7vapGibtskMVkNy6D2PgE2C1rhwKdRyEGSZY+bvepLX+JcHaiA==", - "license": "ISC", - "dependencies": { - "axios": "1.7.4", - "bitcoin-address-validation": "2.2.3", - "buffer": "6.0.3", - "jsontokens": "4.0.1", - "lodash.omit": "4.5.0", - "valibot": "0.33.2" - } + "resolved": "../sats-connect-core", + "link": true }, "node_modules/@sats-connect/make-default-provider-config": { "version": "0.0.5", @@ -1990,23 +1987,6 @@ "node": ">=8" } }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "license": "MIT" - }, - "node_modules/axios": { - "version": "1.7.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.4.tgz", - "integrity": "sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==", - "license": "MIT", - "dependencies": { - "follow-redirects": "^1.15.6", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/babel-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.7.0.tgz", @@ -2126,41 +2106,6 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, - "node_modules/base58-js": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/base58-js/-/base58-js-1.0.5.tgz", - "integrity": "sha512-LkkAPP8Zu+c0SVNRTRVDyMfKVORThX+rCViget00xdgLRrKkClCTz1T7cIrpr69ShwV5XJuuoZvMvJ43yURwkA==", - "license": "MIT", - "engines": { - "node": ">= 8" - } - }, - "node_modules/base64-js": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", - "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT" - }, - "node_modules/bech32": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/bech32/-/bech32-2.0.0.tgz", - "integrity": "sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg==", - "license": "MIT" - }, "node_modules/binary-extensions": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", @@ -2173,17 +2118,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/bitcoin-address-validation": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/bitcoin-address-validation/-/bitcoin-address-validation-2.2.3.tgz", - "integrity": "sha512-1uGCGl26Ye8JG5qcExtFLQfuib6qEZWNDo1ZlLlwp/z7ygUFby3IxolgEfgMGaC+LG9csbVASLcH8fRLv7DIOg==", - "license": "MIT", - "dependencies": { - "base58-js": "^1.0.0", - "bech32": "^2.0.0", - "sha256-uint8array": "^0.10.3" - } - }, "node_modules/bowser": { "version": "2.11.0", "resolved": "https://registry.npmjs.org/bowser/-/bowser-2.11.0.tgz", @@ -2266,30 +2200,6 @@ "node-int64": "^0.4.0" } }, - "node_modules/buffer": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", - "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT", - "dependencies": { - "base64-js": "^1.3.1", - "ieee754": "^1.2.1" - } - }, "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", @@ -2560,18 +2470,6 @@ "integrity": "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==", "dev": true }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "license": "MIT", - "dependencies": { - "delayed-stream": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/commander": { "version": "10.0.1", "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz", @@ -2672,15 +2570,6 @@ "node": ">=0.10.0" } }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "license": "MIT", - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/detect-newline": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-3.1.0.tgz", @@ -2944,26 +2833,6 @@ "node": ">=8" } }, - "node_modules/follow-redirects": { - "version": "1.15.9", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", - "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], - "license": "MIT", - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } - } - }, "node_modules/foreground-child": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", @@ -2992,20 +2861,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "license": "MIT", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -3199,26 +3054,6 @@ "url": "https://github.com/sponsors/typicode" } }, - "node_modules/ieee754": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", - "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "BSD-3-Clause" - }, "node_modules/ignore": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.1.tgz", @@ -4144,17 +3979,6 @@ "node": ">=6" } }, - "node_modules/jsontokens": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/jsontokens/-/jsontokens-4.0.1.tgz", - "integrity": "sha512-+MO415LEN6M+3FGsRz4wU20g7N2JA+2j9d9+pGaNJHviG4L8N0qzavGyENw6fJqsq9CcrHOIL6iWX5yeTZ86+Q==", - "license": "MIT", - "dependencies": { - "@noble/hashes": "^1.1.2", - "@noble/secp256k1": "^1.6.3", - "base64-js": "^1.5.1" - } - }, "node_modules/kleur": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", @@ -4456,12 +4280,6 @@ "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==", "dev": true }, - "node_modules/lodash.omit": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.omit/-/lodash.omit-4.5.0.tgz", - "integrity": "sha512-XeqSp49hNGmlkj2EJlfrQFIzQ6lXdNro9sddtQzcJY8QaoC2GO0DT7xaIokHeyM+mIT0mPMlPvkYzg2xCuHdZg==", - "license": "MIT" - }, "node_modules/lodash.sortby": { "version": "4.7.0", "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", @@ -4629,27 +4447,6 @@ "node": ">=8.6" } }, - "node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "license": "MIT", - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, "node_modules/mimic-fn": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", @@ -5116,12 +4913,6 @@ "node": ">= 6" } }, - "node_modules/proxy-from-env": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", - "license": "MIT" - }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -5368,12 +5159,6 @@ "semver": "bin/semver.js" } }, - "node_modules/sha256-uint8array": { - "version": "0.10.7", - "resolved": "https://registry.npmjs.org/sha256-uint8array/-/sha256-uint8array-0.10.7.tgz", - "integrity": "sha512-1Q6JQU4tX9NqsDGodej6pkrUVQVNapLZnvkwIhddH/JqzBZF1fSaxSWNY6sziXBE8aEa2twtGkXUrwzGeZCMpQ==", - "license": "MIT" - }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", @@ -6045,12 +5830,6 @@ "node": ">=10.12.0" } }, - "node_modules/valibot": { - "version": "0.33.2", - "resolved": "https://registry.npmjs.org/valibot/-/valibot-0.33.2.tgz", - "integrity": "sha512-ZpFWuI+bs5+PP66q4zVFn4e4t/s5jmMw5iPBZmGUoi8iQqXyU9YY/BLCAyk62Z/bNS8qdUNBEyx52952qdqW3w==", - "license": "MIT" - }, "node_modules/walker": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/walker/-/walker-1.0.8.tgz", diff --git a/package.json b/package.json index e0b3427..bef6e16 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ ] }, "dependencies": { - "@sats-connect/core": "0.3.0-580becb", + "@sats-connect/core": "file:../sats-connect-core", "@sats-connect/make-default-provider-config": "0.0.5", "@sats-connect/ui": "0.0.6" }, From 7302d8ae3addd4b7f315ec1a28261c119c9f0171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduard=20Bardaj=C3=AD=20Puig?= Date: Wed, 25 Sep 2024 10:33:35 +0100 Subject: [PATCH 04/10] WIP --- example/src/App.tsx | 2 + .../src/components/wallet/GetPermissions.tsx | 59 +++++++++++++++++++ package-lock.json | 2 +- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 example/src/components/wallet/GetPermissions.tsx diff --git a/example/src/App.tsx b/example/src/App.tsx index 0f71dea..cc03618 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -29,6 +29,7 @@ import { SendSip10 } from './components/stacks/SendSip10'; import { SendStx } from './components/stacks/SendStx'; import { SignTransaction } from './components/stacks/SignTransaction.tsx'; import TransferRunes from './components/transferRunes/index.tsx'; +import { GetPermissions } from './components/wallet/GetPermissions.tsx'; import { WalletType } from './components/wallet/WalletType'; import { useLocalStorage } from './hooks'; import { CollapseDesktop } from './layouts/CollapseDesktop'; @@ -176,6 +177,7 @@ const WalletMethods = () => { /> + ); diff --git a/example/src/components/wallet/GetPermissions.tsx b/example/src/components/wallet/GetPermissions.tsx new file mode 100644 index 0000000..469b006 --- /dev/null +++ b/example/src/components/wallet/GetPermissions.tsx @@ -0,0 +1,59 @@ +import { useQuery } from '@tanstack/react-query'; +import Wallet from 'sats-connect'; +import styled from 'styled-components'; +import { Button, Card } from '../../App.styles'; + +const ErrorMessage = styled.div({ + color: 'red', +}); + +export function GetPermissions() { + const { refetch, error, data, isFetching, isError, isSuccess } = useQuery({ + queryKey: ['wallet_getPermissions'], + queryFn: async () => { + const res = await Wallet.request('wallet_getPermissions', undefined); + if (res.status === 'error') { + throw new Error('Error getting permissions.', { cause: res.error }); + } + return res.result; + }, + enabled: false, + }); + + return ( + +

Get permissions

+ + + + {(() => { + if (isFetching) { + return

Loading...

; + } + + if (isError) { + console.error(error); + console.error(error.cause); + return Error. Check console for details.; + } + + if (isSuccess) { + return ( +
+

Permissions:

+
+                {JSON.stringify(data, null, 2)}
+              
+
+ ); + } + })()} +
+ ); +} diff --git a/package-lock.json b/package-lock.json index 247e7e5..a704281 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,7 @@ }, "../sats-connect-core": { "name": "@sats-connect/core", - "version": "0.2.2", + "version": "0.3.0", "license": "ISC", "dependencies": { "axios": "1.7.4", From d5923e9f2f772f306e964490a968ed1b9526a2e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduard=20Bardaj=C3=AD=20Puig?= Date: Sat, 19 Oct 2024 12:11:27 +0200 Subject: [PATCH 05/10] Use new connect method --- example/package-lock.json | 2 +- example/src/App.tsx | 30 ++++++++++++++++++++++++++---- package-lock.json | 8 ++++---- package.json | 2 +- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/example/package-lock.json b/example/package-lock.json index eb7207f..2cb073d 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -45,7 +45,7 @@ "version": "2.8.3", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.4.0-7a3cb13", + "@sats-connect/core": "0.4.0-a7186b1", "@sats-connect/make-default-provider-config": "0.0.9", "@sats-connect/ui": "0.0.7" }, diff --git a/example/src/App.tsx b/example/src/App.tsx index 0f0c3a4..3545c94 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -97,7 +97,7 @@ function AppWithProviders({ children }: React.PropsWithChildren<{}>) { }; }, [btcAddressInfo]); - const onConnectLegacy = useCallback(() => { + const handleLegacyConnectWithGetAccounts = useCallback(() => { (async () => { const response = await Wallet.request('getAccounts', { purposes: [AddressPurpose.Payment, AddressPurpose.Ordinals, AddressPurpose.Stacks], @@ -110,7 +110,7 @@ function AppWithProviders({ children }: React.PropsWithChildren<{}>) { })().catch(console.error); }, [setBtcAddressInfo, setStxAddressInfo]); - const onConnect = useCallback(() => { + const handleLegacyConnectWithRequestPermissions = useCallback(() => { (async () => { const res = await Wallet.request('wallet_requestPermissions', undefined); if (res.status === 'error') { @@ -139,6 +139,23 @@ function AppWithProviders({ children }: React.PropsWithChildren<{}>) { })().catch(console.error); }, [setBtcAddressInfo, setStxAddressInfo]); + const handleConnect = useCallback(() => { + (async () => { + const res = await Wallet.request('wallet_connect', undefined); + if (res.status === 'error') { + console.error('Error connecting to wallet, details in terminal.'); + console.error(res); + return; + } + const btcAddresses = res.result.addresses.filter((a) => + [AddressPurpose.Ordinals, AddressPurpose.Payment].includes(a.purpose), + ); + setBtcAddressInfo(btcAddresses); + + setStxAddressInfo(res.result.addresses.filter((a) => a.purpose === AddressPurpose.Stacks)); + })().catch(console.error); + }, [setBtcAddressInfo, setStxAddressInfo]); + const connectionContextValue = useMemo( () => ({ network, btcAddressInfo, stxAddressInfo, onDisconnect }), [network, btcAddressInfo, stxAddressInfo, onDisconnect], @@ -152,8 +169,13 @@ function AppWithProviders({ children }: React.PropsWithChildren<{}>) {

Click the button to connect your wallet

- - + + + diff --git a/package-lock.json b/package-lock.json index 4807320..df5a6f3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.8.3", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.4.0-7a3cb13", + "@sats-connect/core": "0.4.0-a7186b1", "@sats-connect/make-default-provider-config": "0.0.9", "@sats-connect/ui": "0.0.7" }, @@ -1833,9 +1833,9 @@ ] }, "node_modules/@sats-connect/core": { - "version": "0.4.0-7a3cb13", - "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.4.0-7a3cb13.tgz", - "integrity": "sha512-RhoqxJdf75zm9dlH4RnpvokVCQzj163+fiZS160sYtxaAGv41m7JH5bW3RZBz2k2PXBFp7cnbFtjKRuD2ZGFjA==", + "version": "0.4.0-a7186b1", + "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.4.0-a7186b1.tgz", + "integrity": "sha512-ssmL7T3cTZb9u+R9o063aecnH/+0VFPge01fTUorcuqiKCQWX8+nUqYgc9RhWNtTVYbGdCvRCHRg8VL53oCiwA==", "license": "ISC", "dependencies": { "@secretkeylabs/xverse-core": "26.0.0-216d0dd", diff --git a/package.json b/package.json index 56cf226..b4575c5 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ ] }, "dependencies": { - "@sats-connect/core": "0.4.0-7a3cb13", + "@sats-connect/core": "0.4.0-a7186b1", "@sats-connect/make-default-provider-config": "0.0.9", "@sats-connect/ui": "0.0.7" }, From 04fbee36682c9d308049be7ecd7ec73d92d15503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduard=20Bardaj=C3=AD=20Puig?= Date: Sat, 19 Oct 2024 16:59:00 +0200 Subject: [PATCH 06/10] wip --- example/.eslintrc.cjs | 2 +- example/package-lock.json | 16 ++- example/package.json | 1 + example/src/App.tsx | 118 +++++++++++++++--- .../src/components/AddressDisplay/index.tsx | 6 +- .../src/components/wallet/GetPermissions.tsx | 9 +- package-lock.json | 8 +- package.json | 2 +- 8 files changed, 134 insertions(+), 28 deletions(-) diff --git a/example/.eslintrc.cjs b/example/.eslintrc.cjs index 62786bc..a44ec22 100644 --- a/example/.eslintrc.cjs +++ b/example/.eslintrc.cjs @@ -18,7 +18,7 @@ module.exports = { project: ['./tsconfig.app.json', './tsconfig.node.json'], tsconfigRootDir: __dirname, }, - plugins: ['react-refresh', 'prettier'], + plugins: ['react-refresh'], rules: { 'react-refresh/only-export-components': ['warn', { allowConstantExport: true }], }, diff --git a/example/package-lock.json b/example/package-lock.json index 2cb073d..c466480 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -29,6 +29,7 @@ "@typescript-eslint/parser": "^7.13.1", "@vitejs/plugin-react": "^4.3.1", "eslint": "^8.57.0", + "eslint-config-prettier": "^9.1.0", "eslint-plugin-react-hooks": "^4.6.2", "eslint-plugin-react-refresh": "^0.4.7", "postcss": "^8.4.40", @@ -45,7 +46,7 @@ "version": "2.8.3", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.4.0-a7186b1", + "@sats-connect/core": "0.4.0-174f886", "@sats-connect/make-default-provider-config": "0.0.9", "@sats-connect/ui": "0.0.7" }, @@ -3231,6 +3232,19 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint-config-prettier": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz", + "integrity": "sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==", + "dev": true, + "license": "MIT", + "bin": { + "eslint-config-prettier": "bin/cli.js" + }, + "peerDependencies": { + "eslint": ">=7.0.0" + } + }, "node_modules/eslint-plugin-react": { "version": "7.34.3", "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.34.3.tgz", diff --git a/example/package.json b/example/package.json index 0ce2de8..efd352d 100644 --- a/example/package.json +++ b/example/package.json @@ -37,6 +37,7 @@ "@typescript-eslint/parser": "^7.13.1", "@vitejs/plugin-react": "^4.3.1", "eslint": "^8.57.0", + "eslint-config-prettier": "^9.1.0", "eslint-plugin-react-hooks": "^4.6.2", "eslint-plugin-react-refresh": "^0.4.7", "postcss": "^8.4.40", diff --git a/example/src/App.tsx b/example/src/App.tsx index 3545c94..6e58f59 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,7 +1,7 @@ import { Container, createTheme, MantineProvider, Stack } from '@mantine/core'; import '@mantine/core/styles.css'; import { QueryClient, QueryClientProvider, useQueryClient } from '@tanstack/react-query'; -import { createContext, useCallback, useContext, useEffect, useMemo } from 'react'; +import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'; import { createBrowserRouter, createRoutesFromElements, @@ -9,8 +9,14 @@ import { Outlet, Route, RouterProvider, + useNavigate, } from 'react-router-dom'; -import Wallet, { AddressPurpose, BitcoinNetworkType, type Address } from 'sats-connect'; +import Wallet, { + AddressPurpose, + BitcoinNetworkType, + RpcErrorCode, + type Address, +} from 'sats-connect'; import { Button, ConnectButtonsContainer, Header, Logo } from './App.styles'; import { GetAccounts } from './components/bitcoin/GetAccounts'; import { GetBtcBalance } from './components/bitcoin/GetBtcBalance'; @@ -36,11 +42,13 @@ import { useLocalStorage } from './hooks'; import { CollapseDesktop } from './layouts/CollapseDesktop'; const ConnectionContext = createContext<{ + accountId: string | null; network: BitcoinNetworkType; btcAddressInfo: Address[]; stxAddressInfo: Address[]; onDisconnect: () => void; }>({ + accountId: null, network: BitcoinNetworkType.Mainnet, btcAddressInfo: [], stxAddressInfo: [], @@ -53,37 +61,66 @@ const useConnectionContext = () => useContext(ConnectionContext); const whiteListedPaths = ['/mobile-universal-link']; -function AppWithProviders({ children }: React.PropsWithChildren<{}>) { +function AppWithProviders({ children }: React.PropsWithChildren) { const queryClient = useQueryClient(); + const navigate = useNavigate(); const [network, setNetwork] = useLocalStorage( 'network', BitcoinNetworkType.Mainnet, ); - const [btcAddressInfo, setBtcAddressInfo] = useLocalStorage('btc-addresses', []); - const [stxAddressInfo, setStxAddressInfo] = useLocalStorage('stx-addresses', []); + const [accountId, setAccountId] = useState(null); + const [btcAddressInfo, setBtcAddressInfo] = useState([]); + const [stxAddressInfo, setStxAddressInfo] = useState([]); + const [isLoading, setIsLoading] = useState(true); const isConnected = btcAddressInfo.length + stxAddressInfo.length > 0; const isWhiteListedPath = whiteListedPaths.includes(window.location.pathname); const clearAppData = useCallback(() => { + setAccountId(null); setBtcAddressInfo([]); setStxAddressInfo([]); queryClient.clear(); - }, [queryClient, setBtcAddressInfo, setStxAddressInfo]); + }, [queryClient, setBtcAddressInfo, setStxAddressInfo, setAccountId]); const onDisconnect = useCallback(() => { (async () => { await Wallet.disconnect(); clearAppData(); })().catch(console.error); - }, [queryClient, setBtcAddressInfo, setStxAddressInfo]); + }, [clearAppData]); useEffect(() => { - if (btcAddressInfo.length < 1) return; - const removeListenerAccountChange = Wallet.addListener('accountChange', (ev) => { console.log('The account has changed.', ev); + + // Attempt to get the new account details. + (async () => { + const res = await Wallet.request('wallet_getAccount', undefined); + + if (res.status === 'error' && res.error.code === (RpcErrorCode.ACCESS_DENIED as number)) { + // The app doesn't have permission to read from this account. Clear + // state and redirect to home page, where the user is prompted to + // connect. + clearAppData(); + navigate('/'); + return; + } + + if (res.status === 'error') { + console.error('Received unexpected error while getting account details.'); + console.error(res); + return; + } + + const btcAddresses = res.result.addresses.filter((a) => + [AddressPurpose.Ordinals, AddressPurpose.Payment].includes(a.purpose), + ); + setBtcAddressInfo(btcAddresses); + setStxAddressInfo(res.result.addresses.filter((a) => a.purpose === AddressPurpose.Stacks)); + setAccountId(res.result.id); + })().catch(console.error); }); const removeListenerDisconnect = Wallet.addListener('disconnect', (ev) => { @@ -95,7 +132,41 @@ function AppWithProviders({ children }: React.PropsWithChildren<{}>) { removeListenerAccountChange(); removeListenerDisconnect(); }; - }, [btcAddressInfo]); + }, [clearAppData, navigate]); + + // On initial load, check if the app has the perms it needs and load necessary + // data. + useEffect(() => { + (async function () { + const res = await Wallet.request('wallet_getAccount', undefined); + + if (res.status === 'error' && res.error.code === (RpcErrorCode.ACCESS_DENIED as number)) { + // The app doesn't have permission to read from this account. Clear + // state and redirect to home page, where the user is prompted to + // connect. + clearAppData(); + navigate('/'); + setIsLoading(false); + return; + } + + if (res.status === 'error') { + console.error('Received unexpected error while getting account details.'); + console.error(res); + setIsLoading(false); + return; + } + + const btcAddresses = res.result.addresses.filter((a) => + [AddressPurpose.Ordinals, AddressPurpose.Payment].includes(a.purpose), + ); + setBtcAddressInfo(btcAddresses); + setStxAddressInfo(res.result.addresses.filter((a) => a.purpose === AddressPurpose.Stacks)); + setAccountId(res.result.id); + + setIsLoading(false); + })().catch(console.error); + }, [clearAppData, navigate]); const handleLegacyConnectWithGetAccounts = useCallback(() => { (async () => { @@ -151,16 +222,18 @@ function AppWithProviders({ children }: React.PropsWithChildren<{}>) { [AddressPurpose.Ordinals, AddressPurpose.Payment].includes(a.purpose), ); setBtcAddressInfo(btcAddresses); - setStxAddressInfo(res.result.addresses.filter((a) => a.purpose === AddressPurpose.Stacks)); + setAccountId(res.result.id); })().catch(console.error); }, [setBtcAddressInfo, setStxAddressInfo]); const connectionContextValue = useMemo( - () => ({ network, btcAddressInfo, stxAddressInfo, onDisconnect }), - [network, btcAddressInfo, stxAddressInfo, onDisconnect], + () => ({ network, btcAddressInfo, stxAddressInfo, onDisconnect, accountId }), + [network, btcAddressInfo, stxAddressInfo, onDisconnect, accountId], ); + if (isLoading) return
Loading...
; + if (!isConnected && !isWhiteListedPath) { return ( @@ -191,13 +264,18 @@ function AppWithProviders({ children }: React.PropsWithChildren<{}>) { // TODO move to pages or routes.tsx const WalletMethods = () => { - const { network, btcAddressInfo, stxAddressInfo, onDisconnect } = useConnectionContext(); + const { network, btcAddressInfo, stxAddressInfo, onDisconnect, accountId } = + useConnectionContext(); + + if (!accountId) return
Error: no account ID set.
; + return ( <>
{ }; const BitcoinMethods = () => { - const { network, btcAddressInfo, onDisconnect } = useConnectionContext(); + const { network, btcAddressInfo, onDisconnect, accountId } = useConnectionContext(); + + if (!accountId) return
Error: no account ID set.
; + return ( <> { }; const StacksMethods = () => { - const { network, stxAddressInfo, onDisconnect } = useConnectionContext(); + const { network, stxAddressInfo, onDisconnect, accountId } = useConnectionContext(); + + if (!accountId) return
Error: no account ID set.
; + return ( <> void; } -export const AddressDisplay = ({ network, addresses, onDisconnect }: Props) => { +export const AddressDisplay = ({ accountId, network, addresses, onDisconnect }: Props) => { return (

Connected Addresses - ({network})

+
+

Account: {accountId}

+
{addresses.map((address) => (

{address.purpose}

diff --git a/example/src/components/wallet/GetPermissions.tsx b/example/src/components/wallet/GetPermissions.tsx index 469b006..d658c83 100644 --- a/example/src/components/wallet/GetPermissions.tsx +++ b/example/src/components/wallet/GetPermissions.tsx @@ -9,27 +9,28 @@ const ErrorMessage = styled.div({ export function GetPermissions() { const { refetch, error, data, isFetching, isError, isSuccess } = useQuery({ - queryKey: ['wallet_getPermissions'], + queryKey: ['wallet_getCurrentPermissions'], queryFn: async () => { - const res = await Wallet.request('wallet_getPermissions', undefined); + const res = await Wallet.request('wallet_getCurrentPermissions', undefined); if (res.status === 'error') { throw new Error('Error getting permissions.', { cause: res.error }); } return res.result; }, + retry: false, enabled: false, }); return ( -

Get permissions

+

Get current permissions

{(() => { diff --git a/package-lock.json b/package-lock.json index df5a6f3..88a43bb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.8.3", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.4.0-a7186b1", + "@sats-connect/core": "0.4.0-174f886", "@sats-connect/make-default-provider-config": "0.0.9", "@sats-connect/ui": "0.0.7" }, @@ -1833,9 +1833,9 @@ ] }, "node_modules/@sats-connect/core": { - "version": "0.4.0-a7186b1", - "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.4.0-a7186b1.tgz", - "integrity": "sha512-ssmL7T3cTZb9u+R9o063aecnH/+0VFPge01fTUorcuqiKCQWX8+nUqYgc9RhWNtTVYbGdCvRCHRg8VL53oCiwA==", + "version": "0.4.0-174f886", + "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.4.0-174f886.tgz", + "integrity": "sha512-Osob1kF3F7sWFcO7DRv9QpUHO1k53eUNcv91z226xEkNkldk9HqxOaJSkN3ZPbPbSRKcDrpXW4Y1ghEwrT19RQ==", "license": "ISC", "dependencies": { "@secretkeylabs/xverse-core": "26.0.0-216d0dd", diff --git a/package.json b/package.json index b4575c5..9584f90 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ ] }, "dependencies": { - "@sats-connect/core": "0.4.0-a7186b1", + "@sats-connect/core": "0.4.0-174f886", "@sats-connect/make-default-provider-config": "0.0.9", "@sats-connect/ui": "0.0.7" }, From f64e94a3cff1fb5d752fdadab5ea990a32b619d9 Mon Sep 17 00:00:00 2001 From: Mahmoud Aboelenein Date: Mon, 28 Oct 2024 10:31:28 +0300 Subject: [PATCH 07/10] update core version --- example/src/App.tsx | 7 +- package-lock.json | 2137 +------------------------------------------ package.json | 2 +- 3 files changed, 47 insertions(+), 2099 deletions(-) diff --git a/example/src/App.tsx b/example/src/App.tsx index 6e58f59..d473b3c 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -212,7 +212,10 @@ function AppWithProviders({ children }: React.PropsWithChildren) { const handleConnect = useCallback(() => { (async () => { - const res = await Wallet.request('wallet_connect', undefined); + const res = await Wallet.request('wallet_connect', { + message: 'Cool app wants to know your addresses!', + addresses: [AddressPurpose.Payment, AddressPurpose.Ordinals, AddressPurpose.Stacks], + }); if (res.status === 'error') { console.error('Error connecting to wallet, details in terminal.'); console.error(res); @@ -244,7 +247,7 @@ function AppWithProviders({ children }: React.PropsWithChildren) {