Skip to content

Commit

Permalink
get next seq
Browse files Browse the repository at this point in the history
  • Loading branch information
HoangNDM committed Dec 19, 2023
1 parent 6ecda2e commit 410d941
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 43 deletions.
1 change: 1 addition & 0 deletions src/components/FeeAndSequence/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function FeeAndSequence({
useEffect(() => {
setSequence(nextQueueSeq)
}, [nextQueueSeq])

useEffect(() => {
recalculateFee()
}, [manualGasLimit])
Expand Down
22 changes: 15 additions & 7 deletions src/logic/safe/store/actions/fetchSafe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { SafeRecordProps } from 'src/logic/safe/store/models/safe'
import { getLocalSafe } from 'src/logic/safe/utils'
import { getSafeInfo } from 'src/logic/safe/utils/safeInformation'
import { fetchMSafeTokens } from 'src/logic/tokens/store/actions/fetchSafeTokens'
import { fetchAccountInfo, getAccountAsset, getMSafeInfo } from 'src/services'
import { fetchAccountInfo, getAccountAsset, getMSafeInfo, getMSafeNextSeq } from 'src/services'
import { IMSafeInfo } from 'src/types/safe'
import { humanReadableValue } from 'src/utils'
import { checksumAddress } from 'src/utils/checksumAddress'
Expand Down Expand Up @@ -143,9 +143,10 @@ export const fetchMSafe =
let mSafeInfo: IMSafeInfo | null = null
let accountInfo: SequenceResponse | null = null
let isSafeLoaded = false
let nextQueueSeq = ''

try {
;[mSafeInfo, remoteSafeInfo, accountInfo, isSafeLoaded] = await _getSafeInfo(safeAddress, safeId)
;[mSafeInfo, remoteSafeInfo, accountInfo, isSafeLoaded, nextQueueSeq] = await _getSafeInfo(safeAddress, safeId)
} catch (err) {
console.error(err)
}
Expand All @@ -164,7 +165,7 @@ export const fetchMSafe =
safeInfo = await extractRemoteSafeInfo(remoteSafeInfo)
const onlineData: SequenceResponse | null = accountInfo

safeInfo.nextQueueSeq = mSafeInfo?.nextQueueSeq || onlineData?.sequence?.toString()
safeInfo.nextQueueSeq = nextQueueSeq || onlineData?.sequence?.toString()
safeInfo.sequence = mSafeInfo?.sequence || onlineData?.sequence?.toString()
const coinDecimal = getCoinDecimal()
const { txQueuedTag, txHistoryTag, balances } = currentSafeWithNames(state)
Expand Down Expand Up @@ -217,18 +218,25 @@ export const fetchMSafe =
async function _getSafeInfo(
safeAddress: string,
safeId: number,
): Promise<[IMSafeInfo, SafeInfo, SequenceResponse, boolean]> {
): Promise<[IMSafeInfo, SafeInfo, SequenceResponse, boolean, string]> {
const getAccountAssetPromise = getAccountAsset(safeAddress)
const getMSafeInfoPromise = getMSafeInfo(safeId)
const getAccountInfoPromise = fetchAccountInfo(safeAddress)
const getMSafeNextSeqPromise = getMSafeNextSeq(safeId)

const results = await Promise.allSettled([getAccountAssetPromise, getMSafeInfoPromise, getAccountInfoPromise])
const results = await Promise.allSettled([
getAccountAssetPromise,
getMSafeInfoPromise,
getAccountInfoPromise,
getMSafeNextSeqPromise,
])

const [accountAssetDataResult, mSafeInfotDataResult, accountInfoDataResult] = results
const [accountAssetDataResult, mSafeInfotDataResult, accountInfoDataResult, nextQueueSeqResult] = results

const accountAssetData = accountAssetDataResult.status === 'fulfilled' ? accountAssetDataResult.value : null
const mSafeInfotData = mSafeInfotDataResult.status === 'fulfilled' ? mSafeInfotDataResult.value : null
const accountInfoData = accountInfoDataResult.status === 'fulfilled' ? accountInfoDataResult.value : null
const nextQueueSeq = nextQueueSeqResult.status === 'fulfilled' ? nextQueueSeqResult.value : ''

if (!mSafeInfotData) {
throw new Error('Get Safe Info failed')
Expand Down Expand Up @@ -316,5 +324,5 @@ async function _getSafeInfo(
txHistoryTag: mSafeInfotData.txHistoryTag,
}

return [formatMSafeInfotData, safeInfoData, accountInfoData, isSafeLoaded]
return [formatMSafeInfotData, safeInfoData, accountInfoData, isSafeLoaded, nextQueueSeq]
}
8 changes: 4 additions & 4 deletions src/pages/Transactions/TxActionModal/ClaimReward/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ export default function Execute({ open, onClose, data, sendTx, rejectTx, disable
action == 'confirm'
? txHandler('confirm')
: action == 'reject'
? rejectTx()
: action == 'change-sequence'
? txHandler('change-sequence')
: sendTx()
? rejectTx()
: action == 'change-sequence'
? txHandler('change-sequence')
: sendTx()
}}
disabled={disabled || +sequence < +currentSequence}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ export default function Execute({ open, onClose, data, sendTx, rejectTx, disable
action == 'confirm'
? txHandler('confirm')
: action == 'reject'
? rejectTx()
: action == 'change-sequence'
? txHandler('change-sequence')
: sendTx()
? rejectTx()
: action == 'change-sequence'
? txHandler('change-sequence')
: sendTx()
}}
disabled={disabled || +sequence < +currentSequence}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ export default function Execute({ open, onClose, data, sendTx, rejectTx, disable
action == 'confirm'
? txHandler('confirm')
: action == 'reject'
? rejectTx()
: action == 'change-sequence'
? txHandler('change-sequence')
: sendTx()
? rejectTx()
: action == 'change-sequence'
? txHandler('change-sequence')
: sendTx()
}}
disabled={disabled || +sequence < +currentSequence}
>
Expand Down
8 changes: 4 additions & 4 deletions src/pages/Transactions/TxActionModal/Delegate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ export default function Execute({ open, onClose, data, sendTx, rejectTx, disable
action == 'confirm'
? txHandler('confirm')
: action == 'reject'
? rejectTx()
: action == 'change-sequence'
? txHandler('change-sequence')
: sendTx()
? rejectTx()
: action == 'change-sequence'
? txHandler('change-sequence')
: sendTx()
}}
disabled={disabled || +sequence < +currentSequence}
>
Expand Down
8 changes: 4 additions & 4 deletions src/pages/Transactions/TxActionModal/MultiSend/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ export default function Execute({ open, onClose, data, sendTx, rejectTx, disable
action == 'confirm'
? txHandler('confirm')
: action == 'reject'
? rejectTx()
: action == 'change-sequence'
? txHandler('change-sequence')
: sendTx()
? rejectTx()
: action == 'change-sequence'
? txHandler('change-sequence')
: sendTx()
}}
disabled={disabled || +sequence < +currentSequence}
>
Expand Down
8 changes: 4 additions & 4 deletions src/pages/Transactions/TxActionModal/Redelegate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ export default function Execute({ open, onClose, data, sendTx, rejectTx, disable
action == 'confirm'
? txHandler('confirm')
: action == 'reject'
? rejectTx()
: action == 'change-sequence'
? txHandler('change-sequence')
: sendTx()
? rejectTx()
: action == 'change-sequence'
? txHandler('change-sequence')
: sendTx()
}}
disabled={disabled || +sequence < +currentSequence}
>
Expand Down
8 changes: 4 additions & 4 deletions src/pages/Transactions/TxActionModal/Send/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ export default function Execute({ open, onClose, data, sendTx, rejectTx, disable
action == 'confirm'
? txHandler('confirm')
: action == 'reject'
? rejectTx()
: action == 'change-sequence'
? txHandler('change-sequence')
: sendTx()
? rejectTx()
: action == 'change-sequence'
? txHandler('change-sequence')
: sendTx()
}}
disabled={disabled || +sequence < +currentSequence}
>
Expand Down
8 changes: 4 additions & 4 deletions src/pages/Transactions/TxActionModal/Undelegate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ export default function Execute({ open, onClose, data, sendTx, rejectTx, disable
action == 'confirm'
? txHandler('confirm')
: action == 'reject'
? rejectTx()
: action == 'change-sequence'
? txHandler('change-sequence')
: sendTx()
? rejectTx()
: action == 'change-sequence'
? txHandler('change-sequence')
: sendTx()
}}
disabled={disabled || +sequence < +currentSequence}
>
Expand Down
8 changes: 4 additions & 4 deletions src/pages/Transactions/TxActionModal/Vote/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ export default function Execute({ open, onClose, data, sendTx, rejectTx, disable
action == 'confirm'
? txHandler('confirm')
: action == 'reject'
? rejectTx()
: action == 'change-sequence'
? txHandler('change-sequence')
: sendTx()
? rejectTx()
: action == 'change-sequence'
? txHandler('change-sequence')
: sendTx()
}}
disabled={disabled || +sequence < +currentSequence}
>
Expand Down
4 changes: 4 additions & 0 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ export async function getMSafeInfo(safeId: number): Promise<IMSafeInfo> {
return axios.get(`${baseUrl}/multisigwallet/${safeId}`).then((res) => res.data.Data)
}

export async function getMSafeNextSeq(safeId: number): Promise<string> {
return axios.get(`${baseUrl}/transaction/next-seq?safeId=${safeId}`).then((res) => res.data.nextSequence)
}

export async function getAccountAsset(safeAddress: string): Promise<any> {
const chainInfo = getChainInfo() as any
return axios
Expand Down

0 comments on commit 410d941

Please sign in to comment.