Skip to content

Commit 1e61246

Browse files
authored
Merge pull request #269 from oasisprotocol/lw/catch-timeout
Catch timeout error in waitForTransactionReceipt
2 parents e22f2e1 + 2965526 commit 1e61246

File tree

3 files changed

+45
-51
lines changed

3 files changed

+45
-51
lines changed

.changelog/269.bugfix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Catch timeout error in waitForTransactionReceipt

stake/src/pages/StakingAmountPage/index.tsx

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,32 +94,31 @@ const StakingAmountPageCmp: FC = () => {
9494
const sapphireAmount = NumberUtils.consensusAmountToSapphireAmount(value)
9595
setStep(Steps.DelegateInProgress)
9696

97-
sendTransactionAsync(await populateDelegateTx(sapphireAmount, to, gasPriceSnapshot), {
98-
onSuccess: async hash => {
99-
await getTransactionReceipt(hash)
100-
101-
const [delegations] = await Promise.all([fetchDelegations(), fetchValidators()])
102-
103-
// This should work in 99% of cases!
104-
const [diff] = delegations.filter(
105-
d =>
106-
!prevDelegations.some(prevD => {
107-
return FormattingUtils.serializeObj(prevD) === FormattingUtils.serializeObj(d)
108-
})
109-
)
97+
try {
98+
const hash = await sendTransactionAsync(await populateDelegateTx(sapphireAmount, to, gasPriceSnapshot))
99+
100+
await getTransactionReceipt(hash)
101+
102+
const [delegations] = await Promise.all([fetchDelegations(), fetchValidators()])
110103

111-
if (!diff) {
112-
setError('Unable to retrieve stake! Navigate to dashboard, and continue from there.')
113-
setStep(Steps.DelegateFailed)
114-
}
104+
// This should work in 99% of cases!
105+
const [diff] = delegations.filter(
106+
d =>
107+
!prevDelegations.some(prevD => {
108+
return FormattingUtils.serializeObj(prevD) === FormattingUtils.serializeObj(d)
109+
})
110+
)
115111

116-
setStep(Steps.DelegateSuccessful)
117-
},
118-
onError: e => {
119-
setError(toErrorString(e as Error))
112+
if (!diff) {
113+
setError('Unable to retrieve stake! Navigate to dashboard, and continue from there.')
120114
setStep(Steps.DelegateFailed)
121-
},
122-
})
115+
}
116+
117+
setStep(Steps.DelegateSuccessful)
118+
} catch (e) {
119+
setError(toErrorString(e as Error))
120+
setStep(Steps.DelegateFailed)
121+
}
123122
}
124123

125124
const getAmountFromPercentage = (accountBalance => (percentage: number) => {

stake/src/pages/UnstakePage/index.tsx

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -125,37 +125,31 @@ const UnstakePageCmp: FC = () => {
125125
setError('')
126126
setStep(Steps.UndelegateInProgress)
127127

128-
sendTransactionAsync(await populateUndelegateTx(amountShares, to, gasPrice!), {
129-
onSuccess: async hash => {
130-
await getTransactionReceipt(hash)
131-
132-
const [undelegations] = await Promise.all([
133-
fetchUndelegations(),
134-
fetchDelegations(),
135-
fetchValidators(),
136-
])
137-
138-
// This should work in 99% of cases!
139-
const [diff] = undelegations.filter(
140-
und =>
141-
!prevUndelegations.some(prevUnd => {
142-
return FormattingUtils.serializeObj(prevUnd) === FormattingUtils.serializeObj(und)
143-
})
144-
)
128+
try {
129+
const hash = await sendTransactionAsync(await populateUndelegateTx(amountShares, to, gasPrice!))
130+
await getTransactionReceipt(hash)
131+
132+
const [undelegations] = await Promise.all([fetchUndelegations(), fetchDelegations(), fetchValidators()])
133+
134+
// This should work in 99% of cases!
135+
const [diff] = undelegations.filter(
136+
und =>
137+
!prevUndelegations.some(prevUnd => {
138+
return FormattingUtils.serializeObj(prevUnd) === FormattingUtils.serializeObj(und)
139+
})
140+
)
145141

146-
if (!diff) {
147-
throw new Error('Unable to retrieve unstake! Navigate to dashboard, and continue from there.')
148-
}
142+
if (!diff) {
143+
throw new Error('Unable to retrieve unstake! Navigate to dashboard, and continue from there.')
144+
}
149145

150-
setUndelegationEpoch(diff.epoch)
146+
setUndelegationEpoch(diff.epoch)
151147

152-
setStep(Steps.UndelegateSuccessful)
153-
},
154-
onError: e => {
155-
setError(toErrorString(e as Error))
156-
setStep(Steps.UndelegateFailed)
157-
},
158-
})
148+
setStep(Steps.UndelegateSuccessful)
149+
} catch (e) {
150+
setError(toErrorString(e as Error))
151+
setStep(Steps.UndelegateFailed)
152+
}
159153
}
160154

161155
const getAmountFromPercentage = (delegationShares => (percentage: number) => {

0 commit comments

Comments
 (0)