Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: coinbase connector popup improvements #2392

Merged
merged 28 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ae6407f
Merge branch 'V4' of github.com:WalletConnect/web3modal into V4
svenvoskamp May 15, 2024
9888c89
Merge branch 'V4' of github.com:WalletConnect/web3modal into V4
svenvoskamp May 15, 2024
4362254
Merge branch 'V4' of github.com:WalletConnect/web3modal into V4
svenvoskamp May 16, 2024
fa858a4
Merge branch 'V4' of github.com:WalletConnect/web3modal into V4
svenvoskamp May 16, 2024
2920ef4
Merge branch 'V4' of github.com:WalletConnect/web3modal into V4
svenvoskamp May 27, 2024
e7fc41b
Merge branch 'V4' of github.com:WalletConnect/web3modal into V4
svenvoskamp Jun 3, 2024
c7ed29e
Merge branch 'V4' of github.com:WalletConnect/web3modal into V4
svenvoskamp Jun 5, 2024
987d806
Merge branch 'V4' of github.com:WalletConnect/web3modal into V4
svenvoskamp Jun 10, 2024
d010311
Merge branch 'V4' of github.com:WalletConnect/web3modal into V4
svenvoskamp Jun 11, 2024
b3a5f94
Merge branch 'V4' of github.com:WalletConnect/web3modal into V4
svenvoskamp Jun 11, 2024
5efd2b3
add featured widget
svenvoskamp Jun 11, 2024
1dc70f9
Merge branch 'V4' into fix/add-featured-widget
svenvoskamp Jun 11, 2024
d0dd49d
Merge branch 'V4' into fix/add-featured-widget
svenvoskamp Jun 11, 2024
bad9b9a
add external and remove coinbase
svenvoskamp Jun 11, 2024
70e47f0
Merge branch 'fix/add-featured-widget' of github.com:WalletConnect/we…
svenvoskamp Jun 11, 2024
d84277a
refactor: coinbase connector popup improvements
enesozturk Jun 11, 2024
09c7fc8
fix: duplicate method, variable usage
enesozturk Jun 11, 2024
7ed2ca8
refactor: add tsbuildinfo to gitignore
enesozturk Jun 11, 2024
0d6e75a
refactor: set wcerror to false
enesozturk Jun 11, 2024
c9a388b
Merge branch 'V4' into fix/add-featured-widget
svenvoskamp Jun 12, 2024
213df1e
remove external widget
svenvoskamp Jun 12, 2024
4c158b4
Merge branch 'fix/add-featured-widget' of github.com:WalletConnect/we…
svenvoskamp Jun 12, 2024
8df037a
merge
svenvoskamp Jun 12, 2024
e9c5d61
Merge branch 'fix/add-featured-widget' into refactor/coinbase-connect…
enesozturk Jun 12, 2024
492ff66
refactor: update coinbase widget onConnect handler
enesozturk Jun 12, 2024
c683e4d
Merge branch 'V4' into refactor/coinbase-connector-popup-trigger-logic
enesozturk Jun 12, 2024
3b64225
refactor: update coinbase catch logic
enesozturk Jun 12, 2024
68e1e0c
Merge branch 'V4' into refactor/coinbase-connector-popup-trigger-logic
svenvoskamp Jun 12, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ coverage
test-results
.vscode/*
apps/laboratory/playwright/.auth/user.json
tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions packages/ethers/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ export interface Web3ModalClientOptions extends Omit<LibraryOptions, 'defaultCha
tokens?: Record<number, Token>
}

type CoinbaseProviderError = {
code: number
message: string
data: string | undefined
}

export type Web3ModalOptions = Omit<Web3ModalClientOptions, '_sdkVersion'>

declare global {
Expand Down Expand Up @@ -281,6 +287,7 @@ export class Web3Modal extends Web3ModalScaffold {
this.setCoinbaseProvider(ethersConfig)
} catch (error) {
EthersStoreUtil.setError(error)
throw new Error((error as CoinbaseProviderError).message)
}
} else if (id === ConstantsUtil.AUTH_CONNECTOR_ID) {
this.setAuthProvider()
Expand Down
7 changes: 7 additions & 0 deletions packages/ethers5/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export interface Web3ModalClientOptions extends Omit<LibraryOptions, 'defaultCha
tokens?: Record<number, Token>
}

type CoinbaseProviderError = {
code: number
message: string
data: string | undefined
}

export type Web3ModalOptions = Omit<Web3ModalClientOptions, '_sdkVersion'>

declare global {
Expand Down Expand Up @@ -256,6 +262,7 @@ export class Web3Modal extends Web3ModalScaffold {
await CoinbaseProvider.request({ method: 'eth_requestAccounts' })
} catch (error) {
EthersStoreUtil.setError(error)
throw new Error((error as CoinbaseProviderError).message)
}
}
},
Expand Down
1 change: 0 additions & 1 deletion packages/scaffold/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export * from './src/partials/w3m-wallet-login-list/index.js'
export * from './src/partials/w3m-social-login-list/index.js'
export * from './src/partials/w3m-connect-announced-widget/index.js'
export * from './src/partials/w3m-connect-custom-widget/index.js'
export * from './src/partials/w3m-connect-external-widget/index.js'
export * from './src/partials/w3m-connect-featured-widget/index.js'
export * from './src/partials/w3m-connect-injected-widget/index.js'
export * from './src/partials/w3m-connect-coinbase-widget/index.js'
Expand Down
1 change: 1 addition & 0 deletions packages/scaffold/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"dependencies": {
"@web3modal/common": "4.2.3",
"@web3modal/scaffold-utils": "4.2.3",
"@web3modal/core": "4.2.3",
"@web3modal/ui": "4.2.3",
"lit": "3.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import type { Connector } from '@web3modal/core'
import { AssetUtil, ConnectorController, RouterController } from '@web3modal/core'
import type { BaseError, Connector } from '@web3modal/core'
import {
AssetUtil,
ConnectionController,
ConnectorController,
EventsController,
ModalController,
OptionsController,
RouterController,
StorageUtil
} from '@web3modal/core'
import { ConstantsUtil } from '@web3modal/scaffold-utils'
import { customElement } from '@web3modal/ui'
import { LitElement, html } from 'lit'
import { state } from 'lit/decorators.js'
Expand Down Expand Up @@ -51,8 +61,46 @@ export class W3mConnectCoinbaseWidget extends LitElement {
}

// -- Private Methods ----------------------------------- //
/**
* Replicate of `onConnectProxy` method from `w3m-connecting-external-view` which is only used for Coinbase connector.
*/
private async onCoinbaseConnector(connector: Connector) {
try {
ConnectionController.setWcError(false)

if (connector.imageUrl) {
StorageUtil.setConnectedWalletImageUrl(connector.imageUrl)
}

await ConnectionController.connectExternal(connector)

if (OptionsController.state.isSiweEnabled) {
RouterController.push('ConnectingSiwe')
} else {
ModalController.close()
}

EventsController.sendEvent({
type: 'track',
event: 'CONNECT_SUCCESS',
properties: { method: 'browser', name: connector.name || 'Unknown' }
})
} catch (error) {
EventsController.sendEvent({
type: 'track',
event: 'CONNECT_ERROR',
properties: { message: (error as BaseError)?.message ?? 'Unknown' }
})
ConnectionController.setWcError(true)
}
}

