Skip to content

Commit 884625c

Browse files
committed
Don't stop sync on errors
1 parent a9c5b73 commit 884625c

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/actions/sync.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import cryptoassets from '@liquality/cryptoassets'
22
import { getClient } from '../services/chainClient'
33
import { sleep } from '../utils/async'
44
import { actions as transactionActions } from './transactions'
5+
import { actions as errorActions } from './errors'
56
import { getFundExpiration, getExpirationForParty, getClaimExpiration } from '../utils/expiration'
67
import config from '../config'
78

@@ -20,6 +21,15 @@ function setSynced (party, synced) {
2021
return { type: types.SET_SYNCED, party, synced }
2122
}
2223

24+
async function catchSwapCallError (func, dispatch) {
25+
try {
26+
const result = await func()
27+
return result
28+
} catch (e) {
29+
dispatch(errorActions.setError(e))
30+
}
31+
}
32+
2333
async function findInitiateSwapTransaction (party, blockNumber, dispatch, getState) {
2434
const {
2535
assets: { [party]: { currency, value } },
@@ -31,7 +41,9 @@ async function findInitiateSwapTransaction (party, blockNumber, dispatch, getSta
3141
const client = getClient(currency, type)
3242
const valueInUnit = cryptoassets[currency].currencyToUnit(value).toNumber() // TODO: This should be passed as BigNumber
3343
const swapExpiration = getFundExpiration(expiration, party).time
34-
const initiateTransaction = await client.swap.findInitiateSwapTransaction(valueInUnit, addresses[0], counterParty[party].address, secretParams.secretHash, swapExpiration.unix(), blockNumber)
44+
const initiateTransaction = await catchSwapCallError(async () =>
45+
client.swap.findInitiateSwapTransaction(valueInUnit, addresses[0], counterParty[party].address, secretParams.secretHash, swapExpiration.unix(), blockNumber),
46+
dispatch)
3547
if (initiateTransaction) {
3648
dispatch(transactionActions.setTransaction(party, 'fund', initiateTransaction))
3749
}
@@ -52,7 +64,9 @@ async function findClaimSwapTransaction (party, blockNumber, dispatch, getState)
5264
const swapExpiration = getExpirationForParty(expiration, oppositeParty, isPartyB).time
5365
const recipientAddress = oppositeParty === 'a' ? counterParty[oppositeParty].address : wallets[oppositeParty].addresses[0]
5466
const refundAddress = oppositeParty === 'a' ? wallets[oppositeParty].addresses[0] : counterParty[oppositeParty].address
55-
const claimTransaction = await client.swap.findClaimSwapTransaction(transactions[oppositeParty].fund.hash, recipientAddress, refundAddress, secretParams.secretHash, swapExpiration.unix(), blockNumber)
67+
const claimTransaction = await catchSwapCallError(async () =>
68+
client.swap.findClaimSwapTransaction(transactions[oppositeParty].fund.hash, recipientAddress, refundAddress, secretParams.secretHash, swapExpiration.unix(), blockNumber),
69+
dispatch)
5670
if (claimTransaction) {
5771
dispatch(transactionActions.setTransaction(party, 'claim', claimTransaction))
5872
}
@@ -75,7 +89,9 @@ async function findRefundSwapTransaction (party, blockNumber, dispatch, getState
7589
} else {
7690
swapExpiration = isPartyB ? expiration : getFundExpiration(expiration, 'b').time
7791
}
78-
const refundTransaction = await client.swap.findRefundSwapTransaction(transactions[party].fund.hash, counterParty[party].address, wallets[party].addresses[0], secretParams.secretHash, swapExpiration.unix(), blockNumber)
92+
const refundTransaction = await catchSwapCallError(async () =>
93+
client.swap.findRefundSwapTransaction(transactions[party].fund.hash, counterParty[party].address, wallets[party].addresses[0], secretParams.secretHash, swapExpiration.unix(), blockNumber),
94+
dispatch)
7995
if (refundTransaction) {
8096
dispatch(transactionActions.setTransaction(party, 'refund', refundTransaction))
8197
}
@@ -94,7 +110,9 @@ async function verifyInitiateSwapTransaction (dispatch, getState) {
94110
const client = getClient(currency, type)
95111
const valueInUnit = cryptoassets[currency].currencyToUnit(value).toNumber() // TODO: This should be passed as BigNumber
96112
const swapExpiration = isPartyB ? expiration : getClaimExpiration(expiration, 'a').time
97-
const swapVerified = await client.swap.verifyInitiateSwapTransaction(transactions.b.fund.hash, valueInUnit, addresses[0], counterParty.b.address, secretParams.secretHash, swapExpiration.unix())
113+
const swapVerified = await catchSwapCallError(async () =>
114+
client.swap.verifyInitiateSwapTransaction(transactions.b.fund.hash, valueInUnit, addresses[0], counterParty.b.address, secretParams.secretHash, swapExpiration.unix()),
115+
dispatch)
98116
if (swapVerified) {
99117
dispatch(transactionActions.setIsVerified(true))
100118
}

0 commit comments

Comments
 (0)