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

fix: use start time to check for new transactions #1930

Closed
wants to merge 3 commits into from
Closed
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
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
16 changes: 12 additions & 4 deletions packages/scaffold/src/views/w3m-buy-in-progress-view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@

private async initializeCoinbaseTransactions() {
await this.watchCoinbaseTransactions()
this.intervalId = setInterval(() => this.watchCoinbaseTransactions(), 10000)
this.intervalId = setInterval(() => this.watchCoinbaseTransactions(), 4000)
}

private async watchCoinbaseTransactions() {
Expand All @@ -166,11 +166,19 @@
projectId
})

const pendingTransactions = coinbaseResponse.data.filter(
tx => tx.metadata.status === 'ONRAMP_TRANSACTION_STATUS_IN_PROGRESS'
console.log('Coinbase respnose')

Check failure on line 169 in packages/scaffold/src/views/w3m-buy-in-progress-view/index.ts

View workflow job for this annotation

GitHub Actions / code_style (lint)

Unexpected console statement
console.log(coinbaseResponse)

Check failure on line 170 in packages/scaffold/src/views/w3m-buy-in-progress-view/index.ts

View workflow job for this annotation

GitHub Actions / code_style (lint)

Unexpected console statement

console.log('Date of first render', this.startTime)

Check failure on line 172 in packages/scaffold/src/views/w3m-buy-in-progress-view/index.ts

View workflow job for this annotation

GitHub Actions / code_style (lint)

Unexpected console statement

const newTransactions = coinbaseResponse.data.filter(
// @ts-expect-error - start time will always be set at this point
tx => new Date(tx.metadata.minedAt) > new Date(this.startTime)
)

if (pendingTransactions.length && this.intervalId) {
console.log('New transactions', newTransactions)

Check failure on line 179 in packages/scaffold/src/views/w3m-buy-in-progress-view/index.ts

View workflow job for this annotation

GitHub Actions / code_style (lint)

Unexpected console statement

if (newTransactions.length && this.intervalId) {
clearInterval(this.intervalId)
RouterController.replace('OnRampActivity')
} else if (this.startTime && Date.now() - this.startTime >= 180_000 && this.intervalId) {
Expand Down
6 changes: 6 additions & 0 deletions packages/scaffold/src/views/w3m-onramp-activity-view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
clearTimeout(this.refetchTimeout)
},
TransactionsController.subscribe(val => {
console.log('Coinbase Transactions updated', val.coinbaseTransactions)

Check failure on line 48 in packages/scaffold/src/views/w3m-onramp-activity-view/index.ts

View workflow job for this annotation

GitHub Actions / code_style (lint)

Unexpected console statement
this.coinbaseTransactions = { ...val.coinbaseTransactions }
})
]
Expand Down Expand Up @@ -158,10 +159,14 @@
private refetchLoadingTransactions() {
const today = new Date()
const currentMonthTxs = this.coinbaseTransactions[today.getFullYear()]?.[today.getMonth()] || []

console.log('Activity - Current month transactions', currentMonthTxs)

Check failure on line 163 in packages/scaffold/src/views/w3m-onramp-activity-view/index.ts

View workflow job for this annotation

GitHub Actions / code_style (lint)

Unexpected console statement
const loadingTransactions = currentMonthTxs.filter(
transaction => transaction.metadata.status === 'ONRAMP_TRANSACTION_STATUS_IN_PROGRESS'
)

console.log('Activity - Loading Transactions', loadingTransactions)

Check failure on line 168 in packages/scaffold/src/views/w3m-onramp-activity-view/index.ts

View workflow job for this annotation

GitHub Actions / code_style (lint)

Unexpected console statement

if (loadingTransactions.length === 0) {
clearTimeout(this.refetchTimeout)

Expand All @@ -171,6 +176,7 @@
// Wait 2 seconds before refetching
this.refetchTimeout = setTimeout(async () => {
const address = AccountController.state.address
console.log('Refetching transactions')

Check failure on line 179 in packages/scaffold/src/views/w3m-onramp-activity-view/index.ts

View workflow job for this annotation

GitHub Actions / code_style (lint)

Unexpected console statement
await TransactionsController.fetchTransactions(address, 'coinbase')
this.refetchLoadingTransactions()
}, 3000)
Expand Down
Loading