From a42371e63514fc7cf29ac1746fb41ac8d9c54e0e Mon Sep 17 00:00:00 2001 From: Andrei Date: Fri, 6 Sep 2024 13:04:16 +0300 Subject: [PATCH 1/3] add create account for passkey wallets --- package.json | 2 +- src/hooks/login/usePasskeyLogin.ts | 22 ++++++++--- yarn.lock | 63 +++++++++++++++--------------- 3 files changed, 49 insertions(+), 38 deletions(-) diff --git a/package.json b/package.json index ad73bd659..1dba05dd5 100644 --- a/package.json +++ b/package.json @@ -163,7 +163,7 @@ "@multiversx/sdk-metamask-provider": "0.0.5", "@multiversx/sdk-native-auth-client": "1.0.7", "@multiversx/sdk-opera-provider": "1.0.0-alpha.1", - "@multiversx/sdk-passkey-provider": "1.0.2", + "@multiversx/sdk-passkey-provider": "1.0.3", "@multiversx/sdk-wallet": "4.2.0", "@multiversx/sdk-wallet-connect-provider": "4.1.3", "@multiversx/sdk-web-wallet-cross-window-provider": "1.0.0", diff --git a/src/hooks/login/usePasskeyLogin.ts b/src/hooks/login/usePasskeyLogin.ts index 62b503fb4..58edc1eaa 100644 --- a/src/hooks/login/usePasskeyLogin.ts +++ b/src/hooks/login/usePasskeyLogin.ts @@ -17,8 +17,13 @@ import { getDefaultCallbackUrl } from 'utils/window'; import { clearInitiatedLogins } from './helpers'; import { useLoginService } from './useLoginService'; +type CreateAccountFunctionType = ( + walletName: string +) => Promise<{ address: string }>; + export type UsePasskeyLoginReturnType = [ InitiateLoginFunctionType, + CreateAccountFunctionType, LoginHookGenericStateType ]; @@ -37,7 +42,7 @@ export const usePasskeyLogin = ({ const dispatch = useDispatch(); const isLoggedIn = getIsLoggedIn(); - async function initiateLogin(newWalletName?: string) { + async function initiateLogin() { if (isLoggedIn) { throw new Error(SECOND_LOGIN_ATTEMPT_ERROR); } @@ -81,11 +86,7 @@ export const usePasskeyLogin = ({ ...(token && { token }) }; - if (newWalletName) { - await provider.createAccount({ walletName: newWalletName, token }); - } else { - await provider.login(providerLoginData); - } + await provider.login(providerLoginData); setAccountProvider(provider); @@ -121,10 +122,19 @@ export const usePasskeyLogin = ({ } } + const createAccount = async (walletName: string) => { + const provider: PasskeyProvider = PasskeyProvider.getInstance(); + await provider.init(); + return await provider.createAccount({ + walletName + }); + }; + const loginFailed = Boolean(error); return [ initiateLogin, + createAccount, { loginFailed, error, diff --git a/yarn.lock b/yarn.lock index 0a5bbea64..3fbc10825 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2412,12 +2412,13 @@ resolved "https://registry.yarnpkg.com/@multiversx/sdk-opera-provider/-/sdk-opera-provider-1.0.0-alpha.1.tgz#2beebd5423fdc2e667b33660f17cbff325449097" integrity sha512-5hrqn+kNpuy/S6eV5wh5mE4lvQo0PduZ7fLsh/2Srcaz3K5kM5lE1VyQmWk4DTxToZSldrGbgWz/olezoC6fPg== -"@multiversx/sdk-passkey-provider@1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@multiversx/sdk-passkey-provider/-/sdk-passkey-provider-1.0.2.tgz#aa67e8c29654f9e4dd6a705935f8d201f1dc9ad1" - integrity sha512-+gngXlSsBwK/i7YJPjWtL0PfPW9PcgxV2EcBMydcVnvSji0dsGb9QvcZr/PfVLS8w/ezriH1uoPlmj85SXrI8A== +"@multiversx/sdk-passkey-provider@1.0.3": + version "1.0.3" + resolved "https://registry.yarnpkg.com/@multiversx/sdk-passkey-provider/-/sdk-passkey-provider-1.0.3.tgz#4f5ce07be6e36fee4b930a61e35cf4bef4a96798" + integrity sha512-1ggb0Nixwo/d2XTESWlM8oVVHu6c7qSInwBaAzqPa+T8X5k/VKM9QnMDK84A1oC6ZjEF5+uFV8epYuxmqgNNgw== dependencies: "@types/jest" "^29.5.11" + short-unique-id "^5.2.0" "@multiversx/sdk-transaction-decoder@1.0.2": version "1.0.2" @@ -6912,9 +6913,9 @@ can-bind-to-host@^1.1.1: integrity sha512-CqsgmaqiyFRNtP17Ihqa/uHbZxRirntNVNl/kJz31DLKuNRfzvzionkLoUSkElQ6Cz+cpXKA3mhHq4tjbieujA== caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001646: - version "1.0.30001657" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001657.tgz#29fd504bffca719d1c6b63a1f6f840be1973a660" - integrity sha512-DPbJAlP8/BAXy3IgiWmZKItubb3TYGP0WscQQlVGIfT4s/YlFYVuJgyOsQNP7rJRChx/qdMeLJQJP0Sgg2yjNA== + version "1.0.30001658" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001658.tgz#b5f7be8ac748a049ab06aa1cf7a1408d83f074ec" + integrity sha512-N2YVqWbJELVdrnsW5p+apoQyYt51aBMSsBZki1XZEfeBCexcM/sf4xiAHcXQBkuOwJBXtWF7aW1sYX6tKebPHw== capture-exit@^2.0.0: version "2.0.0" @@ -7744,11 +7745,11 @@ debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.9: ms "2.0.0" debug@4, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2, debug@^4.3.3, debug@^4.3.4, debug@^4.3.5, debug@~4.3.1, debug@~4.3.2: - version "4.3.6" - resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.6.tgz#2ab2c38fbaffebf8aa95fdfe6d88438c7a13c52b" - integrity sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg== + version "4.3.7" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.7.tgz#87945b4151a011d76d95a198d7111c865c360a52" + integrity sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ== dependencies: - ms "2.1.2" + ms "^2.1.3" debug@^3.0.0, debug@^3.2.7: version "3.2.7" @@ -8199,9 +8200,9 @@ ee-first@1.1.1: integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow== electron-to-chromium@^1.5.4: - version "1.5.14" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.14.tgz#8de5fd941f4deede999f90503c4b5923fbe1962b" - integrity sha512-bEfPECb3fJ15eaDnu9LEJ2vPGD6W1vt7vZleSVyFhYuMIKm3vz/g9lt7IvEzgdwj58RjbPKUF2rXTCN/UW47tQ== + version "1.5.16" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.16.tgz#125b6777774dbd4287aa86ab181cc880f4a5fb47" + integrity sha512-2gQpi2WYobXmz2q23FrOBYTLcI1O/P4heW3eqX+ldmPVDQELRqhiebV380EhlGG12NtnX1qbK/FHpN0ba+7bLA== element-resize-detector@^1.2.2: version "1.2.4" @@ -8846,9 +8847,9 @@ eslint-import-resolver-typescript@2.4.0: tsconfig-paths "^3.9.0" eslint-module-utils@^2.7.3: - version "2.9.0" - resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.9.0.tgz#95d4ac038a68cd3f63482659dffe0883900eb342" - integrity sha512-McVbYmwA3NEKwRQY5g4aWMdcZE5xZxV8i8l7CqJSrameuGSQJtSWaL/LxTEzSKKaCcOhlpDR8XEfYXWPrdo/ZQ== + version "2.11.0" + resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.11.0.tgz#b99b211ca4318243f09661fae088f373ad5243c4" + integrity sha512-gbBE5Hitek/oG6MUVj6sFuzEjA/ClzNflVrLovHi/JgLdC7fiN5gLAY1WIPW1a0V5I999MnsrvVrCOGmmVqDBQ== dependencies: debug "^3.2.7" @@ -12984,12 +12985,7 @@ ms@2.1.1: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a" integrity sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg== -ms@2.1.2: - version "2.1.2" - resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" - integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== - -ms@2.1.3, ms@^2.1.1: +ms@2.1.3, ms@^2.1.1, ms@^2.1.3: version "2.1.3" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== @@ -13985,17 +13981,17 @@ platform@1.3.6: resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.6.tgz#48b4ce983164b209c2d45a107adb31f473a6e7a7" integrity sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg== -playwright-core@1.46.1, playwright-core@>=1.2.0: - version "1.46.1" - resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.46.1.tgz#28f3ab35312135dda75b0c92a3e5c0e7edb9cc8b" - integrity sha512-h9LqIQaAv+CYvWzsZ+h3RsrqCStkBHlgo6/TJlFst3cOTlLghBQlJwPOZKQJTKNaD3QIB7aAVQ+gfWbN3NXB7A== +playwright-core@1.47.0, playwright-core@>=1.2.0: + version "1.47.0" + resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.47.0.tgz#b54ec060fd83e5c2e46b63986b5ebb5e96ace427" + integrity sha512-1DyHT8OqkcfCkYUD9zzUTfg7EfTd+6a8MkD/NWOvjo0u/SCNd5YmY/lJwFvUZOxJbWNds+ei7ic2+R/cRz/PDg== playwright@^1.14.0: - version "1.46.1" - resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.46.1.tgz#ea562bc48373648e10420a10c16842f0b227c218" - integrity sha512-oPcr1yqoXLCkgKtD5eNUPLiN40rYEM39odNpIb6VE6S7/15gJmA1NzVv6zJYusV0e7tzvkU/utBFNa/Kpxmwng== + version "1.47.0" + resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.47.0.tgz#fb9b028883fad11362f9ff63ce7ba44bda0bf626" + integrity sha512-jOWiRq2pdNAX/mwLiwFYnPHpEZ4rM+fRSQpRHwEwZlP2PUANvL3+aJOF/bvISMhFD30rqMxUB4RJx9aQbfh4Ww== dependencies: - playwright-core "1.46.1" + playwright-core "1.47.0" optionalDependencies: fsevents "2.3.2" @@ -15466,6 +15462,11 @@ shelljs@^0.8.5: interpret "^1.0.0" rechoir "^0.6.2" +short-unique-id@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/short-unique-id/-/short-unique-id-5.2.0.tgz#a7e0668e0a8998d3151f27a36cf046055b1f270b" + integrity sha512-cMGfwNyfDZ/nzJ2k2M+ClthBIh//GlZl1JEf47Uoa9XR11bz8Pa2T2wQO4bVrRdH48LrIDWJahQziKo3MjhsWg== + shx@0.3.4: version "0.3.4" resolved "https://registry.yarnpkg.com/shx/-/shx-0.3.4.tgz#74289230b4b663979167f94e1935901406e40f02" From 512b5bb0d8432b745cf0d780294ba01c085fd4f3 Mon Sep 17 00:00:00 2001 From: Andrei Date: Fri, 6 Sep 2024 13:06:03 +0300 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62e4d5bc0..92d066be8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- [Added create wallet feature for passkey provider](https://github.com/multiversx/mx-sdk-dapp/pull/1258) + ## [[v2.40.1]](https://github.com/multiversx/mx-sdk-dapp/pull/1255)] - 2024-09-05 - [Added create wallet feature for passkey provider](https://github.com/multiversx/mx-sdk-dapp/pull/1254) diff --git a/package.json b/package.json index 1dba05dd5..d5c9f0781 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-dapp", - "version": "2.40.1", + "version": "2.40.2", "description": "A library to hold the main logic for a dapp on the MultiversX blockchain", "author": "MultiversX", "license": "GPL-3.0-or-later", From b2565aa71d48df578b5cb2da5aa23a453369817c Mon Sep 17 00:00:00 2001 From: Andrei Date: Fri, 6 Sep 2024 13:14:59 +0300 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92d066be8..56b6479fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -- [Added create wallet feature for passkey provider](https://github.com/multiversx/mx-sdk-dapp/pull/1258) +- [Added create wallet feature for passkey provider without auto login](https://github.com/multiversx/mx-sdk-dapp/pull/1258) ## [[v2.40.1]](https://github.com/multiversx/mx-sdk-dapp/pull/1255)] - 2024-09-05 - [Added create wallet feature for passkey provider](https://github.com/multiversx/mx-sdk-dapp/pull/1254)