Skip to content

Commit

Permalink
Retry failed receive if mint was offline
Browse files Browse the repository at this point in the history
  • Loading branch information
minibits-cash committed Mar 1, 2024
1 parent 8162468 commit 80a4aff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minibits_wallet",
"version": "0.1.6-beta.29",
"version": "0.1.6-beta.30",
"private": true,
"scripts": {
"android:clean": "cd android && ./gradlew clean",
Expand Down
31 changes: 18 additions & 13 deletions src/screens/TranDetailScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ const ReceiveInfoBlock = function (props: {
} = props

const isInternetReachable = useIsInternetReachable()
const tokenToRetry = getTokenToRetryToReceive(transaction)
const {transactionsStore} = useStores()
const retryResult = getTokenToRetryToReceive(transaction)
const {transactionsStore, mintsStore} = useStores()

const [isResultModalVisible, setIsResultModalVisible] = useState<boolean>(false)
const [resultModalInfo, setResultModalInfo] = useState<
Expand All @@ -432,17 +432,25 @@ const ReceiveInfoBlock = function (props: {
setIsResultModalVisible(previousState => !previousState)

const onRetryToReceive = async function () {
if(!tokenToRetry || !isInternetReachable) {
if(!retryResult || !isInternetReachable) {
return
}

setIsLoading(true)

try {
try {
const {tokenToRetry, increaseProofsCounter} = retryResult
const amountToReceive = CashuUtils.getTokenAmounts(tokenToRetry).totalAmount
const memo = tokenToRetry.memo || ''
const encoded = getEncodedToken(tokenToRetry)

if(increaseProofsCounter) {
const mintInstance = mintsStore.findByUrl(transaction.mint)
if(mintInstance) {
mintInstance.increaseProofsCounter(20)
}
}

const result: TransactionResult = await Wallet.receive(
tokenToRetry as Token,
amountToReceive,
Expand Down Expand Up @@ -517,7 +525,7 @@ const ReceiveInfoBlock = function (props: {
label="tranDetailScreen.type"
value={transaction.type as string}
/>
{tokenToRetry && isInternetReachable ? (
{retryResult && isInternetReachable ? (
<View
style={{flexDirection: 'row', justifyContent: 'space-between'}}>
<TranItem
Expand Down Expand Up @@ -1353,7 +1361,7 @@ const getEncodedTokenToSend = (

const getTokenToRetryToReceive = (
transaction: Transaction,
): Token | undefined => {
): {tokenToRetry: Token, increaseProofsCounter: boolean} | undefined => {
try {
if(transaction.type !== (TransactionType.RECEIVE || TransactionType.RECEIVE_OFFLINE)) {
return undefined
Expand Down Expand Up @@ -1386,15 +1394,12 @@ const getTokenToRetryToReceive = (
if(params) {
const {errorToken, message} = params

log.trace('[getTokenToRetryToReceive] message', message)

if(message.includes('Network request failed') || message.includes('Bad Gateway')) {
return errorToken as Token | undefined
return {tokenToRetry: errorToken, increaseProofsCounter: false}
}

if(message.includes('outputs have already been signed before')) {
mintInstance.increaseProofsCounter(20)
return errorToken
if(message.includes('outputs have already been signed before')) {
return {tokenToRetry: errorToken, increaseProofsCounter: true}
}

return undefined
Expand Down

0 comments on commit 80a4aff

Please sign in to comment.