Skip to content

Commit

Permalink
Updated inputsWallet & connector
Browse files Browse the repository at this point in the history
  • Loading branch information
nigeon committed Nov 8, 2023
1 parent 9cde35f commit fb4433d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
7 changes: 4 additions & 3 deletions packages/rainbowkit-wallets/src/lib/inputsWallet.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ethers } from 'ethers'
import { createRoot } from 'react-dom/client'
import { CreateWalletModal } from '../components/CreateWalletModal'
import localStorageWallet from './localStorageWallet'
import { WalletClient } from 'viem'
import { WindowProvider } from 'wagmi'

/**
* This class is used to create a wallet from a form
Expand All @@ -10,7 +11,7 @@ export class inputsWallet extends localStorageWallet {
private data: any
private cancel: boolean = false

async create(): Promise<ethers.Wallet> {
async create(provider: WindowProvider): Promise<WalletClient> {
// Create a div to render the modal
const myDiv = document.createElement('div')
myDiv.setAttribute('id', 'myDiv' + Math.random())
Expand All @@ -37,6 +38,6 @@ export class inputsWallet extends localStorageWallet {
throw new Error('User cancelled')
}

return await localStorageWallet.createWallet(JSON.stringify(this.data))
return await localStorageWallet.createWallet(JSON.stringify(this.data), provider)
}
}
9 changes: 5 additions & 4 deletions packages/rainbowkit-wallets/src/wagmi/inputsConnector.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { inputsWallet } from '../lib/inputsWallet'
import { localStorageConnector } from './localStorageConnector'
import { WindowProvider } from '@wagmi/connectors'

const IS_SERVER = typeof window === 'undefined'

Expand All @@ -9,13 +10,13 @@ export class inputsConnector extends localStorageConnector {
readonly name = 'Inputs'

protected async createWallet() {
let wallet = await inputsWallet.getWallet()
const provider = (await this.getProvider()) as WindowProvider
let wallet = await inputsWallet.getWallet(provider)
if (!wallet) {
const w = new inputsWallet()
wallet = await w.create()
wallet = await w.create(provider)
}

wallet.connect(await this.getProvider())
this.wallet = wallet
this.wallet = wallet?.account
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export class localStorageConnector extends InjectedConnector {
}

const account = await this.getAccount()
const provider = await this.getProvider()
const chainId = await this.getChainId()

const cdata: ConnectorData = {
Expand All @@ -41,7 +40,6 @@ export class localStorageConnector extends InjectedConnector {
id: chainId,
unsupported: false,
},
provider: provider as any,
}

return cdata
Expand Down Expand Up @@ -98,7 +96,7 @@ export class localStorageConnector extends InjectedConnector {
onChainChanged = (chainId: string | number): void => {
const id = normalizeChainId(chainId)

const unsupported = Connector.isChainUnsupported(id)
const unsupported = this.isChainUnsupported(id)
this.emit('change', { chain: { id, unsupported } })
}

Expand Down

0 comments on commit fb4433d

Please sign in to comment.