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

feat: coinbase pay sdk integration #1487

Merged
merged 91 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 83 commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
3b5af82
feat: add coinbase pay w3m
enesozturk Nov 21, 2023
fffb3d2
refactor: connect address and network to pay sdk
enesozturk Nov 21, 2023
72ca4c5
chore: update cb pay sdk logics
enesozturk Nov 21, 2023
e8b9869
Add controller for Coinbase Pay API
neelramachandran-cb Nov 22, 2023
4a28904
chore: fixes
enesozturk Nov 22, 2023
58ca3b3
chore: linter issues
enesozturk Nov 23, 2023
ae0dbfc
feat: add coinbase transactions
enesozturk Nov 23, 2023
f086ac6
feat: init new account page implementations
enesozturk Nov 23, 2023
f53e274
feat: update account page
enesozturk Nov 24, 2023
fbdfeb0
feat: get coinbase transactions
enesozturk Nov 24, 2023
9bc9961
chore: update account button
enesozturk Nov 24, 2023
9927398
chore: update styles
enesozturk Nov 24, 2023
872fbfb
chore: update lock file
enesozturk Nov 24, 2023
e7c0eda
refactor: update styles
enesozturk Nov 24, 2023
941dc85
chore: save state
enesozturk Dec 7, 2023
49ea91e
chore: save state
enesozturk Dec 11, 2023
aa40bdf
chore: revert account design
enesozturk Dec 15, 2023
c00b812
chore: revert transaction list changes
enesozturk Dec 15, 2023
4ddddfb
chore: rebase
enesozturk Dec 15, 2023
3153082
fix: transaction item visuals
enesozturk Dec 15, 2023
b5ffbec
chore: danger issues
enesozturk Dec 15, 2023
ae7da13
chore: build issues
enesozturk Dec 15, 2023
f2e0302
chore: save state
enesozturk Dec 20, 2023
11cddec
feat: onramp activity items, handle transaction detect and timeout st…
enesozturk Dec 20, 2023
d27cc6b
chore: update values
enesozturk Dec 20, 2023
62650d4
feat: update cb api params
enesozturk Dec 20, 2023
14dc742
chore: build issues
enesozturk Dec 20, 2023
2759a01
chore: remove logs
enesozturk Dec 21, 2023
e1c57b6
fix: build issues
enesozturk Dec 21, 2023
329c34e
chore: update generate onramp url logic
enesozturk Dec 21, 2023
699efa5
chore: remove account view list items
enesozturk Dec 21, 2023
2b32e38
chore: add new asset for provider item
enesozturk Dec 21, 2023
31dacaf
chore: update lock file
enesozturk Dec 21, 2023
bcee838
feat: add what is buy page, new icons and visuals
enesozturk Dec 21, 2023
65e576b
chore: remove buy button
enesozturk Dec 21, 2023
c481549
fix: linter issues
enesozturk Dec 21, 2023
3b8eb55
feat: add buy in progress screen
enesozturk Dec 22, 2023
151b480
feat: update onramp activity page
enesozturk Dec 22, 2023
52c81e6
chore: remove activity item image class
enesozturk Dec 22, 2023
8dd4b14
chore: add different chains for buy
enesozturk Jan 3, 2024
a27df69
chore: update cbpay configs
enesozturk Jan 3, 2024
fa01824
feat: fetch coinbase activity
enesozturk Jan 3, 2024
0f83544
chore: update default network logic
enesozturk Jan 4, 2024
da5d521
refactor: remove coinbase api controller
enesozturk Jan 4, 2024
0967018
chore: update interval end duration
enesozturk Jan 4, 2024
038a2a0
Merge branch 'V3' into feat/coinbase-pay
xzilja Jan 16, 2024
36c0572
fix lint issues
xzilja Jan 16, 2024
073a8e4
fix some dangerjs issues
xzilja Jan 16, 2024
3b8e250
fix danger check
xzilja Jan 16, 2024
85546eb
Fix lint issues in dangerfile
xzilja Jan 16, 2024
4b845e7
Remove unused localhost helper
xzilja Jan 16, 2024
f1c1b25
adjustments
xzilja Jan 16, 2024
24e85a4
Remove unused new tabs prop
xzilja Jan 16, 2024
3afdef8
add OnRampController test
xzilja Jan 16, 2024
b46ffa0
Merge branch 'V3' into feat/coinbase-pay
xzilja Jan 16, 2024
bd5a344
wui-onramp-activity-item story
xzilja Jan 16, 2024
c744716
fix gallery
xzilja Jan 16, 2024
3fc6e40
Merge branch 'V3' into feat/coinbase-pay
xzilja Jan 16, 2024
83d25ae
chore: cbpay v4 update (#1786)
tomiir Jan 19, 2024
17a3607
fix: onramp copy (#1770)
tomiir Jan 22, 2024
04f4ef1
feat: cbpay activity images (#1789)
tomiir Jan 22, 2024
00b9a0b
feat: enableOnramp flag (#1765)
tomiir Jan 23, 2024
172da26
fix: update copy icon
tomiir Jan 26, 2024
1557be2
feat: add balance to account screen
tomiir Jan 26, 2024
4766395
feat: add medium-title-600 text and base styles. fixed account view a…
tomiir Jan 26, 2024
6ba9986
fix: Onramp UI (#1848)
tomiir Jan 29, 2024
790844e
fix: coinbase onramp activity infinite loading (#1779)
tomiir Jan 29, 2024
5da39d2
Merge branch 'V4' of github.com:WalletConnect/web3modal into feat/coi…
tomiir Jan 29, 2024
b6000b6
feat: remove cbpay dependency and use blockchain API request
tomiir Jan 29, 2024
15040b0
chore: add onramp to all lab pages
tomiir Jan 29, 2024
ddcdb1d
chore: add spacing between provider name and fees
tomiir Jan 30, 2024
00f8fc5
fix: disable provider when url unavailable
tomiir Jan 30, 2024
9108c31
fix: cache no store on fetch get
tomiir Jan 31, 2024
18b78b8
chore: add cursor on onramptxs
tomiir Jan 31, 2024
b296e04
Merge branch 'V4' of github.com:WalletConnect/web3modal into feat/coi…
tomiir Feb 1, 2024
2f934e3
fix: remove unused styles causing danger
tomiir Feb 1, 2024
05bd5c3
Merge branch 'V4' of github.com:WalletConnect/web3modal into feat/coi…
tomiir Feb 1, 2024
658316d
chore: improve danger logs
tomiir Feb 1, 2024
633c396
fix: onramp activity cache (#1861)
tomiir Feb 5, 2024
86139a7
Merge branch 'V4' of github.com:WalletConnect/web3modal into feat/coi…
tomiir Feb 6, 2024
45bff88
Merge branch 'feat/coinbase-pay' of github.com:WalletConnect/web3moda…
tomiir Feb 6, 2024
d0f63bd
Merge branch 'V4' into feat/coinbase-pay
tomiir Feb 6, 2024
6578bba
Merge branch 'V4' into feat/coinbase-pay
tomiir Feb 7, 2024
fcd3e18
chore: use CoreHelperUtil sort method
tomiir Feb 7, 2024
5f54fea
chore: sort routes alphabetically
tomiir Feb 7, 2024
052c3cb
chore: replace color with css var
tomiir Feb 7, 2024
048cbff
chore: use typed import
tomiir Feb 7, 2024
7c885b1
chore: reformat svgs code style. Remove wallet2 icon
tomiir Feb 7, 2024
838d7f6
Merge branch 'V4' into feat/coinbase-pay
tomiir Feb 7, 2024
e57fc54
Merge branch 'V4' into feat/coinbase-pay
tomiir Feb 7, 2024
d65b46a
Merge branch 'V4' into feat/coinbase-pay
tomiir Feb 7, 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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"**/out": true,
"**/dist": true,
"**/.turbo": true,
"**/playwright-report": true
"**/playwright-report": true,
"**/coverage": true
},
"javascript.updateImportsOnFileMove.enabled": "always",
"typescript.tsdk": "node_modules/typescript/lib",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { Meta } from '@storybook/web-components'
import '@web3modal/ui/src/composites/wui-onramp-activity-item'
import type { WuiOnRampActivityItem } from '@web3modal/ui/src/composites/wui-onramp-activity-item'
import { html } from 'lit'
import '../../components/gallery-container'

type Component = Meta<WuiOnRampActivityItem>

export default {
title: 'Composites/wui-onramp-activity-item',
args: {
completed: true,
inProgress: false,
failed: false,
purchaseCurrency: 'USD',
purchaseValue: '1000',
date: '2 days ago'
}
} as Component

export const Default: Component = {
render: args => html`
<gallery-container width="340">
<wui-onramp-activity-item
label="Bought"
.completed=${args.completed}
.inProgress=${args.inProgress}
.failed=${args.failed}
purchaseCurrency=${args.purchaseCurrency}
purchaseValue=${args.purchaseValue}
date=${args.date}
></wui-onramp-activity-item>
</gallery-container>
`
}
9 changes: 7 additions & 2 deletions apps/gallery/utils/PresetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export const textOptions: TextType[] = [
'paragraph-700',
'large-500',
'large-600',
'large-700'
'large-700',
'2xl-500'
]

export const textAlignOptions: TextAlign[] = ['center', 'left', 'right']
Expand Down Expand Up @@ -225,7 +226,11 @@ export const visualOptions: VisualType[] = [
'nft',
'noun',
'profile',
'system'
'system',
'coinbase',
'stripe',
'moonpay',
'paypal'
]

export const logoOptions: LogoType[] = [
Expand Down
3 changes: 2 additions & 1 deletion apps/laboratory/src/pages/library/ethers-email.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const modal = createWeb3Modal({
enableAnalytics: true,
metadata: ConstantsUtil.Metadata,
termsConditionsUrl: 'https://walletconnect.com/terms',
privacyPolicyUrl: 'https://walletconnect.com/privacy'
privacyPolicyUrl: 'https://walletconnect.com/privacy',
enableOnramp: true
})

ThemeStore.setModal(modal)
Expand Down
3 changes: 2 additions & 1 deletion apps/laboratory/src/pages/library/ethers-siwe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const modal = createWeb3Modal({
projectId: ConstantsUtil.ProjectId,
enableAnalytics: true,
metadata: ConstantsUtil.Metadata,
siweConfig
siweConfig,
enableOnramp: true
})

ThemeStore.setModal(modal)
Expand Down
3 changes: 2 additions & 1 deletion apps/laboratory/src/pages/library/ethers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const modal = createWeb3Modal({
desktop_link: 'https://react-wallet.walletconnect.com',
webapp_link: 'https://react-wallet.walletconnect.com'
}
]
],
enableOnramp: true
})

ThemeStore.setModal(modal)
Expand Down
3 changes: 2 additions & 1 deletion apps/laboratory/src/pages/library/wagmi-email.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const modal = createWeb3Modal({
enableAnalytics: true,
metadata: ConstantsUtil.Metadata,
termsConditionsUrl: 'https://walletconnect.com/terms',
privacyPolicyUrl: 'https://walletconnect.com/privacy'
privacyPolicyUrl: 'https://walletconnect.com/privacy',
enableOnramp: true
})

ThemeStore.setModal(modal)
Expand Down
3 changes: 2 additions & 1 deletion apps/laboratory/src/pages/library/wagmi-siwe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const modal = createWeb3Modal({
projectId: ConstantsUtil.ProjectId,
enableAnalytics: true,
metadata: ConstantsUtil.Metadata,
siweConfig
siweConfig,
enableOnramp: true
})

ThemeStore.setModal(modal)
Expand Down
3 changes: 2 additions & 1 deletion apps/laboratory/src/pages/library/wagmi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const modal = createWeb3Modal({
desktop_link: 'https://react-wallet.walletconnect.com',
webapp_link: 'https://react-wallet.walletconnect.com'
}
]
],
enableOnramp: true
})

ThemeStore.setModal(modal)
Expand Down
25 changes: 21 additions & 4 deletions dangerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,31 @@ async function checkUiPackage() {
fail('New layout components were added, but not exported in ui/index.ts')
}

if (created_ui_components_index_ts.length && !jsx_index_diff?.added.includes('../components')) {
fail('New components were added, but not exported in ui/utils/JSXTypeUtil.ts')
if (
created_ui_components_index_ts.length &&
!jsx_index_diff?.added.includes('../components') &&
!jsx_index_diff?.diff.includes('../components')
) {
fail(
`New components were added, but not exported in ui/utils/JSXTypeUtil.ts: ${created_ui_components.join(
', '
)}`
)
}

if (created_ui_composites_index_ts.length && !jsx_index_diff?.added.includes('../composites')) {
if (
created_ui_composites_index_ts.length &&
!jsx_index_diff?.added.includes('../composites') &&
!jsx_index_diff?.diff.includes('../composites')
) {
fail('New composites were added, but not exported in ui/utils/JSXTypeUtil.ts')
}

if (created_ui_layout_index_ts.length && !jsx_index_diff?.added.includes('../layout')) {
if (
created_ui_layout_index_ts.length &&
!jsx_index_diff?.added.includes('../layout') &&
!jsx_index_diff?.diff.includes('../layout')
) {
fail('New layout components were added, but not exported in ui/utils/JSXTypeUtil.ts')
}

Expand Down Expand Up @@ -278,6 +294,7 @@ checkSdkVersion()
async function checkDevelopmentConstants() {
for (const f of updated_files) {
if (f.includes('README.md') || f.includes('.yml')) {
// eslint-disable-next-line no-continue
continue
}
const diff = await diffForFile(f)
Expand Down
7 changes: 6 additions & 1 deletion packages/common/src/utils/TypeUtil.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export type CoinbaseTransactionStatus =
| 'ONRAMP_TRANSACTION_STATUS_SUCCESS'
| 'ONRAMP_TRANSACTION_STATUS_IN_PROGRESS'
| 'ONRAMP_TRANSACTION_STATUS_FAILED'

export type TransactionStatus = 'confirmed' | 'failed' | 'pending'

export type TransactionDirection = 'in' | 'out' | 'self'
Expand All @@ -19,7 +24,7 @@ export interface TransactionMetadata {
minedAt: string
sentFrom: string
sentTo: string
status: TransactionStatus
status: TransactionStatus | CoinbaseTransactionStatus
nonce: number
}

Expand Down
3 changes: 3 additions & 0 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export type {
NetworkControllerState
} from './src/controllers/NetworkController.js'

export { OnRampController } from './src/controllers/OnRampController.js'
export type { OnRampControllerState, OnRampProvider } from './src/controllers/OnRampController.js'

export { ConnectionController } from './src/controllers/ConnectionController.js'
export type {
ConnectionControllerClient,
Expand Down
41 changes: 38 additions & 3 deletions packages/core/src/controllers/BlockchainApiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ import type {
} from '../utils/TypeUtil.js'
import { OptionsController } from './OptionsController.js'

type DestinationWallet = {
address: string
blockchains: string[]
assets: string[]
}

type GenerateOnRampT = {
destinationWallets: DestinationWallet[]
partnerUserId: string
defaultNetwork?: string
}

// -- Helpers ------------------------------------------- //
const baseUrl = CoreHelperUtil.getBlockchainApiUrl()
const api = new FetchUtil({ baseUrl })
Expand All @@ -24,12 +36,35 @@ export const BlockchainApiController = {
})
},

fetchTransactions({ account, projectId, cursor }: BlockchainApiTransactionsRequest) {
fetchTransactions({
account,
projectId,
cursor,
onramp,
signal
}: BlockchainApiTransactionsRequest) {
const queryParams = cursor ? { cursor } : {}

return api.get<BlockchainApiTransactionsResponse>({
path: `/v1/account/${account}/history?projectId=${projectId}`,
params: queryParams
path: `/v1/account/${account}/history?projectId=${projectId}${
onramp ? `&onramp=${onramp}` : ''
}`,
params: queryParams,
signal
})
},

async generateOnRampURL({ destinationWallets, partnerUserId, defaultNetwork }: GenerateOnRampT) {
const response = await api.post<{ url: string }>({
path: `/v1/generators/onrampurl?projectId=${OptionsController.state.projectId}`,
body: {
destinationWallets,
defaultNetwork,
partnerUserId,
defaultExperience: 'buy'
}
})

return response.url
}
}
31 changes: 31 additions & 0 deletions packages/core/src/controllers/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,37 @@ export const NetworkController = {
state.requestedCaipNetworks = requestedNetworks
},

getRequestedCaipNetworks() {
tomiir marked this conversation as resolved.
Show resolved Hide resolved
tomiir marked this conversation as resolved.
Show resolved Hide resolved
const { approvedCaipNetworkIds, requestedCaipNetworks } = state

const approvedIds = approvedCaipNetworkIds
const requestedNetworks = requestedCaipNetworks
const approvedIndexMap: Record<string, number> = {}

if (requestedNetworks && approvedIds) {
approvedIds.forEach((id, index) => {
approvedIndexMap[id] = index
})

requestedNetworks.sort((a, b) => {
const indexA = approvedIndexMap[a.id]
const indexB = approvedIndexMap[b.id]

if (indexA !== undefined && indexB !== undefined) {
return indexA - indexB
} else if (indexA !== undefined) {
return -1
} else if (indexB !== undefined) {
return 1
}

return 0
})
}

return requestedNetworks
},

async getApprovedCaipNetworksData() {
const data = await this._getClient().getApprovedCaipNetworksData()
state.supportsAllNetworks = data.supportsAllNetworks
Expand Down
41 changes: 41 additions & 0 deletions packages/core/src/controllers/OnRampController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { subscribeKey as subKey } from 'valtio/utils'
import { proxy } from 'valtio/vanilla'
import { ONRAMP_PROVIDERS } from '../utils/ConstantsUtil.js'

// -- Types --------------------------------------------- //
export type OnRampProviderOption = 'coinbase' | 'moonpay' | 'stripe' | 'paypal'

export type OnRampProvider = {
label: string
name: OnRampProviderOption
feeRange: string
url: string
}

export interface OnRampControllerState {
providers: OnRampProvider[]
selectedProvider: OnRampProvider | null
error: string | null
}

type StateKey = keyof OnRampControllerState

// -- State --------------------------------------------- //
const state = proxy<OnRampControllerState>({
providers: ONRAMP_PROVIDERS as OnRampProvider[],
selectedProvider: null,
error: null
})

// -- Controller ---------------------------------------- //
export const OnRampController = {
state,

subscribeKey<K extends StateKey>(key: K, callback: (value: OnRampControllerState[K]) => void) {
return subKey(state, key, callback)
},

setSelectedProvider(provider: OnRampProvider | null) {
state.selectedProvider = provider
}
}
9 changes: 7 additions & 2 deletions packages/core/src/controllers/OptionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type { CustomWallet, Metadata, ProjectId, SdkVersion, Tokens } from '../u
// -- Types --------------------------------------------- //
export interface OptionsControllerState {
projectId: ProjectId
sdkType: 'w3m'
sdkVersion: SdkVersion
allWallets?: 'SHOW' | 'HIDE' | 'ONLY_MOBILE'
featuredWalletIds?: string[]
includeWalletIds?: string[]
Expand All @@ -15,8 +17,7 @@ export interface OptionsControllerState {
privacyPolicyUrl?: string
enableAnalytics?: boolean
metadata?: Metadata
sdkType: 'w3m'
sdkVersion: SdkVersion
enableOnramp?: boolean
}

type StateKey = keyof OptionsControllerState
Expand Down Expand Up @@ -82,5 +83,9 @@ export const OptionsController = {

setMetadata(metadata: OptionsControllerState['metadata']) {
state.metadata = metadata
},

setOnrampEnabled(enableOnramp: OptionsControllerState['enableOnramp']) {
state.enableOnramp = enableOnramp
}
}
5 changes: 5 additions & 0 deletions packages/core/src/controllers/RouterController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { CaipNetwork, Connector, WcWallet } from '../utils/TypeUtil.js'
export interface RouterControllerState {
view:
| 'Account'
| 'AccountSettings'
| 'Connect'
| 'ConnectingExternal'
| 'ConnectingWalletConnect'
Expand All @@ -26,6 +27,10 @@ export interface RouterControllerState {
| 'UpdateEmailPrimaryOtp'
| 'UpdateEmailSecondaryOtp'
| 'UnsupportedChain'
| 'OnRampProviders'
| 'OnRampActivity'
| 'WhatIsABuy'
tomiir marked this conversation as resolved.
Show resolved Hide resolved
| 'BuyInProgress'
history: RouterControllerState['view'][]
data?: {
connector?: Connector
Expand Down
Loading
Loading