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: mobile/brave buy in progress #1943

Merged
merged 4 commits into from
Feb 20, 2024
Merged
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
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