Skip to content

Commit

Permalink
revert using SolanaProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
toddkao committed Feb 28, 2025
1 parent 283ff43 commit 59af2d9
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 41 deletions.
7 changes: 2 additions & 5 deletions packages/widget/src/hooks/useCreateSolanaWallets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useCallback } from "react";
import { ChainType } from "@skip-go/client";
import { callbacksAtom } from "@/state/callbacks";
import { walletConnectLogo } from "@/constants/wagmi";
import { useWallet } from "@solana/wallet-adapter-react";
import { solanaWallets } from "@/constants/solana";

export const useCreateSolanaWallets = () => {
const { data: chains } = useAtomValue(skipChainsAtom);
Expand All @@ -20,13 +20,11 @@ export const useCreateSolanaWallets = () => {
const [svmWallet, setSvmWallet] = useAtom(svmWalletAtom);
const callbacks = useAtomValue(callbacksAtom);
const setWCDeepLinkByChainType = useSetAtom(setWalletConnectDeepLinkByChainTypeAtom);
const { wallets: solanaWallets } = useWallet();

const createSolanaWallets = useCallback(() => {
const wallets: MinimalWallet[] = [];

for (const solWallet of solanaWallets) {
const wallet = solWallet.adapter;
for (const wallet of solanaWallets) {
const isWalletConnect = wallet.name === "WalletConnect";

const connectWallet = async () => {
Expand Down Expand Up @@ -116,7 +114,6 @@ export const useCreateSolanaWallets = () => {
}
return wallets;
}, [
solanaWallets,
chains,
assets,
sourceAsset,
Expand Down
6 changes: 2 additions & 4 deletions packages/widget/src/hooks/useGetAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useCallback } from "react";
import { useAccount as useEvmAccount, useConnectors } from "wagmi";
import { ChainType } from "@skip-go/client";
import { walletConnectLogo } from "@/constants/wagmi";
import { useWallet } from "@solana/wallet-adapter-react";
import { solanaWallets } from "@/constants/solana";

export const useGetAccount = () => {
const wallet = useAtomValue(walletsAtom);
Expand All @@ -20,9 +20,7 @@ export const useGetAccount = () => {
multiChain: true,
});

const { wallets: solanaWallets } = useWallet();

const solanaWallet = solanaWallets.find((wallet) => wallet.adapter.connected === true)?.adapter;
const solanaWallet = solanaWallets.find((wallet) => wallet.connected === true);

const evmAccount = useEvmAccount();
const connectors = useConnectors();
Expand Down
11 changes: 2 additions & 9 deletions packages/widget/src/hooks/useKeepWalletStateSynced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { useAtom, useSetAtom } from "jotai";
import { useCallback, useEffect } from "react";
import { useAccount as useEvmAccount } from "wagmi";
import { ChainType } from "@skip-go/client";
import { useWallet } from "@solana/wallet-adapter-react";
import { solanaWalletsAtom } from "@/state/skipClient";
import { solanaWallets } from "@/constants/solana";

export const useKeepWalletStateSynced = () => {
const [evmWallet, setEvmWallet] = useAtom(evmWalletAtom);
Expand All @@ -21,9 +21,7 @@ export const useKeepWalletStateSynced = () => {
? cosmosAccounts[Object.keys(cosmosAccounts)[0]]?.bech32Address
: "";

const { wallets: solanaWallets } = useWallet();

const solanaWallet = solanaWallets.find((wallet) => wallet.adapter.connected === true)?.adapter;
const solanaWallet = solanaWallets.find((wallet) => wallet.connected === true);

const evmAccount = useEvmAccount();

Expand Down Expand Up @@ -66,10 +64,6 @@ export const useKeepWalletStateSynced = () => {
}
}, [setSvmWallet, solanaWallet]);

useEffect(() => {
setSolanaWallets(solanaWallets);
}, [setSolanaWallets, solanaWallets]);

useEffect(() => {
const currentEvmId = evmAccount.address;
const currentSolanaId = solanaWallet?.publicKey?.toBase58();
Expand Down Expand Up @@ -99,7 +93,6 @@ export const useKeepWalletStateSynced = () => {
evmAccount.address,
updateCosmosWallet,
currentCosmosId,
solanaWallets,
setSolanaWallets,
]);
};
13 changes: 0 additions & 13 deletions packages/widget/src/providers/SolanaProvider.tsx

This file was deleted.

5 changes: 1 addition & 4 deletions packages/widget/src/providers/WalletProviders.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { ReactNode } from "react";
import { CosmosProvider } from "./CosmosProvider";
import { EVMProvider } from "./EVMProvider";
import { SolanaProvider } from "./SolanaProvider";

export const WalletProviders = ({ children }: { children: ReactNode }) => {
return (
<CosmosProvider>
<SolanaProvider>
<EVMProvider>{children}</EVMProvider>
</SolanaProvider>
<EVMProvider>{children}</EVMProvider>
</CosmosProvider>
);
};
8 changes: 2 additions & 6 deletions packages/widget/src/state/skipClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getWalletClient } from "@wagmi/core";
import { config } from "@/constants/wagmi";
import { WalletClient } from "viem";
import { defaultTheme, Theme } from "@/widget/theme";
import { Wallet } from "@solana/wallet-adapter-react";
import { solanaWallets } from "@/constants/solana";

type ArgumentTypes<F extends Function> = F extends (...args: infer A) => unknown ? A : never;

Expand All @@ -25,15 +25,11 @@ export const skipClientConfigAtom = atom<SkipClientOptions>({

export const themeAtom = atom<Theme>(defaultTheme);

export const solanaWalletsAtom = atom<Wallet[]>();

export const skipClient = atom((get) => {
const options = get(skipClientConfigAtom);
const wallets = get(walletsAtom);
const getSigners = get(getConnectedSignersAtom);

const solanaWallets = get(solanaWalletsAtom);

return new SkipClient({
...options,
getCosmosSigner: async (chainID) => {
Expand Down Expand Up @@ -69,7 +65,7 @@ export const skipClient = atom((get) => {
}
const walletName = wallets.svm?.walletName;
if (!walletName) throw new Error("getSVMSigner error: no svm wallet");
const solanaWallet = solanaWallets?.find((w) => w.adapter.name === walletName)?.adapter;
const solanaWallet = solanaWallets.find((w) => w.name === walletName);
if (!solanaWallet) throw new Error("getSVMSigner error: wallet not found");
return solanaWallet as ArgumentTypes<typeof SkipClient>["getSVMSigner"];
},
Expand Down

0 comments on commit 59af2d9

Please sign in to comment.