From 6dac95bd489d28faf3bbd415f6c327022de915ee Mon Sep 17 00:00:00 2001 From: Manan Tank Date: Thu, 11 Jan 2024 15:47:52 +0530 Subject: [PATCH] Fix/Improve changesets (#2150) --- .changeset/silent-monkeys-help.md | 52 +++++++++++++++++++++++++ .changeset/tidy-falcons-listen.md | 65 +++++++++++++++++++++++++++---- 2 files changed, 109 insertions(+), 8 deletions(-) create mode 100644 .changeset/silent-monkeys-help.md diff --git a/.changeset/silent-monkeys-help.md b/.changeset/silent-monkeys-help.md new file mode 100644 index 00000000000..674469fb83e --- /dev/null +++ b/.changeset/silent-monkeys-help.md @@ -0,0 +1,52 @@ +--- +"@thirdweb-dev/react-native": minor +--- + +### API changed for creating wallet configurator + +( This is only relevant if you are creating your own wallet configurator - If you are using the wallet configurators provided by thirdweb such as `metamaskWallet()`, `coinbaseWallet()` etc - This API change does not affect you ) + +We have introduce a few changes to how the wallet configurator should be created: + +Do not use any wallet connection hooks in the wallet configurator. Only use the `props` passed in the `connectUI` and `selectUI`. The wallet configurator's `connectUI` and `selectUI` now gets below mentioned additional props so that you can avoid using the wallet connection hooks + +- `props.connect` - replaces the `useConnect` hook usage +- `props.connectionStatus` - replaces the `useConnectionStatus` hook usage +- `props.setConnectionStatus` - replaces the `useSetConnectionStatus` hook usage +- `props.setConnectedWallet` - replaces the `useSetConnectedWallet` hook usage +- `props.createWalletInstance` - replaces the `useCreateWalletInstance` hook usage +- `props.connectedWalletAddress` - replaces the `useAddress` hook usage + +#### Example + +```tsx +import { WalletConfig } from "@thirdweb-dev/react-native"; +import { MyCustomWallet } from "./MyCustomWallet"; // your custom wallet class + +// your custom wallet configurator +function myCustomWallet(): WalletConfig { + return { + id: "MyCustomWallet", + meta: { + name: "FooBar", + iconURL: "https://link-to-the-wallet-icon.png", + }, + create(walletOptions) { + return new MyCustomWallet(walletOptions); + }, + // only use the props passed in the connectUI and selectUI + // do not use any wallet connection hooks that read or write to the wallet connection state + connectUI(props) { + // const connect = useConnect(); -> old + const connect = props.connect; // new + + return
....
; + }, + selectUI(props) { + return
....
; + }, + }; +} +``` + +`onLocallyConnected` has been removed from the `connectUI` props - You no longer need to worry about whether a wallet is part of another wallet's connection flow or not - just use the regular `props` passed in the `connectUI` and `selectUI` and it will be handled automatically. diff --git a/.changeset/tidy-falcons-listen.md b/.changeset/tidy-falcons-listen.md index e8b324aa7e3..98bf6489a71 100644 --- a/.changeset/tidy-falcons-listen.md +++ b/.changeset/tidy-falcons-listen.md @@ -1,17 +1,15 @@ --- -"@thirdweb-dev/react-native": minor "@thirdweb-dev/react-core": minor -"@thirdweb-dev/wallets": patch "@thirdweb-dev/react": minor --- -- Fix double connection issue when Connecting a Safe / Smart Wallet. Now the personal wallet will not be set as the active wallet - only the final wallet will be set as the active wallet. This fixes the issue of hooks like `useWallet`, `useAddress`, `useConnectionStatus` etc showing the wrong wallet / address / connection status for a brief moment when connecting a Safe / Smart Wallet. +### New `ConnectEmbed` component and `useShowConnectEmbed` hook -- Add `ConnectEmbed` component and `useShowConnectEmbed` hook to allow for embedding the ConnectWallet's Modal directly into the page. -- `useShowConnectEmbed` returns `true`` if the ``should be rendered. It returns`true`` if either one of the following conditions are met: +- Add `ConnectEmbed` component and `useShowConnectEmbed` hook allow embedding the `ConnectWallet`'s Modal directly into the page. +- `useShowConnectEmbed` returns `true` if the ``should be rendered. It returns`true` if either one of the following conditions are met: - - the wallet is NOT connected - - the wallet IS connected but the user is NOT signed in and `auth` is required ( loginOptional is NOT set to false ) + - Wallet is NOT connected + - Wallet IS connected but the user is NOT signed in and `auth` is required ( loginOptional is NOT set to false ) ```tsx function Example() { @@ -32,4 +30,55 @@ } ``` -- Show "Disconnect Wallet" option in "Sign in" Screen and don't disconnect wallet instead of disconnecting the wallet when "Sign in" screen is dismissed by closing the modal. This makes this screen reusable for both ConnectWallet and ConnectEmbed components and also improves the user experience. +### `ConnectWallet` component changes + +- Fix double connection issue when Connecting a Safe / Smart Wallet. Now the personal wallet will not be set as the active wallet - only the final wallet will be set as the active wallet. This fixes the issue of hooks like `useWallet`, `useAddress`, `useConnectionStatus` etc showing the wrong wallet / address / connection status for a brief moment when connecting a Safe / Smart Wallet. + +- Add "Disconnect Wallet" button in "Sign in" Screen and don't disconnect wallet when the "Sign in" screen is dismissed by closing the modal. This makes this screen reusable for both `ConnectWallet` and `ConnectEmbed` components and also improves the user experience. + +### API changed for creating wallet configurator + +_This is only relevant if you are creating your own wallet configurator - If you are using the wallet configurators provided by thirdweb such as `metamaskWallet()`, `coinbaseWallet()` etc - This API change does not affect you_ + +To Fix the above mentioned "double connection" issue in the `ConnectWallet` component, We have introduce a few changes to how the wallet configurator should be created. + +Do not use any wallet connection hooks in the wallet configurator. Only use the `props` passed in the `connectUI` and `selectUI`. The wallet configurator's `connectUI` and `selectUI` now gets below mentioned additional props so that you can avoid using the wallet connection hooks + +- `props.connect` - replaces the `useConnect` hook usage +- `props.connectionStatus` - replaces the `useConnectionStatus` hook usage +- `props.setConnectionStatus` - replaces the `useSetConnectionStatus` hook usage +- `props.setConnectedWallet` - replaces the `useSetConnectedWallet` hook usage +- `props.createWalletInstance` - replaces the `useCreateWalletInstance` hook usage +- `props.connectedWalletAddress` - replaces the `useAddress` hook usage + +#### Example + +```tsx +import { WalletConfig } from "@thirdweb-dev/react"; +import { MyCustomWallet } from "./MyCustomWallet"; // your custom wallet class + +// your custom wallet configurator +function myCustomWallet(): WalletConfig { + return { + id: "MyCustomWallet", + meta: { + name: "FooBar", + iconURL: "https://link-to-the-wallet-icon.png", + }, + create(walletOptions) { + return new MyCustomWallet(walletOptions); + }, + // only use the props passed in the connectUI and selectUI + // do not use any wallet connection hooks that read or write to the wallet connection state + connectUI(props) { + // const connect = useConnect(); -> old + const connect = props.connect; // new + + return
....
; + }, + selectUI(props) { + return
....
; + }, + }; +} +```