-
Notifications
You must be signed in to change notification settings - Fork 116
Upgrade Stellar Wallet Kits to the latest version #1855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,3 +51,6 @@ mise.toml | |
|
|
||
| # Sentry Config File | ||
| .env.sentry-build-plugin | ||
|
|
||
| # asdf | ||
| .tool-versions | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| nodejs 23.0.0 | ||
| yarn 1.22.22 | ||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
|
|
||
| import { useContext, useEffect, useState } from "react"; | ||
| import { Button, Modal, Text } from "@stellar/design-system"; | ||
| import { ISupportedWallet } from "@creit.tech/stellar-wallets-kit"; | ||
| import { StellarWalletsKit } from "@creit-tech/stellar-wallets-kit/sdk"; | ||
| import { useStore } from "@/store/useStore"; | ||
|
|
||
| import { useAccountInfo } from "@/query/useAccountInfo"; | ||
|
|
@@ -23,7 +23,7 @@ export const ConnectWallet = () => { | |
| const [errorMessageOnConnect, setErrorMessageOnConnect] = useState(""); | ||
| const [hasAttemptedAutoConnect, setHasAttemptedAutoConnect] = | ||
| useState<boolean>(false); | ||
| const walletKitInstance = useContext(WalletKitContext); | ||
| const walletKitContext = useContext(WalletKitContext); | ||
| const savedWallet = localStorageSavedWallet.get(); | ||
|
|
||
| const { data: accountInfo, refetch: fetchAccountInfo } = useAccountInfo({ | ||
|
|
@@ -38,6 +38,7 @@ export const ConnectWallet = () => { | |
| walletType: undefined, | ||
| }); | ||
|
|
||
| StellarWalletsKit.disconnect(); | ||
| setShowModal(false); | ||
| setConnected(false); | ||
| setHasAttemptedAutoConnect(false); | ||
|
|
@@ -52,18 +53,13 @@ export const ConnectWallet = () => { | |
| !hasAttemptedAutoConnect && | ||
| !!savedWallet?.id && | ||
| ![undefined, "false", "wallet_connect"].includes(savedWallet?.id) && | ||
| savedWallet.network.id === network.id | ||
| savedWallet.network.id === network.id && | ||
| walletKitContext.isInitialized | ||
| ) { | ||
| t = setTimeout(async () => { | ||
| if (!walletKitInstance?.walletKit) { | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| walletKitInstance.walletKit?.setWallet(savedWallet.id); | ||
| const success = await handleSetWalletAddress({ | ||
| skipRequestAccess: true, | ||
| }); | ||
| StellarWalletsKit.setWallet(savedWallet.id); | ||
| const success = await handleSetWalletAddress(); | ||
|
|
||
| // Only set the flag if connection failed, so we can retry on successful connections | ||
| if (!success) { | ||
|
|
@@ -83,22 +79,21 @@ export const ConnectWallet = () => { | |
| }; | ||
| // Not including savedWallet.network.id | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, [savedWallet?.id, connected, hasAttemptedAutoConnect, walletKitInstance]); | ||
| }, [ | ||
| savedWallet?.id, | ||
| connected, | ||
| hasAttemptedAutoConnect, | ||
| walletKitContext.isInitialized, | ||
| ]); | ||
|
|
||
| // Reset auto-connect attempt when network changes | ||
| useEffect(() => { | ||
| setHasAttemptedAutoConnect(false); | ||
| }, [network.id]); | ||
|
|
||
| const handleSetWalletAddress = async ({ | ||
| skipRequestAccess, | ||
| }: { | ||
| skipRequestAccess: boolean; | ||
| }): Promise<boolean> => { | ||
| const handleSetWalletAddress = async (): Promise<boolean> => { | ||
| try { | ||
| const addressResult = await walletKitInstance.walletKit?.getAddress({ | ||
| skipRequestAccess, | ||
| }); | ||
| const addressResult = await StellarWalletsKit.getAddress(); | ||
|
|
||
| if (!addressResult?.address) { | ||
| return false; | ||
|
|
@@ -124,38 +119,43 @@ export const ConnectWallet = () => { | |
|
|
||
| const connectWallet = async () => { | ||
| try { | ||
| await walletKitInstance.walletKit?.openModal({ | ||
| onWalletSelected: async (option: ISupportedWallet) => { | ||
| walletKitInstance.walletKit?.setWallet(option.id); | ||
| const isWalletConnected = await handleSetWalletAddress({ | ||
| skipRequestAccess: false, | ||
| }); | ||
|
|
||
| if (!isWalletConnected) { | ||
| const errorMessage = "Unable to load wallet information"; | ||
| setErrorMessageOnConnect(errorMessage); | ||
| disconnect(); | ||
| return; | ||
| } | ||
| const { address } = await StellarWalletsKit.authModal(); | ||
|
|
||
|
Comment on lines
120
to
+123
|
||
| if (!address) { | ||
| const errorMessage = "Unable to load wallet information"; | ||
| setErrorMessageOnConnect(errorMessage); | ||
| disconnect(); | ||
| return; | ||
| } | ||
|
|
||
| localStorageSavedWallet.set({ | ||
| id: option.id, | ||
| network: { | ||
| id: network.id, | ||
| label: network.label, | ||
| }, | ||
| }); | ||
|
|
||
| trackEvent(TrackingEvent.WALLET_KIT_SELECTED, { | ||
| walletType: option.id, | ||
| }); | ||
| }, | ||
| updateWalletKit({ | ||
| publicKey: address, | ||
| walletType: walletKitContext.selectedWalletId, | ||
| }); | ||
| setConnected(true); | ||
|
|
||
| // Use the wallet ID from the kit event (set via WALLET_SELECTED event in context) | ||
| if (walletKitContext.selectedWalletId) { | ||
| localStorageSavedWallet.set({ | ||
| id: walletKitContext.selectedWalletId, | ||
| network: { | ||
| id: network.id, | ||
| label: network.label, | ||
| }, | ||
| }); | ||
|
|
||
| trackEvent(TrackingEvent.WALLET_KIT_SELECTED, { | ||
| walletType: walletKitContext.selectedWalletId, | ||
| }); | ||
| } | ||
|
Comment on lines
+122
to
+150
|
||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| } catch (e) { | ||
| const errorMessage = | ||
| (e as { message?: string })?.message || "Unknown error occurred"; | ||
| setErrorMessageOnConnect(errorMessage); | ||
| // Don't show error if user just closed the modal | ||
| if (errorMessage !== "The user closed the modal.") { | ||
| setErrorMessageOnConnect(errorMessage); | ||
| } | ||
| disconnect(); | ||
| } | ||
| }; | ||
|
|
@@ -199,6 +199,10 @@ export const ConnectWallet = () => { | |
| ); | ||
| }; | ||
|
|
||
| if (!walletKitContext.isInitialized) { | ||
| return; | ||
| } | ||
|
|
||
| return walletKit?.publicKey ? ( | ||
| <> | ||
| <Button | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| "use client"; | ||
|
|
||
| import dynamic from "next/dynamic"; | ||
|
|
||
| // Dynamically import WalletKitContextProvider with SSR disabled | ||
| // This ensures the StellarWalletsKit only loads on the client side | ||
| export const DynamicWalletKitProvider = dynamic( | ||
| () => | ||
| import("@/components/WalletKit/WalletKitContextProvider").then( | ||
| (mod) => mod.WalletKitContextProvider, | ||
| ), | ||
| { | ||
| ssr: false, | ||
| }, | ||
| ); |
Uh oh!
There was an error while loading. Please reload this page.