Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(synapse-interface): disable input pending wallet #2738

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ export const InputContainer = () => {
const dispatch = useAppDispatch()
const { chain, isConnected } = useAccount()
const { balances } = usePortfolioState()
const { fromChainId, toChainId, fromToken, toToken, fromValue } =
useBridgeState()
const {
fromChainId,
toChainId,
fromToken,
toToken,
fromValue,
isWalletPending,
} = useBridgeState()
const [showValue, setShowValue] = useState('')
const [hasMounted, setHasMounted] = useState(false)

Expand Down Expand Up @@ -152,6 +158,7 @@ export const InputContainer = () => {
inputRef={inputRef}
showValue={showValue}
handleFromValueChange={handleFromValueChange}
disabled={isWalletPending}
/>
<AvailableBalance
balance={formattedBalance}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ import {
setFromToken,
setToChainId,
setToToken,
} from '@/slices/bridge/reducer'
import {
updateFromValue,
setBridgeQuote,
setIsLoading,
setIsWalletPending,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

Please ensure that the Redux action setIsWalletPending is appropriately documented and tested, given its critical role in state management.

  • No test cases involving setIsWalletPending were found in the codebase.
  • Documentation for setIsWalletPending was not found near its definition.

Please add relevant documentation and test cases for setIsWalletPending to ensure proper coverage and clarity.

Analysis chain

Please ensure that the Redux action setIsWalletPending is appropriately documented and tested, given its critical role in state management.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify if `setIsWalletPending` is covered by unit tests.

# Test: Search for test cases involving `setIsWalletPending`.
rg --type typescript $'setIsWalletPending' --glob '*test.ts'

Length of output: 94



Script:

#!/bin/bash
# Description: Verify if `setIsWalletPending` is covered by unit tests.

# Test: Search for test cases involving `setIsWalletPending`.
rg 'setIsWalletPending' --glob '*.ts' --glob '*.tsx'

Length of output: 755


Script:

#!/bin/bash
# Description: Verify if `setIsWalletPending` is documented.

# Search for the definition of `setIsWalletPending` in the codebase.
rg 'setIsWalletPending' --glob '*.ts' --glob '*.tsx'

Length of output: 755

setDestinationAddress,
} from '@/slices/bridge/reducer'
import {
Expand Down Expand Up @@ -94,12 +93,12 @@ const StateManagedBridge = () => {
debouncedFromValue,
destinationAddress,
isLoading: isQuoteLoading,
isWalletPending,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usage of the isWalletPending state variable directly affects the UI's responsiveness to wallet state changes. Consider adding a fallback or error state if the wallet status cannot be determined, to enhance robustness.

}: BridgeState = useBridgeState()
const { showSettingsSlideOver, showDestinationAddress } = useSelector(
(state: RootState) => state.bridgeDisplay
)

const [isWalletPending, setIsWalletPending] = useState<boolean>(false)
const [isApproved, setIsApproved] = useState<boolean>(false)

const dispatch = useAppDispatch()
Expand Down Expand Up @@ -327,6 +326,7 @@ const StateManagedBridge = () => {

const approveTxn = async () => {
try {
dispatch(setIsWalletPending(true))
const tx = approveToken(
bridgeQuote?.routerAddress,
fromChainId,
Expand All @@ -338,6 +338,8 @@ const StateManagedBridge = () => {
getAndSetBridgeQuote()
} catch (error) {
return txErrorHandler(error)
} finally {
dispatch(setIsWalletPending(false))
}
}

Expand Down Expand Up @@ -377,7 +379,7 @@ const StateManagedBridge = () => {
})
)
try {
setIsWalletPending(true)
dispatch(setIsWalletPending(true))
const wallet = await getWalletClient(wagmiConfig, {
chainId: fromChainId,
})
Expand Down Expand Up @@ -524,7 +526,7 @@ const StateManagedBridge = () => {

return txErrorHandler(error)
} finally {
setIsWalletPending(false)
dispatch(setIsWalletPending(false))
}
}

Expand Down
6 changes: 6 additions & 0 deletions packages/synapse-interface/slices/bridge/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface BridgeState {
toTokensBridgeQuotes: BridgeQuoteResponse[]
toTokensBridgeQuotesStatus: FetchState
isLoading: boolean
isWalletPending: boolean
deadlineMinutes: number | null
destinationAddress: Address | null
}
Expand Down Expand Up @@ -71,6 +72,7 @@ export const initialState: BridgeState = {
toTokensBridgeQuotes: [],
toTokensBridgeQuotesStatus: FetchState.IDLE,
isLoading: false,
isWalletPending: false,
deadlineMinutes: null,
destinationAddress: null,
}
Expand All @@ -82,6 +84,9 @@ export const bridgeSlice = createSlice({
setIsLoading: (state, action: PayloadAction<boolean>) => {
state.isLoading = action.payload
},
setIsWalletPending: (state, action: PayloadAction<boolean>) => {
state.isWalletPending = action.payload
},
setFromChainId: (state, action: PayloadAction<number>) => {
const incomingFromChainId = action.payload

Expand Down Expand Up @@ -509,6 +514,7 @@ export const {
setDeadlineMinutes,
setDestinationAddress,
setIsLoading,
setIsWalletPending,
resetBridgeInputs,
clearDestinationAddress,
resetFetchedBridgeQuotes,
Expand Down
Loading