Skip to content

Commit

Permalink
Merge branch 'chore/onramp-bugbash' of github.com:WalletConnect/web3m…
Browse files Browse the repository at this point in the history
…odal into chore/onramp-bugbash
  • Loading branch information
tomiir committed Feb 21, 2024
2 parents cdca1ba + 3bb43e8 commit a09b3fc
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions packages/scaffold/src/views/w3m-buy-in-progress-view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class W3mBuyInProgressView extends LitElement {

@state() private error = false

@state() private intervalId: NodeJS.Timeout | null = null
@state() private intervalId?: NodeJS.Timeout

@state() private startTime: number | null = null

Expand Down Expand Up @@ -147,39 +147,37 @@ export class W3mBuyInProgressView extends LitElement {

private async watchCoinbaseTransactions() {
try {
await this.fetchCoinbaseTransactions()
const address = AccountController.state.address
const projectId = OptionsController.state.projectId
if (!address) {
throw new Error('No address found')
}

const coinbaseResponse = await BlockchainApiController.fetchTransactions({
account: address,
onramp: 'coinbase',
projectId
})

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

if (newTransactions.length) {
clearInterval(this.intervalId)
RouterController.replace('OnRampActivity')
} else if (this.startTime && Date.now() - this.startTime >= 180_000) {
clearInterval(this.intervalId)
this.error = true
}
} catch (error) {
SnackController.showError(error)
}
}

private async fetchCoinbaseTransactions() {
const address = AccountController.state.address
const projectId = OptionsController.state.projectId
if (!address) {
throw new Error('No address found')
}

const coinbaseResponse = await BlockchainApiController.fetchTransactions({
account: address,
onramp: 'coinbase',
projectId
})

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 (newTransactions.length && this.intervalId) {
clearInterval(this.intervalId)
RouterController.replace('OnRampActivity')
} else if (this.startTime && Date.now() - this.startTime >= 180_000 && this.intervalId) {
clearInterval(this.intervalId)
this.error = true
}
}

private onTryAgain() {
if (!this.selectedOnRampProvider) {
return
Expand Down

0 comments on commit a09b3fc

Please sign in to comment.