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

chore: onramp tests #1944

Merged
merged 38 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7751131
fix: use start time to check for new transactions
tomiir Feb 15, 2024
8171401
feat: add Base and debug logs
tomiir Feb 16, 2024
5775d36
--amend
tomiir Feb 16, 2024
98120a5
fix: buy crypto button label and icon
tomiir Feb 16, 2024
df8d066
chore: update what is buy copy
tomiir Feb 16, 2024
a1af81a
chore: filter repeated transactions by minedAt
tomiir Feb 16, 2024
11fec48
chore: add hash check
tomiir Feb 16, 2024
b4a150b
chore: code style
tomiir Feb 16, 2024
30948d6
chore: remove logs
tomiir Feb 19, 2024
d491625
Merge branch 'V4' into chore/onramp-bugbash
tomiir Feb 19, 2024
9f9e90b
fix: onramp transactions history parsing when tx hash is undefined
tomiir Feb 19, 2024
491a85c
Merge branch 'chore/onramp-bugbash' of github.com:WalletConnect/web3m…
tomiir Feb 19, 2024
c54d4e1
chore: rebuild lock
tomiir Feb 19, 2024
965f92c
fix: onramp transaction status group (#1942)
tomiir Feb 19, 2024
2e1588e
fix: previously broken tests
tomiir Feb 20, 2024
7a10ef0
feat: add TransactionsController onramp fetchTransactions test
tomiir Feb 20, 2024
3bb43e8
fix: mobile/brave buy in progress (#1943)
tomiir Feb 20, 2024
4835938
chore: split mock transactions into jan and feb. add update flow test
tomiir Feb 20, 2024
c8beadd
chore: clarify manual state wipe
tomiir Feb 20, 2024
3169577
chore: update data
tomiir Feb 20, 2024
791100a
chore: add pending to failed and multi update tests
tomiir Feb 20, 2024
e6d76fb
chore: add checks that other parts of statte havent changed
tomiir Feb 20, 2024
295b579
chore: add onramp controller getAvailableCurrencies test
tomiir Feb 20, 2024
e08ff1c
chore: add quotes tests
tomiir Feb 20, 2024
e9198e6
chore: add purchaseAmount state check on quotes test
tomiir Feb 21, 2024
251e5c4
chore: add error try catch and corresponding test
tomiir Feb 21, 2024
cdca1ba
Merge branch 'V4' of github.com:WalletConnect/web3modal into chore/on…
tomiir Feb 21, 2024
a09b3fc
Merge branch 'chore/onramp-bugbash' of github.com:WalletConnect/web3m…
tomiir Feb 21, 2024
5795de3
Merge branch 'chore/onramp-bugbash' of github.com:WalletConnect/web3m…
tomiir Feb 21, 2024
c4abb17
Merge branch 'V4' into chore/onramp-bugbash
tomiir Feb 21, 2024
67b1567
Merge branch 'chore/onramp-bugbash' of github.com:WalletConnect/web3m…
tomiir Feb 21, 2024
fadacfb
Merge branch 'V4' into chore/onramp-tests
tomiir Feb 21, 2024
2c0bd6e
Merge branch 'V4' of github.com:WalletConnect/web3modal into chore/on…
tomiir Feb 23, 2024
0a90e6f
chore: re-type to prevnt type assertion
tomiir Feb 23, 2024
aaa706e
Merge branch 'V4' into chore/onramp-tests
tomiir Feb 27, 2024
9223cbb
Merge branch 'V4' into chore/onramp-tests
tomiir Feb 29, 2024
5149996
Merge branch 'V4' into chore/onramp-tests
tomiir Feb 29, 2024
0d85d2f
chore: readd junit reporter
tomiir Feb 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
184 changes: 103 additions & 81 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/common/src/utils/TypeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface TransactionMetadata {
sentTo: string
status: TransactionStatus | CoinbaseTransactionStatus
nonce: number
chain?: string
}

export interface TransactionTransfer {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"build:core": "tsc --build",
"watch": "tsc --watch",
"typecheck": "tsc --noEmit",
"test": "vitest run --dir tests --coverage.enabled --reporter=junit --coverage.reporter=json-summary --coverage.reporter=html",
"test": "vitest run --dir tests --coverage.enabled --coverage.reporter=json-summary --coverage.reporter=html",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
},
"dependencies": {
Expand Down
52 changes: 38 additions & 14 deletions packages/core/src/controllers/OnRampController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface OnRampControllerState {

type StateKey = keyof OnRampControllerState

const USDC_CURRENCY_DEFAULT = {
export const USDC_CURRENCY_DEFAULT = {
id: '2b92315d-eab7-5bef-84fa-089a131333f5',
name: 'USD Coin',
symbol: 'USDC',
Expand All @@ -50,7 +50,7 @@ const USDC_CURRENCY_DEFAULT = {
]
}

const USD_CURRENCY_DEFAULT = {
export const USD_CURRENCY_DEFAULT = {
id: 'USD',
payment_method_limits: [
{
Expand All @@ -66,8 +66,7 @@ const USD_CURRENCY_DEFAULT = {
]
}

// -- State --------------------------------------------- //
const state = proxy<OnRampControllerState>({
const defaultState = {
providers: ONRAMP_PROVIDERS as OnRampProvider[],
selectedProvider: null,
error: null,
Expand All @@ -76,7 +75,10 @@ const state = proxy<OnRampControllerState>({
purchaseCurrencies: [USDC_CURRENCY_DEFAULT],
paymentCurrencies: [],
quotesLoading: false
})
}

// -- State --------------------------------------------- //
const state = proxy<OnRampControllerState>(defaultState)

// -- Controller ---------------------------------------- //
export const OnRampController = {
Expand Down Expand Up @@ -124,15 +126,37 @@ export const OnRampController = {

async getQuote() {
state.quotesLoading = true
const quote = await BlockchainApiController.getOnrampQuote({
purchaseCurrency: state.purchaseCurrency,
paymentCurrency: state.paymentCurrency,
amount: state.paymentAmount?.toString() || '0',
network: state.purchaseCurrency?.name
})
state.quotesLoading = false
state.purchaseAmount = Number(quote.purchaseAmount.amount)
try {
const quote = await BlockchainApiController.getOnrampQuote({
purchaseCurrency: state.purchaseCurrency,
paymentCurrency: state.paymentCurrency,
amount: state.paymentAmount?.toString() || '0',
network: state.purchaseCurrency?.symbol
})
state.quotesLoading = false
state.purchaseAmount = Number(quote.purchaseAmount.amount)

return quote
} catch (error) {
state.error = (error as Error).message
state.quotesLoading = false

return null
} finally {
state.quotesLoading = false
}
},

return quote
resetState() {
state.providers = ONRAMP_PROVIDERS as OnRampProvider[]
state.selectedProvider = null
state.error = null
state.purchaseCurrency = USDC_CURRENCY_DEFAULT
state.paymentCurrency = USD_CURRENCY_DEFAULT
state.purchaseCurrencies = [USDC_CURRENCY_DEFAULT]
state.paymentCurrencies = []
state.paymentAmount = undefined
state.purchaseAmount = undefined
state.quotesLoading = false
}
}
19 changes: 6 additions & 13 deletions packages/core/src/controllers/TransactionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface TransactionsControllerState {
// -- State --------------------------------------------- //
const state = proxy<TransactionsControllerState>({
transactions: [],
coinbaseTransactions: [],
coinbaseTransactions: {},
transactionsByYear: {},
loading: false,
empty: false,
Expand Down Expand Up @@ -93,27 +93,20 @@ export const TransactionsController = {
transactionsMap: TransactionByYearMap = {},
transactions: Transaction[] = []
) {
const grouped: TransactionByYearMap = transactionsMap

const grouped = transactionsMap
transactions.forEach(transaction => {
const year = new Date(transaction.metadata.minedAt).getFullYear()
const month = new Date(transaction.metadata.minedAt).getMonth()

const yearTransactions = grouped[year] ?? {}
const monthTransactions = yearTransactions[month] ?? []

if (
monthTransactions.find(
t =>
t.metadata.hash === transaction.metadata.hash &&
t.metadata.status === transaction.metadata.status
)
) {
return
}
// If there's a transaction with the same id, remove the old one
const newMonthTransactions = monthTransactions.filter(tx => tx.id !== transaction.id)

grouped[year] = {
...yearTransactions,
[month]: [...monthTransactions, transaction].sort(
[month]: [...newMonthTransactions, transaction].sort(
(a, b) => new Date(b.metadata.minedAt).getTime() - new Date(a.metadata.minedAt).getTime()
)
}
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/utils/ConstantsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export const ConstantsUtil = {
'polygon',
'avalanche-c-chain',
'optimism',
'celo'
'celo',
'base'
],

WC_COINBASE_PAY_SDK_FALLBACK_CHAIN: 'ethereum',
Expand All @@ -59,7 +60,8 @@ export const ConstantsUtil = {
Polygon: 'polygon',
Avalanche: 'avalanche-c-chain',
'OP Mainnet': 'optimism',
Celo: 'celo'
Celo: 'celo',
Base: 'base'
},

WC_COINBASE_ONRAMP_APP_ID: 'bf18c88d-495a-463b-b249-0b9d3656cf5e'
Expand Down
151 changes: 151 additions & 0 deletions packages/core/tests/constants/OnrampTransactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
export const ONRAMP_TRANSACTIONS_RESPONSES_JAN = {
SUCCESS: {
id: '1eeccf2f-ef04-6d48-a2dd-0e1dca1d3cfb',
metadata: {
operationType: 'buy',
hash: '0xbf5f116e0e77b304404ff873b527578d8c0a247732a50b0da174a533b669ab5b',
minedAt: '2024-01-15T16:59:37.345Z',
sentFrom: 'Coinbase',
sentTo: '0xf3ea39310011333095CFCcCc7c4Ad74034CABA64',
status: 'ONRAMP_TRANSACTION_STATUS_SUCCESS',
nonce: 1,
chain: 'eip155:137'
},
transfers: [
{
fungible_info: {
name: 'USDC',
symbol: 'USDC'
},
direction: 'in',
quantity: {
numeric: '3.003898'
}
}
]
},
FAILED: {
id: '1eeccf2f-ef04-6d48-a2dd-0e1dca1d3cfb',
metadata: {
operationType: 'buy',
hash: '',
minedAt: '2024-01-15T16:59:37.345Z',
sentFrom: 'Coinbase',
sentTo: '0xf3ea39310011333095CFCcCc7c4Ad74034CABA64',
status: 'ONRAMP_TRANSACTION_STATUS_FAILED',
nonce: 1
},
transfers: [
{
fungible_info: {
name: 'USDC',
symbol: 'USDC'
},
direction: 'in',
quantity: {
numeric: '4.995375'
}
}
]
},
IN_PROGRESS: {
id: '1eeccf2f-ef04-6d48-a2dd-0e1dca1d3cfb',
metadata: {
operationType: 'buy',
hash: '',
minedAt: '2024-01-15T16:59:37.345Z',
sentFrom: 'Coinbase',
sentTo: '0xf3ea39310011333095CFCcCc7c4Ad74034CABA64',
status: 'ONRAMP_TRANSACTION_STATUS_IN_PROGRESS',
nonce: 1
},
transfers: [
{
fungible_info: {
name: 'USDC',
symbol: 'USDC'
},
direction: 'in',
quantity: {
numeric: '4.995375'
}
}
]
}
}

export const ONRAMP_TRANSACTIONS_RESPONSES_FEB = {
SUCCESS: {
id: '1eecc239-9ed5-696e-afeb-129d128962f1',
metadata: {
operationType: 'buy',
hash: '0xbf5f116e0e77b304404ff873b527578d8c0a247732a50b0da174a533b669ab5b',
minedAt: '2024-02-15T16:59:37.345Z',
sentFrom: 'Coinbase',
sentTo: '0xf3ea39310011333095CFCcCc7c4Ad74034CABA64',
status: 'ONRAMP_TRANSACTION_STATUS_SUCCESS',
nonce: 1,
chain: 'eip155:137'
},
transfers: [
{
fungible_info: {
name: 'USDC',
symbol: 'USDC'
},
direction: 'in',
quantity: {
numeric: '3.003898'
}
}
]
},
FAILED: {
id: '1eecc239-9ed5-696e-afeb-129d128962f1',
metadata: {
operationType: 'buy',
hash: '',
minedAt: '2024-02-15T16:59:37.345Z',
sentFrom: 'Coinbase',
sentTo: '0xf3ea39310011333095CFCcCc7c4Ad74034CABA64',
status: 'ONRAMP_TRANSACTION_STATUS_FAILED',
nonce: 1
},
transfers: [
{
fungible_info: {
name: 'USDC',
symbol: 'USDC'
},
direction: 'in',
quantity: {
numeric: '4.995375'
}
}
]
},
IN_PROGRESS: {
id: '1eecc239-9ed5-696e-afeb-129d128962f1',
metadata: {
operationType: 'buy',
hash: '',
minedAt: '2024-02-15T16:59:37.345Z',
sentFrom: 'Coinbase',
sentTo: '0xf3ea39310011333095CFCcCc7c4Ad74034CABA64',
status: 'ONRAMP_TRANSACTION_STATUS_IN_PROGRESS',
nonce: 1
},
transfers: [
{
fungible_info: {
name: 'USDC',
symbol: 'USDC'
},
direction: 'in',
quantity: {
numeric: '4.995375'
}
}
]
}
}
3 changes: 2 additions & 1 deletion packages/core/tests/controllers/AssetController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ describe('AssetController', () => {
walletImages: {},
networkImages: {},
connectorImages: {},
tokenImages: {}
tokenImages: {},
currencyImages: {}
})
})
})