Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/kind-parents-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@reown/appkit-adapter-bitcoin': patch
'@reown/appkit-utils': patch
'@reown/appkit-controllers': patch
---

Fixes issue where OKX wallet would not target the Signet network correctly.
82 changes: 47 additions & 35 deletions packages/adapters/bitcoin/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,39 @@ export class BitcoinAdapter extends AdapterBlueprint<BitcoinConnector> {
throw new Error('The connector does not support any of the requested chains')
}

const connection = this.getConnection({
address: params.address,
connectorId: connector.id,
connections: this.connections,
connectors: this.connectors
})

if (connection?.account) {
this.emit('accountChanged', {
address: connection.account.address,
chainId: connection.caipNetwork?.id,
connector
// If we are already connected to the address, return the connection to prevent extra interactions
if (params.address) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do for the other adapters as well? i.e Solana or Ton also have the same logics, or it's Bitcoin only issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can do this, would need to deeply test all wallets on other networks for this tho

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added it for solana, a bit wary to do this for evm ones tho , specially wagmi. Will do separately

const connection = this.getConnection({
address: params.address,
connectorId: connector.id,
connections: this.connections,
connectors: this.connectors
})

return {
id: connector.id,
type: connector.type,
address: connection.account.address,
chainId: chain.id,
provider: connector.provider
if (connection?.account) {
this.emit('accountChanged', {
address: connection.account.address,
chainId: connection.caipNetwork?.id,
connector
})

return {
id: connector.id,
type: connector.type,
address: connection.account.address,
chainId: chain.id,
provider: connector.provider
}
}
}

const address = await connector.connect().catch(err => {
const address = await connector.connect({ caipNetworkId: chain.caipNetworkId }).catch(err => {
throw new UserRejectedRequestError(err)
})
const accounts = await this.getAccounts({ id: connector.id })
const accounts = await this.getAccounts({
id: connector.id,
caipNetworkId: chain.caipNetworkId
})

this.emit('accountChanged', {
address,
Expand Down Expand Up @@ -119,7 +125,7 @@ export class BitcoinAdapter extends AdapterBlueprint<BitcoinConnector> {
): Promise<AdapterBlueprint.GetAccountsResult> {
const addresses = await this.connectors
.find(connector => connector.id === params.id)
?.getAccountAddresses()
?.getAccountAddresses({ caipNetworkId: params.caipNetworkId })
.catch(() => [])

let accounts = addresses?.map(a =>
Expand Down Expand Up @@ -180,13 +186,13 @@ export class BitcoinAdapter extends AdapterBlueprint<BitcoinConnector> {
})
)

const okxConnector = OKXConnector.getWallet({
const okxConnector = new OKXConnector({
requestedChains: this.networks,
requestedCaipNetworkId: ChainController.getActiveCaipNetwork(ConstantsUtil.CHAIN.BITCOIN)
?.caipNetworkId
})

if (okxConnector) {
if (CoreHelperUtil.isClient()) {
this.addConnector(okxConnector)
}

Expand Down Expand Up @@ -220,7 +226,6 @@ export class BitcoinAdapter extends AdapterBlueprint<BitcoinConnector> {
const { address } = CoreHelperUtil.getAccount(accounts[0])

const allAccounts = await this.getAccounts({ id: connectorId })

const connection = this.getConnection({
connectorId,
connections: this.connections,
Expand Down Expand Up @@ -570,24 +575,22 @@ export class BitcoinAdapter extends AdapterBlueprint<BitcoinConnector> {
if (!connector) {
throw new Error('BitcoinAdapter:onChainChanged - connector is undefined')
}
const chain = connector.chains.find(c => c.id === chainId) || connector.chains[0]

if (!chain) {
throw new Error('BitcoinAdapter:onChainChanged - chain is undefined')
}

const { address } = await this.connect({
id: connector.id,
chainId,
type: ''
})

const accounts = await this.getAccounts({ id: connector.id })
const chain = connector.chains.find(c => c.id === chainId) || connector.chains[0]

if (
HelpersUtil.isLowerCaseMatch(
this.getConnectorId(CommonConstantsUtil.CHAIN.BITCOIN),
connector.id
)
) {
this.emit('switchNetwork', { chainId, address })
}
const accounts = await this.getAccounts({
id: connector.id,
caipNetworkId: chain?.caipNetworkId
})

this.addConnection({
connectorId: connector.id,
Expand All @@ -599,6 +602,15 @@ export class BitcoinAdapter extends AdapterBlueprint<BitcoinConnector> {
})),
caipNetwork: chain
})

if (
HelpersUtil.isLowerCaseMatch(
this.getConnectorId(CommonConstantsUtil.CHAIN.BITCOIN),
connector.id
)
) {
this.emit('switchNetwork', { chainId: chain.id, address })
}
}

// -- Private ------------------------------------------ //
Expand Down
Loading
Loading