From 530ac0258601973886b095ed13e2fd5644ce59b1 Mon Sep 17 00:00:00 2001 From: Dmytro Svyrydenko Date: Thu, 7 Dec 2023 15:47:29 +0200 Subject: [PATCH] feat: Reuse hooks and utils - reuse `useSearch` and `useDomainsSuggestions` from `@bonfida/sns-react` - reuse `getDomainPriceFromName` from `@bonfida/spl-name-service` - bump dependencies --- package-lock.json | 209 ++++++++++++++++------- package.json | 11 +- src/components/DomainSearchResultRow.tsx | 4 +- src/hooks/useDomainSuggestions.tsx | 30 ---- src/hooks/useSearch.tsx | 68 -------- src/screens/Cart/index.tsx | 6 +- src/screens/SearchResult.tsx | 12 +- src/utils/price/price-from-length.tsx | 19 --- 8 files changed, 162 insertions(+), 197 deletions(-) delete mode 100644 src/hooks/useDomainSuggestions.tsx delete mode 100644 src/hooks/useSearch.tsx delete mode 100644 src/utils/price/price-from-length.tsx diff --git a/package-lock.json b/package-lock.json index 707c159c..89b273c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,19 +1,19 @@ { "name": "sns-manager", - "version": "1.0.1", + "version": "1.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "sns-manager", - "version": "1.0.1", + "version": "1.0.2", "dependencies": { "@adraffy/ens-normalize": "1.9.0", "@bonfida/name-offers": "0.0.10", "@bonfida/name-tokenizer": "0.0.12", "@bonfida/sns-emitter": "0.1.7", - "@bonfida/sns-react": "2.0.1", - "@bonfida/spl-name-service": "1.0.7", + "@bonfida/sns-react": "2.0.2", + "@bonfida/spl-name-service": "2.0.3", "@coral-xyz/common-public": "0.2.0-latest.3375", "@expo-google-fonts/dev": "*", "@expo/html-elements": "0.5.1", @@ -64,7 +64,6 @@ "react-native-svg": "13.9.0", "react-native-web": "~0.19.6", "recoil": "*", - "split-graphemes": "0.5.0", "twrnc": "*", "use-latest-callback": "0.1.7" }, @@ -2345,12 +2344,12 @@ } }, "node_modules/@bonfida/sns-react": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@bonfida/sns-react/-/sns-react-2.0.1.tgz", - "integrity": "sha512-vo92AuIrVh6RxKAws6I5/pWa7x1udzbRYYsDTP6beNpMCU7sPt2aRO9aRmtCnDb7IriNqLOGU/TvGylRXiOhYQ==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@bonfida/sns-react/-/sns-react-2.0.2.tgz", + "integrity": "sha512-JHWofh9Xq6vftQB/zBt+COr4ck74UzW/F9tJnAnGo8d7GZLqg22w0oc8/yzZnIj/91/QCO3jY21iQatXyDDstg==", "dependencies": { - "@bonfida/spl-name-service": "^1.0.11", - "@solana/web3.js": "^1.73.3", + "@bonfida/spl-name-service": "^1.6.1", + "@solana/web3.js": "^1.87.6", "react-async-hook": "^4.0.0" }, "peerDependencies": { @@ -2359,9 +2358,9 @@ } }, "node_modules/@bonfida/sns-react/node_modules/@bonfida/spl-name-service": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@bonfida/spl-name-service/-/spl-name-service-1.5.0.tgz", - "integrity": "sha512-s+EyQ7fzl9crwEavcd28RCuMyMwAImxjNCECgcADuX67i4P6XLBRBETuxklMYmW4El54JidJ/lBTYchL5Mb/rg==", + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/@bonfida/spl-name-service/-/spl-name-service-1.6.1.tgz", + "integrity": "sha512-AWIPJM6uoofz2tCDRdD8wf1kCzs32yHYmRRQSIzYJ3HuIDufqoilxn8svxsvKRQA2Fm2up6kqnesROp2aoVMCA==", "dependencies": { "@ethersproject/sha2": "^5.7.0", "@pythnetwork/client": "^2.19.0", @@ -2405,31 +2404,22 @@ "text-encoding-utf-8": "^1.0.2" } }, - "node_modules/@bonfida/spl-name-service": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/@bonfida/spl-name-service/-/spl-name-service-1.0.7.tgz", - "integrity": "sha512-awghF0UiBT7SHwE0EGpouoCakQa0EdNEC/87EgkmcaIT/xdDhOifPI2hs+4BDQsyjqxNyWi94qIzp5C+v4/roA==", + "node_modules/@bonfida/sns-records": { + "version": "0.0.1-alpha.8", + "resolved": "https://registry.npmjs.org/@bonfida/sns-records/-/sns-records-0.0.1-alpha.8.tgz", + "integrity": "sha512-y9noqQ28SsqsQUv4XvOUTPK3rlbPjcrcI4Rwphqs3Xp0LW7z+rT6TBRY+i2FVdqhsF4NpLPcWrm1K8coW4+qSA==", "dependencies": { - "@ethersproject/sha2": "^5.7.0", - "@pythnetwork/client": "^2.19.0", - "@solana/buffer-layout": "^4.0.1", - "@solana/spl-token": "0.3.7 ", - "bech32-buffer": "^0.2.1", - "bn.js": "^5.2.1", - "borsh": "^0.7.0", - "buffer": "^6.0.3", - "ipaddr.js": "^2.1.0", - "punycode": "^2.3.0", - "tweetnacl": "^1.0.3" - }, - "peerDependencies": { - "@solana/web3.js": "^1.75.0" + "@solana/spl-token": "0.3.8", + "@solana/web3.js": "1.87.2", + "borsh": "1.0.0", + "bs58": "5.0.0", + "buffer": "^6.0.3" } }, - "node_modules/@bonfida/spl-name-service/node_modules/@solana/spl-token": { - "version": "0.3.7", - "resolved": "https://registry.npmjs.org/@solana/spl-token/-/spl-token-0.3.7.tgz", - "integrity": "sha512-bKGxWTtIw6VDdCBngjtsGlKGLSmiu/8ghSt/IOYJV24BsymRbgq7r12GToeetpxmPaZYLddKwAz7+EwprLfkfg==", + "node_modules/@bonfida/sns-records/node_modules/@solana/spl-token": { + "version": "0.3.8", + "resolved": "https://registry.npmjs.org/@solana/spl-token/-/spl-token-0.3.8.tgz", + "integrity": "sha512-ogwGDcunP9Lkj+9CODOWMiVJEdRtqHAtX2rWF62KxnnSWtMZtV9rDhTrZFshiyJmxDnRL/1nKE1yJHg4jjs3gg==", "dependencies": { "@solana/buffer-layout": "^4.0.0", "@solana/buffer-layout-utils": "^0.2.0", @@ -2442,6 +2432,93 @@ "@solana/web3.js": "^1.47.4" } }, + "node_modules/@bonfida/sns-records/node_modules/@solana/web3.js": { + "version": "1.87.2", + "resolved": "https://registry.npmjs.org/@solana/web3.js/-/web3.js-1.87.2.tgz", + "integrity": "sha512-TZNhS+tvJbYjm0LAvIkUy/3Aqgt2l6/3X6XsVUpvj5MGOl2Q6Ch8hYSxcUUtMbAFNN3sUXmV8NhhMLNJEvI6TA==", + "dependencies": { + "@babel/runtime": "^7.22.6", + "@noble/curves": "^1.2.0", + "@noble/hashes": "^1.3.1", + "@solana/buffer-layout": "^4.0.0", + "agentkeepalive": "^4.3.0", + "bigint-buffer": "^1.1.5", + "bn.js": "^5.2.1", + "borsh": "^0.7.0", + "bs58": "^4.0.1", + "buffer": "6.0.3", + "fast-stable-stringify": "^1.0.0", + "jayson": "^4.1.0", + "node-fetch": "^2.6.12", + "rpc-websockets": "^7.5.1", + "superstruct": "^0.14.2" + } + }, + "node_modules/@bonfida/sns-records/node_modules/@solana/web3.js/node_modules/borsh": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/borsh/-/borsh-0.7.0.tgz", + "integrity": "sha512-CLCsZGIBCFnPtkNnieW/a8wmreDmfUtjU2m9yHrzPXIlNbqVs0AQrSatSG6vdNYUqdc83tkQi2eHfF98ubzQLA==", + "dependencies": { + "bn.js": "^5.2.0", + "bs58": "^4.0.0", + "text-encoding-utf-8": "^1.0.2" + } + }, + "node_modules/@bonfida/sns-records/node_modules/@solana/web3.js/node_modules/bs58": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz", + "integrity": "sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw==", + "dependencies": { + "base-x": "^3.0.2" + } + }, + "node_modules/@bonfida/sns-records/node_modules/borsh": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/borsh/-/borsh-1.0.0.tgz", + "integrity": "sha512-fSVWzzemnyfF89EPwlUNsrS5swF5CrtiN4e+h0/lLf4dz2he4L3ndM20PS9wj7ICSkXJe/TQUHdaPTq15b1mNQ==" + }, + "node_modules/@bonfida/sns-records/node_modules/bs58": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/bs58/-/bs58-5.0.0.tgz", + "integrity": "sha512-r+ihvQJvahgYT50JD05dyJNKlmmSlMoOGwn1lCcEzanPglg7TxYjioQUYehQ9mAR/+hOSd2jRc/Z2y5UxBymvQ==", + "dependencies": { + "base-x": "^4.0.0" + } + }, + "node_modules/@bonfida/sns-records/node_modules/bs58/node_modules/base-x": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-4.0.0.tgz", + "integrity": "sha512-FuwxlW4H5kh37X/oW59pwTzzTKRzfrrQwhmyspRM7swOEZcHtDZSCt45U6oKgtuFE+WYPblePMVIPR4RZrh/hw==" + }, + "node_modules/@bonfida/sns-records/node_modules/superstruct": { + "version": "0.14.2", + "resolved": "https://registry.npmjs.org/superstruct/-/superstruct-0.14.2.tgz", + "integrity": "sha512-nPewA6m9mR3d6k7WkZ8N8zpTWfenFH3q9pA2PkuiZxINr9DKB2+40wEQf0ixn8VaGuJ78AB6iWOtStI+/4FKZQ==" + }, + "node_modules/@bonfida/spl-name-service": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@bonfida/spl-name-service/-/spl-name-service-2.0.3.tgz", + "integrity": "sha512-AXQQ0RrUelblqtoajjMfpPKMDnP1mPPaYmvTn/BeEjOhQwwM9sy7RCHX21D9a2eYlZMA08gYr52TY3y01VQz4w==", + "dependencies": { + "@bonfida/sns-records": "0.0.1-alpha.8", + "@ethersproject/hash": "^5.7.0", + "@ethersproject/sha2": "^5.7.0", + "@pythnetwork/client": "^2.19.0", + "@solana/buffer-layout": "^4.0.1", + "@solana/spl-token": "0.3.9", + "bech32-buffer": "^0.2.1", + "bn.js": "^5.2.1", + "borsh": "^0.7.0", + "buffer": "^6.0.3", + "graphemesplit": "^2.4.4", + "ipaddr.js": "^2.1.0", + "punycode": "^2.3.1", + "tweetnacl": "^1.0.3" + }, + "peerDependencies": { + "@solana/web3.js": "^1.87.3" + } + }, "node_modules/@bonfida/spl-name-service/node_modules/borsh": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/borsh/-/borsh-0.7.0.tgz", @@ -3272,7 +3349,6 @@ "version": "5.7.0", "resolved": "https://registry.npmjs.org/@ethersproject/abstract-provider/-/abstract-provider-5.7.0.tgz", "integrity": "sha512-R41c9UkchKCpAqStMYUpdunjo3pkEvZC3FAwZn5S5MGbXoMQOHIdHItezTETxAO5bevtMApSyEhn9+CHcDsWBw==", - "dev": true, "funding": [ { "type": "individual", @@ -3297,7 +3373,6 @@ "version": "5.7.0", "resolved": "https://registry.npmjs.org/@ethersproject/abstract-signer/-/abstract-signer-5.7.0.tgz", "integrity": "sha512-a16V8bq1/Cz+TGCkE2OPMTOUDLS3grCpdjoJCYNnVBbdYEMSgKrU0+B90s8b6H+ByYTBZN7a3g76jdIJi7UfKQ==", - "dev": true, "funding": [ { "type": "individual", @@ -3320,7 +3395,6 @@ "version": "5.7.0", "resolved": "https://registry.npmjs.org/@ethersproject/address/-/address-5.7.0.tgz", "integrity": "sha512-9wYhYt7aghVGo758POM5nqcOMaE168Q6aRLJZwUmiqSrAungkG74gSSeKEIR7ukixesdRZGPgVqme6vmxs1fkA==", - "dev": true, "funding": [ { "type": "individual", @@ -3343,7 +3417,6 @@ "version": "5.7.0", "resolved": "https://registry.npmjs.org/@ethersproject/base64/-/base64-5.7.0.tgz", "integrity": "sha512-Dr8tcHt2mEbsZr/mwTPIQAf3Ai0Bks/7gTw9dSqk1mQvhW3XvRlmDJr/4n+wg1JmCl16NZue17CDh8xb/vZ0sQ==", - "dev": true, "funding": [ { "type": "individual", @@ -3382,7 +3455,6 @@ "version": "5.7.0", "resolved": "https://registry.npmjs.org/@ethersproject/bignumber/-/bignumber-5.7.0.tgz", "integrity": "sha512-n1CAdIHRWjSucQO3MC1zPSVgV/6dy/fjL9pMrPP9peL+QxEg9wOsVqwD4+818B6LUEtaXzVHQiuivzRoxPxUGw==", - "dev": true, "funding": [ { "type": "individual", @@ -3421,7 +3493,6 @@ "version": "5.7.0", "resolved": "https://registry.npmjs.org/@ethersproject/constants/-/constants-5.7.0.tgz", "integrity": "sha512-DHI+y5dBNvkpYUMiRQyxRBYBefZkJfo70VUkUAsRjcPs47muV9evftfZ0PJVCXYbAiCgght0DtcF9srFQmIgWA==", - "dev": true, "funding": [ { "type": "individual", @@ -3468,7 +3539,6 @@ "version": "5.7.0", "resolved": "https://registry.npmjs.org/@ethersproject/hash/-/hash-5.7.0.tgz", "integrity": "sha512-qX5WrQfnah1EFnO5zJv1v46a8HW0+E5xuBBDTwMFZLuVTx0tbU2kkx15NqdjxecrLGatQN9FGQKpb1FKdHCt+g==", - "dev": true, "funding": [ { "type": "individual", @@ -3556,7 +3626,6 @@ "version": "5.7.0", "resolved": "https://registry.npmjs.org/@ethersproject/keccak256/-/keccak256-5.7.0.tgz", "integrity": "sha512-2UcPboeL/iW+pSg6vZ6ydF8tCnv3Iu/8tUmLLzWWGzxWKFFqOBQFLo6uLUv6BDrLgCDfN28RJ/wtByx+jZ4KBg==", - "dev": true, "funding": [ { "type": "individual", @@ -3591,7 +3660,6 @@ "version": "5.7.1", "resolved": "https://registry.npmjs.org/@ethersproject/networks/-/networks-5.7.1.tgz", "integrity": "sha512-n/MufjFYv3yFcUyfhnXotyDlNdFb7onmkSy8aQERi2PjNcnWQ66xXxa3XlS8nCcA8aJKJjIIMNJTC7tu80GwpQ==", - "dev": true, "funding": [ { "type": "individual", @@ -3630,7 +3698,6 @@ "version": "5.7.0", "resolved": "https://registry.npmjs.org/@ethersproject/properties/-/properties-5.7.0.tgz", "integrity": "sha512-J87jy8suntrAkIZtecpxEPxY//szqr1mlBaYlQ0r4RCaiD2hjheqF9s1LVE8vVuJCXisjIP+JgtK/Do54ej4Sw==", - "dev": true, "funding": [ { "type": "individual", @@ -3728,7 +3795,6 @@ "version": "5.7.0", "resolved": "https://registry.npmjs.org/@ethersproject/rlp/-/rlp-5.7.0.tgz", "integrity": "sha512-rBxzX2vK8mVF7b0Tol44t5Tb8gomOHkj5guL+HhzQ1yBh/ydjGnpw6at+X6Iw0Kp3OzzzkcKp8N9r0W4kYSs9w==", - "dev": true, "funding": [ { "type": "individual", @@ -3768,7 +3834,6 @@ "version": "5.7.0", "resolved": "https://registry.npmjs.org/@ethersproject/signing-key/-/signing-key-5.7.0.tgz", "integrity": "sha512-MZdy2nL3wO0u7gkB4nA/pEf8lu1TlFswPNmy8AiYkfKTdO6eXBJyUdmHO/ehm/htHw9K/qF8ujnTyUAD+Ry54Q==", - "dev": true, "funding": [ { "type": "individual", @@ -3816,7 +3881,6 @@ "version": "5.7.0", "resolved": "https://registry.npmjs.org/@ethersproject/strings/-/strings-5.7.0.tgz", "integrity": "sha512-/9nu+lj0YswRNSH0NXYqrh8775XNyEdUQAuf3f+SmOrnVewcJ5SBNAjF7lpgehKi4abvNNXyf+HX86czCdJ8Mg==", - "dev": true, "funding": [ { "type": "individual", @@ -3837,7 +3901,6 @@ "version": "5.7.0", "resolved": "https://registry.npmjs.org/@ethersproject/transactions/-/transactions-5.7.0.tgz", "integrity": "sha512-kmcNicCp1lp8qanMTC3RIikGgoJ80ztTyvtsFvCYpSCfkjhD0jZ2LOrnbcuxuToLIUYYf+4XwD1rP+B/erDIhQ==", - "dev": true, "funding": [ { "type": "individual", @@ -3918,7 +3981,6 @@ "version": "5.7.1", "resolved": "https://registry.npmjs.org/@ethersproject/web/-/web-5.7.1.tgz", "integrity": "sha512-Gueu8lSvyjBWL4cYsWsjh6MtMwM0+H4HvqFPZfB6dV8ctbP9zFAO73VG1cMWae0FLPCtz0peKPpZY8/ugJJX2w==", - "dev": true, "funding": [ { "type": "individual", @@ -11096,8 +11158,7 @@ "node_modules/brorand": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz", - "integrity": "sha512-cKV8tMCEpQs4hK/ik71d6LrPOnpkpGBR0wzxqr68g2m/LB2GxVYQroAjMJZRVM1Y4BCjCKc3vAamxSzOY2RP+w==", - "dev": true + "integrity": "sha512-cKV8tMCEpQs4hK/ik71d6LrPOnpkpGBR0wzxqr68g2m/LB2GxVYQroAjMJZRVM1Y4BCjCKc3vAamxSzOY2RP+w==" }, "node_modules/browser-resolve": { "version": "2.0.0", @@ -13544,7 +13605,6 @@ "version": "6.5.4", "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz", "integrity": "sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==", - "dev": true, "dependencies": { "bn.js": "^4.11.9", "brorand": "^1.1.0", @@ -13558,8 +13618,7 @@ "node_modules/elliptic/node_modules/bn.js": { "version": "4.12.0", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", - "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==", - "dev": true + "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==" }, "node_modules/emoji-regex": { "version": "8.0.0", @@ -16965,6 +17024,15 @@ "dev": true, "peer": true }, + "node_modules/graphemesplit": { + "version": "2.4.4", + "resolved": "https://registry.npmjs.org/graphemesplit/-/graphemesplit-2.4.4.tgz", + "integrity": "sha512-lKrpp1mk1NH26USxC/Asw4OHbhSQf5XfrWZ+CDv/dFVvd1j17kFgMotdJvOesmHkbFX9P9sBfpH8VogxOWLg8w==", + "dependencies": { + "js-base64": "^3.6.0", + "unicode-trie": "^2.0.0" + } + }, "node_modules/graphql": { "version": "15.8.0", "resolved": "https://registry.npmjs.org/graphql/-/graphql-15.8.0.tgz", @@ -17183,7 +17251,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", "integrity": "sha512-Tti3gMqLdZfhOQY1Mzf/AanLiqh1WTiJgEj26ZuYQ9fbkLomzGchCws4FyrSd4VkpBfiNhaE1On+lOz894jvXg==", - "dev": true, "dependencies": { "hash.js": "^1.0.3", "minimalistic-assert": "^1.0.0", @@ -18881,8 +18948,7 @@ "node_modules/js-sha3": { "version": "0.8.0", "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz", - "integrity": "sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==", - "dev": true + "integrity": "sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==" }, "node_modules/js-sha512": { "version": "0.8.0", @@ -20920,8 +20986,7 @@ "node_modules/minimalistic-crypto-utils": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz", - "integrity": "sha512-JIYlbt6g8i5jKfJ3xz7rF0LXmv2TkDxBLUkiBeZ7bAx4GnnNMr8xFpGnOxn6GhTEHx3SjRrZEoU+j04prX1ktg==", - "dev": true + "integrity": "sha512-JIYlbt6g8i5jKfJ3xz7rF0LXmv2TkDxBLUkiBeZ7bAx4GnnNMr8xFpGnOxn6GhTEHx3SjRrZEoU+j04prX1ktg==" }, "node_modules/minimatch": { "version": "3.1.2", @@ -25471,11 +25536,6 @@ "node": "*" } }, - "node_modules/split-graphemes": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/split-graphemes/-/split-graphemes-0.5.0.tgz", - "integrity": "sha512-TTZ4IPmxuGZOPqhKLHscOeVf568gDP8JE8FxaZU/k30Q3Ra1BRhMv8d9jq1R6A/6T8wSz6ozYn3aJ5skgP6omA==" - }, "node_modules/split-on-first": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/split-on-first/-/split-on-first-1.1.0.tgz", @@ -26492,6 +26552,11 @@ "node": ">=0.6.0" } }, + "node_modules/tiny-inflate": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tiny-inflate/-/tiny-inflate-1.0.3.tgz", + "integrity": "sha512-pkY1fj1cKHb2seWDy0B16HeWyczlJA9/WW3u3c4z/NiWDsO3DOU5D7nhTLE9CF0yXv/QZFY7sEJmj24dK+Rrqw==" + }, "node_modules/tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", @@ -26983,6 +27048,20 @@ "node": ">=4" } }, + "node_modules/unicode-trie": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/unicode-trie/-/unicode-trie-2.0.0.tgz", + "integrity": "sha512-x7bc76x0bm4prf1VLg79uhAzKw8DVboClSN5VxJuQ+LKDOVEW9CdH+VY7SP+vX7xCYQqzzgQpFqz15zeLvAtZQ==", + "dependencies": { + "pako": "^0.2.5", + "tiny-inflate": "^1.0.0" + } + }, + "node_modules/unicode-trie/node_modules/pako": { + "version": "0.2.9", + "resolved": "https://registry.npmjs.org/pako/-/pako-0.2.9.tgz", + "integrity": "sha512-NUcwaKxUxWrZLpDG+z/xZaCgQITkA/Dv4V/T6bw7VON6l1Xz/VnrBqrYjZQ12TamKHzITTfOEIYUj48y2KXImA==" + }, "node_modules/unique-filename": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/unique-filename/-/unique-filename-1.1.1.tgz", diff --git a/package.json b/package.json index 362c707d..2aff763c 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,6 @@ { + "name": "sns-manager", + "version": "1.0.2", "private": true, "homepage": ".", "scripts": { @@ -25,8 +27,8 @@ "@bonfida/name-offers": "0.0.10", "@bonfida/name-tokenizer": "0.0.12", "@bonfida/sns-emitter": "0.1.7", - "@bonfida/sns-react": "2.0.1", - "@bonfida/spl-name-service": "1.0.7", + "@bonfida/sns-react": "2.0.2", + "@bonfida/spl-name-service": "2.0.3", "@coral-xyz/common-public": "0.2.0-latest.3375", "@expo-google-fonts/dev": "*", "@expo/html-elements": "0.5.1", @@ -77,7 +79,6 @@ "react-native-svg": "13.9.0", "react-native-web": "~0.19.6", "recoil": "*", - "split-graphemes": "0.5.0", "twrnc": "*", "use-latest-callback": "0.1.7" }, @@ -105,7 +106,5 @@ "volta": { "node": "20.9.0" }, - "prettier": "@bonfida/prettier-config", - "name": "sns-manager", - "version": "1.0.1" + "prettier": "@bonfida/prettier-config" } diff --git a/src/components/DomainSearchResultRow.tsx b/src/components/DomainSearchResultRow.tsx index 557c21fc..9470b3bd 100644 --- a/src/components/DomainSearchResultRow.tsx +++ b/src/components/DomainSearchResultRow.tsx @@ -7,7 +7,7 @@ import { domainViewScreenProp } from "@src/types"; import { abbreviate } from "@src/utils/abbreviate"; import tw from "@src/utils/tailwind"; import { tokenIconBySymbol } from "@src/utils/tokens/popular-tokens"; -import { priceFromLength } from "@src/utils/price/price-from-length"; +import { getDomainPriceFromName } from "@bonfida/spl-name-service"; import { cartState } from "@src/atoms/cart"; export const DomainSearchResultRow = ({ @@ -21,7 +21,7 @@ export const DomainSearchResultRow = ({ }) => { const [cart, setCart] = useRecoilState(cartState); const inCart = cart.includes(domain); - price = price ?? priceFromLength(domain); + price = price ?? getDomainPriceFromName(domain); const navigation = useNavigation(); const handle = () => { diff --git a/src/hooks/useDomainSuggestions.tsx b/src/hooks/useDomainSuggestions.tsx deleted file mode 100644 index ac3aef38..00000000 --- a/src/hooks/useDomainSuggestions.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import { useAsync } from "react-async-hook"; -import axios from "axios"; -import { generateRandom } from "../utils/suggestions"; -import { getDomainsResult } from "./useSearch"; -import { useSolanaConnection } from "./xnft-hooks"; - -const URL = "https://sns-api.bonfida.com/v2/suggestion/search"; - -export const useDomainSuggestions = (domain: string) => { - const connection = useSolanaConnection(); - const fn = async () => { - if (!domain || domain === "") return; - const { data }: { data: string[] } = await axios.get(`${URL}/${domain}`); - const splitted = domain.split("."); - const isSub = splitted.length === 2; - if (isSub) return []; - if (!data || data.length < 5) { - if (!connection) return []; - const alternatives = generateRandom(domain, 10); - const result = getDomainsResult(connection, alternatives); - return result; - } - // All domains returned by the API are available - return data.map((e) => { - return { domain: e, available: true }; - }); - }; - - return useAsync(fn, [domain, !!connection]); -}; diff --git a/src/hooks/useSearch.tsx b/src/hooks/useSearch.tsx deleted file mode 100644 index 3f646885..00000000 --- a/src/hooks/useSearch.tsx +++ /dev/null @@ -1,68 +0,0 @@ -import { getDomainKeySync } from "@bonfida/spl-name-service"; -import { useSolanaConnection } from "./xnft-hooks"; -import { useAsync } from "react-async-hook"; -import { generateRandom } from "../utils/suggestions"; -import { Connection } from "@solana/web3.js"; - -export interface Result { - domain: string; - available: boolean; -} - -export const getDomainsResult = async ( - connection: Connection, - domains: string[], -): Promise => { - const keys = domains.map((e) => getDomainKeySync(e).pubkey); - const infos = await connection?.getMultipleAccountsInfo(keys); - if (!infos) { - return []; - } - - return domains.map((e, idx) => ({ - domain: e, - available: !infos[idx]?.data, - })); -}; - -export const useSearch = (domain: string) => { - const connection = useSolanaConnection(); - const fn = async (): Promise => { - if (!domain || !connection) return []; - - const splitted = domain.split("."); - const isSub = splitted.length === 2; - - if (isSub) { - const parsedDomain = splitted[1]; - const subdomainKey = getDomainKeySync(domain).pubkey; - const subdomainInfo = await connection?.getAccountInfo(subdomainKey); - - const domainsAlternatives = generateRandom(parsedDomain, 10); - const domainsAlternativesResult = await getDomainsResult( - connection, - domainsAlternatives, - ); - // if the subdomain doesn't exists check if the domain is available - if (!subdomainInfo?.data) { - const domainKey = getDomainKeySync(parsedDomain).pubkey; - const domainInfo = await connection?.getAccountInfo(domainKey); - - return [ - { domain: parsedDomain, available: !domainInfo?.data }, - ...domainsAlternativesResult, - ]; - } else { - return [ - { domain, available: !subdomainInfo.data }, - ...domainsAlternativesResult, - ]; - } - } - - const domains = [domain]; - return getDomainsResult(connection, domains); - }; - - return useAsync(fn, [!!connection, domain]); -}; diff --git a/src/screens/Cart/index.tsx b/src/screens/Cart/index.tsx index 1791c4d0..a93958b9 100644 --- a/src/screens/Cart/index.tsx +++ b/src/screens/Cart/index.tsx @@ -28,7 +28,7 @@ import { cartState } from "@src/atoms/cart"; import { referrerState } from "@src/atoms/referrer"; import tw from "@src/utils/tailwind"; import { FIDA_MINT, tokenList } from "@src/utils/tokens/popular-tokens"; -import { priceFromLength } from "@src/utils/price/price-from-length"; +import { getDomainPriceFromName } from "@bonfida/spl-name-service"; import { wrapSol } from "@src/utils/tokens/wrap-sol"; import { unwrapSol } from "@src/utils/tokens/unwrap-sol"; import { chunkIx } from "@src/utils/tx/chunk-tx"; @@ -94,7 +94,7 @@ export const Cart = () => { const discountMul = mint === FIDA_MINT ? 0.95 : 1; const totalUsd = cart.reduce( - (acc, v) => acc + priceFromLength(v, discountMul), + (acc, v) => acc + getDomainPriceFromName(v) * discountMul, 0, ); @@ -288,7 +288,7 @@ export const Cart = () => { - {priceFromLength(item)} + {getDomainPriceFromName(item)} { + const connection = useSolanaConnection(); const { currentModal } = useModal(); const { setStatus } = useStatusModalContext(); const [search, setSearch] = useState(domain || ""); const [input, setInput] = useState(domain || ""); - const results = useSearch(search); - const suggestions = useDomainSuggestions(search); + const results = useSearch({ connection: connection!, domain: search }); + const suggestions = useDomainSuggestions({ + connection: connection!, + domain: search, + }); const navigation = useNavigation(); const isFocused = useIsFocused(); const topDomainsSales = useTopDomainsSales(loadPopular); diff --git a/src/utils/price/price-from-length.tsx b/src/utils/price/price-from-length.tsx deleted file mode 100644 index 2dc08d8b..00000000 --- a/src/utils/price/price-from-length.tsx +++ /dev/null @@ -1,19 +0,0 @@ -// @ts-ignore -import { splitGraphemes } from "split-graphemes"; - -export const priceFromLength = (name: string, discountMultiplier = 1) => { - const split: string[] = splitGraphemes(name); - const length = split.length; - switch (length) { - case 1: - return 750 * discountMultiplier; - case 2: - return 700 * discountMultiplier; - case 3: - return 640 * discountMultiplier; - case 4: - return 160 * discountMultiplier; - default: - return 20 * discountMultiplier; - } -};