private onConnector(connector: Connector) {
RouterController.push('ConnectingExternal', { connector })

if (connector.id === ConstantsUtil.COINBASE_SDK_CONNECTOR_ID) {
this.onCoinbaseConnector(connector)
}
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export class W3mWalletLoginList extends LitElement {
<w3m-connect-injected-widget></w3m-connect-injected-widget>
<w3m-connect-featured-widget></w3m-connect-featured-widget>
<w3m-connect-custom-widget></w3m-connect-custom-widget>
<w3m-connect-coinbase-widget></w3m-connect-coinbase-widget>
<w3m-connect-recommended-widget></w3m-connect-recommended-widget>
<w3m-connect-external-widget></w3m-connect-external-widget>
<w3m-all-wallets-widget></w3m-all-wallets-widget>
</wui-flex>
`
Expand Down
3 changes: 2 additions & 1 deletion packages/scaffold/src/views/w3m-connect-view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ export class W3mConnectView extends LitElement {
<w3m-connect-recent-widget></w3m-connect-recent-widget>
<w3m-connect-announced-widget></w3m-connect-announced-widget>
<w3m-connect-injected-widget></w3m-connect-injected-widget>
<w3m-connect-coinbase-widget></w3m-connect-coinbase-widget>
<w3m-connect-featured-widget></w3m-connect-featured-widget>
<w3m-connect-custom-widget></w3m-connect-custom-widget>
<w3m-connect-coinbase-widget></w3m-connect-coinbase-widget>
<w3m-connect-recommended-widget></w3m-connect-recommended-widget>
<wui-flex class="all-wallets" .margin=${['xs', '0', '0', '0'] as const}>
<w3m-all-wallets-widget></w3m-all-wallets-widget>
Expand Down
30 changes: 19 additions & 11 deletions packages/scaffold/src/views/w3m-connecting-external-view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '@web3modal/core'
import { customElement } from '@web3modal/ui'
import { W3mConnectingWidget } from '../../utils/w3m-connecting-widget/index.js'
import { ConstantsUtil } from '@web3modal/scaffold-utils'

@customElement('w3m-connecting-external-view')
export class W3mConnectingExternalView extends W3mConnectingWidget {
Expand Down Expand Up @@ -39,19 +40,26 @@ export class W3mConnectingExternalView extends W3mConnectingWidget {
if (this.connector.imageUrl) {
StorageUtil.setConnectedWalletImageUrl(this.connector.imageUrl)
}
await ConnectionController.connectExternal(this.connector)
/**
* Coinbase SDK works with popups and popups requires user interaction to be opened since modern browsers block popups which triggered programmatically.
* Instead of opening a popup in first render for `W3mConnectingWidget`, we need to trigger connection for Coinbase connector specifically when users select it.
* And if there is an error, this condition will be skipped and the connection will be triggered as usual because we have `Try again` button in this view which is a user interaction as well.
*/
if (this.connector.id !== ConstantsUtil.COINBASE_SDK_CONNECTOR_ID || !this.error) {
await ConnectionController.connectExternal(this.connector)

if (OptionsController.state.isSiweEnabled) {
RouterController.push('ConnectingSiwe')
} else {
ModalController.close()
}
if (OptionsController.state.isSiweEnabled) {
RouterController.push('ConnectingSiwe')
} else {
ModalController.close()
}

EventsController.sendEvent({
type: 'track',
event: 'CONNECT_SUCCESS',
properties: { method: 'browser', name: this.connector.name || 'Unknown' }
})
EventsController.sendEvent({
type: 'track',
event: 'CONNECT_SUCCESS',
properties: { method: 'browser', name: this.connector.name || 'Unknown' }
})
}
}
} catch (error) {
EventsController.sendEvent({
Expand Down
Loading