Skip to content

Commit

Permalink
Removed address type from solana utils and client
Browse files Browse the repository at this point in the history
  • Loading branch information
gooxpf committed Feb 28, 2024
1 parent 5b3731d commit 81f8e1c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
2 changes: 0 additions & 2 deletions packages/scaffold-utils/src/SolanaTypesUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ export interface ISolConfig {
SSR?: boolean
}

export type Address = `0x${string}`

export type ProviderType = {
injected?: Provider
coinbase?: Provider
Expand Down
22 changes: 10 additions & 12 deletions packages/solana/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import type {
ProviderType,
Chain,
Provider,
Address,
SolStoreUtilState
} from '@web3modal/scaffold-utils/solana'
import type { Web3ModalSIWEClient } from '@web3modal/siwe'
Expand Down Expand Up @@ -116,15 +115,15 @@ export class Web3Modal extends Web3ModalScaffold {
onUri(uri)
})
const address = await this.WalletConnectConnector.connect()
this.setWalletConnectProvider(address as Address)
this.setWalletConnectProvider(address)
},

connectExternal: async ({ id }) => {
const adapter = id.toLocaleLowerCase() === 'Trust' ? 'trustWallet' : id.toLocaleLowerCase() as AdapterKey

await this.walletAdapters[adapter].connect()
const address = this.walletAdapters[adapter].publicKey?.toString() as Address
this.setInjectedProvider(this.walletAdapters[adapter] as unknown as Provider, address, adapter)
const address = this.walletAdapters[adapter].publicKey?.toString()
this.setInjectedProvider(this.walletAdapters[adapter] as unknown as Provider, adapter, address)
},

checkInstalled(ids) {
Expand Down Expand Up @@ -167,7 +166,7 @@ export class Web3Modal extends Web3ModalScaffold {
params: [message, this.getAddress()]
})

return signature as `0x${string}`
return signature as string
}
}

Expand Down Expand Up @@ -235,7 +234,7 @@ export class Web3Modal extends Web3ModalScaffold {
public getAddress() {
const { address } = SolStoreUtil.state

return address ? (SolStoreUtil.state.address as Address) : address
return address ? (SolStoreUtil.state.address) : address
}

public async checkActiveProviders() {
Expand All @@ -246,14 +245,14 @@ export class Web3Modal extends Web3ModalScaffold {
await this.WalletConnectConnector.connect(true)
const provider = await this.WalletConnectConnector.getProvider();
const accounts = await provider.enable();
this.setWalletConnectProvider(accounts[0] as Address)
this.setWalletConnectProvider(accounts[0])
} else {
const wallet = walletId?.split('_')[1] as AdapterKey
const adapter = this.walletAdapters[wallet]
if (window[wallet as keyof Window]) {
await adapter.connect()
const address = adapter.publicKey?.toString() as Address
this.setInjectedProvider(adapter as unknown as Provider, address, wallet)
const address = adapter.publicKey?.toString()
this.setInjectedProvider(adapter as unknown as Provider, wallet, address)
}
}
} catch (error) {
Expand Down Expand Up @@ -408,7 +407,7 @@ export class Web3Modal extends Web3ModalScaffold {
return SolStoreUtil.subscribe(callback)
}

private async setWalletConnectProvider(address: string) {
private async setWalletConnectProvider(address = "") {
const caipChainId = `${SolStoreUtil.state.currentChain?.name}: ${SolStoreUtil.state.currentChain?.chainId}`
const chain = SolHelpersUtil.getChainFromCaip(this.chains, typeof window === 'object' ? localStorage.getItem(SolConstantsUtil.CAIP_CHAIN_ID) : '');
if (chain) {
Expand All @@ -432,7 +431,7 @@ export class Web3Modal extends Web3ModalScaffold {
])
}

private setInjectedProvider(provider: Provider, address: Address, adapter: AdapterKey) {
private setInjectedProvider(provider: Provider, adapter: AdapterKey, address = "") {
window?.localStorage.setItem(SolConstantsUtil.WALLET_ID, `${ConstantsUtil.INJECTED_CONNECTOR_ID}_${adapter}`)

const chainId = SolStoreUtil.state.currentChain?.chainId
Expand Down Expand Up @@ -469,7 +468,6 @@ export class Web3Modal extends Web3ModalScaffold {
}
}

// Console.log(`provider`, provider);
if (provider) {
provider.on('disconnect', disconnectHandler)
provider.on('accountsChanged', accountsChangedHandler)
Expand Down

0 comments on commit 81f8e1c

Please sign in to comment.