Skip to content

Commit

Permalink
feat: add coinbase pay
Browse files Browse the repository at this point in the history
  • Loading branch information
enesozturk committed Nov 20, 2023
1 parent 30f4bd4 commit e43b2ce
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
19 changes: 18 additions & 1 deletion package-lock.json

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

1 change: 1 addition & 0 deletions packages/scaffold/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
},
"dependencies": {
"@coinbase/cbpay-js": "^1.9.0",
"@web3modal/core": "3.3.2",
"@web3modal/ui": "3.3.2",
"lit": "3.0.0"
Expand Down
55 changes: 54 additions & 1 deletion packages/scaffold/src/views/w3m-account-view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { state } from 'lit/decorators.js'
import { ifDefined } from 'lit/directives/if-defined.js'
import styles from './styles.js'

import { initOnRamp, generateOnRampURL } from '@coinbase/cbpay-js'
import type { CBPayInstanceType } from '@coinbase/cbpay-js'

@customElement('w3m-account-view')
export class W3mAccountView extends LitElement {
public static override styles = styles
Expand All @@ -37,6 +40,8 @@ export class W3mAccountView extends LitElement {

@state() private network = NetworkController.state.caipNetwork

@state() private onrampInstance: CBPayInstanceType | null = null

@state() private disconecting = false

public constructor() {
Expand Down Expand Up @@ -67,6 +72,42 @@ export class W3mAccountView extends LitElement {
this.usubscribe.forEach(unsubscribe => unsubscribe())
}

public override firstUpdated() {
initOnRamp(
{
appId: 'bf18c88d-495a-463b-b249-0b9d3656cf5e',
widgetParameters: {
destinationWallets: [
{
address: '0xf3ea39310011333095CFCcCc7c4Ad74034CABA63',
blockchains: ['ethereum']
}
]
},
onSuccess: () => {
console.log('success')
},
onExit: () => {
console.log('exit')
},
onEvent: event => {
console.log('event', event)
},
experienceLoggedIn: 'popup',
experienceLoggedOut: 'popup',
closeOnExit: true,
closeOnSuccess: true
},
(_, instance) => {
this.onrampInstance = instance
}
)

return () => {
this.onrampInstance?.destroy()
}
}

// -- Render -------------------------------------------- //
public override render() {
if (!this.address) {
Expand All @@ -87,7 +128,6 @@ export class W3mAccountView extends LitElement {
address=${this.address}
imageSrc=${ifDefined(this.profileImage)}
></wui-avatar>
<wui-flex flexDirection="column" alignItems="center">
<wui-flex gap="3xs" alignItems="center" justifyContent="center">
<wui-text variant="large-600" color="fg-100">
Expand Down Expand Up @@ -135,6 +175,15 @@ export class W3mAccountView extends LitElement {
${this.network?.name ?? 'Unknown'}
</wui-text>
</wui-list-item>
<wui-list-item
iconVariant="blue"
icon="swapHorizontalBold"
iconSize="sm"
?chevron=${true}
@click=${this.handleClickPay.bind(this)}
>
<wui-text variant="paragraph-500" color="fg-100">Pay with Coinbase</wui-text>
</wui-list-item>
<wui-list-item
iconVariant="blue"
icon="swapHorizontalBold"
Expand All @@ -159,6 +208,10 @@ export class W3mAccountView extends LitElement {
}

// -- Private ------------------------------------------- //
private handleClickPay() {
this.onrampInstance?.open()
}

private explorerBtnTemplate() {
const { addressExplorerUrl } = AccountController.state

Expand Down

0 comments on commit e43b2ce

Please sign in to comment.