-
Notifications
You must be signed in to change notification settings - Fork 360
Fix: deep-linked tx status and internal state #3156
Changes from all commits
e388b44
dd75f0c
0e4f943
86d3a3d
125e1bb
a7a3c19
a1cac28
6ac43b0
cd9e46d
c844524
de2f702
79563ab
0e3d8d3
609582f
9a39ff2
95002df
0eb232a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { useSelector } from 'react-redux' | ||
| import { TransactionStatus } from '@gnosis.pm/safe-react-gateway-sdk' | ||
| import { Transaction } from 'src/logic/safe/store/models/types/gateway.d' | ||
| import { AppReduxState } from 'src/store' | ||
| import { selectTxStatus } from 'src/logic/safe/store/selectors/txStatus' | ||
| import { useState } from 'react' | ||
| import { useDebounce } from './useDebounce' | ||
|
|
||
| const useLocalTxStatus = (transaction: Transaction): TransactionStatus => { | ||
| const storedStatus = useSelector((state: AppReduxState) => selectTxStatus(state, transaction)) | ||
| const [localStatus, setLocalStatus] = useState(storedStatus) | ||
|
|
||
| useDebounce(() => { | ||
| if (storedStatus) { | ||
| setLocalStatus(storedStatus) | ||
| } | ||
| }, 100) | ||
|
|
||
| return localStatus | ||
| } | ||
|
|
||
| export default useLocalTxStatus |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import { createAction } from 'redux-actions' | ||
|
|
||
| import { TransactionStatusPayload } from 'src/logic/safe/store/reducer/gatewayTransactions' | ||
| import { TransactionStatusPayload } from 'src/logic/safe/store/reducer/localTransactions' | ||
|
|
||
| export const UPDATE_TRANSACTION_STATUS = 'UPDATE_TRANSACTION_STATUS' | ||
| export const updateTransactionStatus = createAction<TransactionStatusPayload>(UPDATE_TRANSACTION_STATUS) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,8 @@ import { store as reduxStore } from 'src/store/index' | |
| import { HistoryPayload } from 'src/logic/safe/store/reducer/gatewayTransactions' | ||
| import { history, extractSafeAddress, generateSafeRoute, ADDRESSED_ROUTE, SAFE_ROUTES } from 'src/routes/routes' | ||
| import { getShortName } from 'src/config' | ||
| import { localStatuses } from '../selectors/txStatus' | ||
| import { currentChainId } from 'src/logic/config/store/selectors' | ||
|
|
||
| const watchedActions = [ADD_OR_UPDATE_SAFE, ADD_QUEUED_TRANSACTIONS, ADD_HISTORY_TRANSACTIONS] | ||
|
|
||
|
|
@@ -105,7 +107,23 @@ const notificationsMiddleware = | |
| const safesMap = safesAsMap(state) | ||
| const currentSafe = safesMap.get(safeAddress) | ||
|
|
||
| if (!currentSafe || !isUserAnOwner(currentSafe, userAddress) || awaitingTransactions.length === 0) { | ||
| const chainId = currentChainId(state) | ||
| const localStatusedSafeTxHashes = Object.keys(localStatuses(state)?.[chainId] || {}) | ||
|
|
||
| if (!localStatusedSafeTxHashes.length) { | ||
| break | ||
| } | ||
|
|
||
| const hasLocalStatus = transactions.some((tx) => | ||
| localStatusedSafeTxHashes.some((safeTxHash) => tx.id.includes(safeTxHash)), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Transaction summaries do not return the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it in a random place or can we extract the exact safeTxHash part and use it for a direct hash map lookup?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my understanding, it is the last part of the |
||
| ) | ||
|
|
||
| if ( | ||
| hasLocalStatus || | ||
| !currentSafe || | ||
| !isUserAnOwner(currentSafe, userAddress) || | ||
| awaitingTransactions.length === 0 | ||
| ) { | ||
| break | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to search the array or keys instead of just looking up the key in the hash map?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have the
safeTxHash. Please check my other response.