saepenatus
Version:
Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, mul
40 lines (31 loc) • 1.03 kB
text/typescript
import { getBNMulitChainSdk } from './services.js'
import { state } from './store/index.js'
import { removeWallet } from './store/actions.js'
import { disconnectWallet$ } from './streams.js'
import type { DisconnectOptions, WalletState } from './types.js'
import { validateDisconnectOptions } from './validation.js'
async function disconnect(options: DisconnectOptions): Promise<WalletState[]> {
const error = validateDisconnectOptions(options)
if (error) {
throw error
}
const { label } = options
if (state.get().notify.enabled) {
// handle unwatching addresses
const sdk = await getBNMulitChainSdk()
if (sdk) {
const wallet = state.get().wallets.find(wallet => wallet.label === label)
wallet.accounts.forEach(({ address }) => {
sdk.unsubscribe({
id: address,
chainId: wallet.chains[0].id,
timeout: 60000
})
})
}
}
disconnectWallet$.next(label)
removeWallet(label)
return state.get().wallets
}
export default disconnect