Skip to content

Commit

Permalink
fix: update method to get a signer from walletconnect provider
Browse files Browse the repository at this point in the history
  • Loading branch information
zaibon committed Mar 15, 2024
1 parent 6ae1d84 commit e907492
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@
"@socket.tech/ll-core-v2": "^0.0.68"
}
}
}
}
25 changes: 11 additions & 14 deletions src/lib/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// import { chains } from '$lib/consts/chains';
import { CHAIN_DETAILS } from '@squirrel-labs/peanut-sdk';
import { createWeb3Modal, defaultConfig } from '@web3modal/ethers5';
import type { Web3Modal } from '@web3modal/ethers5/dist/types/src/client';
import type { ethers } from 'ethers';
import { ethers } from 'ethers';
import { writable } from 'svelte/store';

import type { PeanutChain } from './types';

type Web3Modal = ReturnType<typeof createWeb3Modal>;
export interface OpenOptions {
view: 'Account' | 'Connect' | 'Networks';
}
Expand All @@ -16,10 +15,6 @@ let modal: Web3Modal | null = null;
export const getAccountStores = () => accountStores;

export const accountStores = {
provider: writable<ethers.providers.Web3Provider | undefined>(undefined),
providerType: writable<'walletConnect' | 'injected' | 'coinbaseWallet' | 'eip6963' | undefined>(
undefined
),
address: writable<string | undefined>(undefined),
chainId: writable<number | undefined>(undefined),
isConnected: writable<boolean>(false),
Expand Down Expand Up @@ -55,26 +50,28 @@ export function initWeb3Modal() {
projectId
});

//TODO: unsubribe
//TODO: unsubscribe
modal?.subscribeProvider((newState) => {
accountStores.provider.set(newState.provider);
accountStores.providerType.set(newState.providerType);
accountStores.address.set(newState.address);
accountStores.chainId.set(newState.chainId);
accountStores.isConnected.set(newState.isConnected);
});

//TODO: unsubribe
//TODO: unsubscribe
modal?.subscribeState((newState) => {
modalSateStores.selectedNetworkId.set(newState.selectedNetworkId);
modalSateStores.isOpen.set(newState.open);
});
}

function getSigner(): ethers.providers.JsonRpcSigner | undefined {
if (modal) {
return modal.getSigner();
}
if (!modal) return undefined;
const provider = modal.getWalletProvider();

if (!provider) return undefined;

const p = new ethers.providers.Web3Provider(provider);
return p.getSigner();
}

export async function open(options?: OpenOptions) {
Expand Down

0 comments on commit e907492

Please sign in to comment.