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

PKG -- [fcl] Make errors accessible to subscribers from fcl.tx polling and throw for onceSealed, onceExecuted, onceFinalized #1243

Merged
merged 12 commits into from
Jun 14, 2022
5 changes: 5 additions & 0 deletions .changeset/seven-shoes-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/fcl": minor
---

Make errors accessible to subscribers from fcl.tx polling (txStatus.error) and throw for onceSealed, onceExecuted, onceFinalized. Remove retried polling requests as they are a redundancy already implemented by @onflow/transport-http
13 changes: 6 additions & 7 deletions packages/fcl/src/transaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ const isDiff = (cur, next) => {

const HANDLERS = {
[INIT]: async ctx => {
const tx = await fetchTxStatus(ctx.self())
if (!isSealed(tx)) setTimeout(() => ctx.sendSelf(POLL), RATE)
ctx.merge(tx)
ctx.sendSelf(POLL)
},
[SUBSCRIBE]: (ctx, letter) => {
ctx.subscribe(letter.from)
Expand All @@ -51,10 +49,10 @@ const HANDLERS = {
try {
tx = await fetchTxStatus(ctx.self())
} catch (e) {
console.error(e)
setTimeout(() => ctx.sendSelf(POLL), RATE)
ctx.merge({error: e})
return
}

if (!isSealed(tx)) setTimeout(() => ctx.sendSelf(POLL), RATE)
if (isDiff(ctx.all(), tx)) ctx.broadcast(UPDATED, tx)
ctx.merge(tx)
Expand Down Expand Up @@ -86,8 +84,9 @@ export function transaction(transactionId) {
const suppress = opts.suppress || false
return new Promise((resolve, reject) => {
const unsub = subscribe(txStatus => {
if (txStatus.statusCode && !suppress) {
reject(txStatus.errorMessage)
console.log(txStatus)
jribbink marked this conversation as resolved.
Show resolved Hide resolved
if ((txStatus.statusCode || txStatus.error) && !suppress) {
reject(txStatus.error || txStatus.errorMessage)
unsub()
} else if (predicate(txStatus)) {
resolve(txStatus)
Expand Down