feat: poll payment status every 15s on my-listings page for pending transactions
This commit is contained in:
@@ -38,6 +38,50 @@ class PageMyListings extends HTMLElement {
|
|||||||
disconnectedCallback() {
|
disconnectedCallback() {
|
||||||
if (this.unsubscribe) this.unsubscribe()
|
if (this.unsubscribe) this.unsubscribe()
|
||||||
if (this.authUnsubscribe) this.authUnsubscribe()
|
if (this.authUnsubscribe) this.authUnsubscribe()
|
||||||
|
this.stopPolling()
|
||||||
|
}
|
||||||
|
|
||||||
|
startPolling() {
|
||||||
|
this.stopPolling()
|
||||||
|
const hasPending = this.listings.some(l =>
|
||||||
|
l.payment_status === 'processing' || l.payment_status === 'pending'
|
||||||
|
)
|
||||||
|
if (hasPending) {
|
||||||
|
this.pollInterval = setInterval(() => this.pollListings(), 15000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stopPolling() {
|
||||||
|
if (this.pollInterval) {
|
||||||
|
clearInterval(this.pollInterval)
|
||||||
|
this.pollInterval = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async pollListings() {
|
||||||
|
try {
|
||||||
|
const user = await auth.getUser()
|
||||||
|
if (!user) return
|
||||||
|
|
||||||
|
const response = await directus.getListings({
|
||||||
|
fields: [
|
||||||
|
'id', 'status', 'title', 'slug', 'price', 'currency',
|
||||||
|
'condition', 'payment_status', 'date_created', 'user_created',
|
||||||
|
'images.directus_files_id.id',
|
||||||
|
'location.id', 'location.name'
|
||||||
|
],
|
||||||
|
filter: {
|
||||||
|
user_created: { _eq: user.id }
|
||||||
|
},
|
||||||
|
sort: ['-date_created'],
|
||||||
|
limit: 50
|
||||||
|
})
|
||||||
|
this.listings = response.items || []
|
||||||
|
this.updateContent()
|
||||||
|
this.startPolling()
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Polling failed:', err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadMyListings() {
|
async loadMyListings() {
|
||||||
@@ -65,6 +109,7 @@ class PageMyListings extends HTMLElement {
|
|||||||
this.listings = response.items || []
|
this.listings = response.items || []
|
||||||
this.loading = false
|
this.loading = false
|
||||||
this.updateContent()
|
this.updateContent()
|
||||||
|
this.startPolling()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to load my listings:', err)
|
console.error('Failed to load my listings:', err)
|
||||||
this.error = err.message
|
this.error = err.message
|
||||||
|
|||||||
Reference in New Issue
Block a user