-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Refactor send page state management #10965
Changes from 1 commit
849ca6a
f7bb6c3
3d8ca2d
0320dff
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 |
---|---|---|
|
@@ -44,6 +44,7 @@ import { | |
hideLoadingIndication, | ||
showConfTxPage, | ||
showLoadingIndication, | ||
updateTokenType, | ||
updateTransaction, | ||
} from '../../store/actions'; | ||
import { | ||
|
@@ -831,6 +832,7 @@ const slice = createSlice({ | |
// 5. State is invalid if the send state is uninitialized | ||
// 6. State is invalid if gas estimates are loading | ||
// 7. State is invalid if gasLimit is less than the minimumGasLimit | ||
// 8. State is invalid if the selected asset is a ERC721 | ||
case Boolean(state.amount.error): | ||
case Boolean(state.gas.error): | ||
case state.asset.type === ASSET_TYPES.TOKEN && | ||
|
@@ -843,6 +845,10 @@ const slice = createSlice({ | |
): | ||
state.status = SEND_STATUSES.INVALID; | ||
break; | ||
case state.asset.type === ASSET_TYPES.TOKEN && | ||
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. not req but wondering if it makes sense to separate this out so that asset has an error field, as we do with amount and gas? 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. i was thinking that when I was working through erc721 updates, i think its a definite candidate for an improvement but not to be handled here. |
||
state.asset.details.isERC721: | ||
state.state = SEND_STATUSES.INVALID; | ||
break; | ||
default: | ||
state.status = SEND_STATUSES.VALID; | ||
// Recompute the draftTransaction object | ||
|
@@ -1078,6 +1084,11 @@ export function updateSendAsset({ type, details }) { | |
details, | ||
state.send.account.address ?? getSelectedAddress(state), | ||
); | ||
if (details && details.isERC721 === undefined) { | ||
const updatedAssetDetails = await updateTokenType(details.address); | ||
details.isERC721 = updatedAssetDetails.isERC721; | ||
} | ||
|
||
await dispatch(hideLoadingIndication()); | ||
} else { | ||
// if changing to native currency, get it from the account key in send | ||
|
@@ -1385,6 +1396,13 @@ export function getSendAssetAddress(state) { | |
return getSendAsset(state)?.details?.address; | ||
} | ||
|
||
export function getIsAssetSendable(state) { | ||
if (state[name].asset.type === ASSET_TYPES.NATIVE) { | ||
return true; | ||
} | ||
return state[name].asset.details.isERC721 === false; | ||
} | ||
|
||
// Amount Selectors | ||
export function getSendAmount(state) { | ||
return state[name].amount.value; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1246,21 +1246,6 @@ export function addToken( | |
}; | ||
} | ||
|
||
export function updateTokenType(tokenAddress) { | ||
return async (dispatch) => { | ||
let token = {}; | ||
dispatch(showLoadingIndication()); | ||
try { | ||
token = await promisifiedBackground.updateTokenType(tokenAddress); | ||
} catch (error) { | ||
log.error(error); | ||
} finally { | ||
dispatch(hideLoadingIndication()); | ||
} | ||
return token; | ||
}; | ||
} | ||
|
||
export function removeToken(address) { | ||
return (dispatch) => { | ||
dispatch(showLoadingIndication()); | ||
|
@@ -2738,6 +2723,16 @@ export function estimateGas(params) { | |
return promisifiedBackground.estimateGas(params); | ||
} | ||
|
||
export async function updateTokenType(tokenAddress) { | ||
let token = {}; | ||
try { | ||
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. Guess you felt loading indicator wasn't required here? 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. its handled at the callsite now, the loading indicator is shown anytime we updateAsset to a token asset. |
||
token = await promisifiedBackground.updateTokenType(tokenAddress); | ||
} catch (error) { | ||
log.error(error); | ||
} | ||
return token; | ||
} | ||
|
||
// MetaMetrics | ||
/** | ||
* @typedef {import('../../shared/constants/metametrics').MetaMetricsEventPayload} MetaMetricsEventPayload | ||
|
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.
So while trying to test this I re-found an issue similar to one I had been having while trying to tack a PR on top of the broad send-slice refactor.
Here it is, so entering the send flow the form status is immediately set to valid:
once, however, I click the dropdown to select another token, the form becomes invalid:
That is expected, but then I cannot get the form status to be valid again:
even if I go back and select Eth as the send asset:
I believe it has something to do with sequencing of actions and the gas loading thunk. The last call to validateSendState sets us to invalid here.
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.
can you try 3d8ca2d out for a spin? see if the issue persists?
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.
@brad-decker That commit seems to have fixed the issue, 🚀