Skip to content

Commit

Permalink
display hex data on send screen fixed (#12709)
Browse files Browse the repository at this point in the history
  • Loading branch information
igorms-cons authored Dec 9, 2021
1 parent e455608 commit e41ac17
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
13 changes: 12 additions & 1 deletion ui/ducks/send/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ export const initializeSendState = createAsyncThunk(
send: { asset, stage, recipient, amount, draftTransaction },
metamask,
} = state;

// First determine the correct from address. For new sends this is always
// the currently selected account and switching accounts switches the from
// address. If editing an existing transaction (by clicking 'edit' on the
Expand Down Expand Up @@ -707,6 +708,7 @@ const slice = createSlice({
state.recipient.nickname = action.payload.nickname;
state.draftTransaction.id = action.payload.id;
state.draftTransaction.txParams.from = action.payload.from;
state.draftTransaction.userInputHexData = action.payload.data;
slice.caseReducers.updateDraftTransaction(state);
},
/**
Expand Down Expand Up @@ -1601,6 +1603,7 @@ export function editTransaction(
const { txParams } = transaction;
if (assetType === ASSET_TYPES.NATIVE) {
const {
data,
from,
gas: gasLimit,
gasPrice,
Expand All @@ -1610,6 +1613,7 @@ export function editTransaction(
const nickname = getAddressBookEntry(state, address)?.name ?? '';
await dispatch(
actions.editTransaction({
data,
id: transactionId,
gasLimit,
gasPrice,
Expand All @@ -1624,7 +1628,13 @@ export function editTransaction(
`send/editTransaction dispatched with assetType 'TOKEN' but missing assetData or assetDetails parameter`,
);
} else {
const { from, to: tokenAddress, gas: gasLimit, gasPrice } = txParams;
const {
data,
from,
to: tokenAddress,
gas: gasLimit,
gasPrice,
} = txParams;
const tokenAmountInDec = getTokenValueParam(tokenData);
const address = getTokenAddressParam(tokenData);
const nickname = getAddressBookEntry(state, address)?.name ?? '';
Expand All @@ -1645,6 +1655,7 @@ export function editTransaction(

await dispatch(
actions.editTransaction({
data,
id: transactionId,
gasLimit,
gasPrice,
Expand Down
4 changes: 4 additions & 0 deletions ui/ducks/send/send.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2077,6 +2077,7 @@ describe('Send Slice', () => {
1: {
id: 1,
txParams: {
data: '',
from: '0xAddress',
to: '0xRecipientAddress',
gas: GAS_LIMITS.SIMPLE,
Expand Down Expand Up @@ -2107,6 +2108,7 @@ describe('Send Slice', () => {
expect(actionResult[0].payload).toStrictEqual({
address: '0xRecipientAddress',
amount: '0xde0b6b3a7640000',
data: '',
from: '0xAddress',
gasLimit: GAS_LIMITS.SIMPLE,
gasPrice: '0x3b9aca00',
Expand Down Expand Up @@ -2154,6 +2156,7 @@ describe('Send Slice', () => {
1: {
id: 1,
txParams: {
data: '',
from: '0xAddress',
to: '0xTokenAddress',
gas: GAS_LIMITS.SIMPLE,
Expand Down Expand Up @@ -2241,6 +2244,7 @@ describe('Send Slice', () => {
expect(actionResult[6].payload).toStrictEqual({
address: '0xrecipientaddress', // getting address from tokenData does .toLowerCase
amount: '0x3a98',
data: '',
from: '0xAddress',
gasLimit: GAS_LIMITS.SIMPLE,
gasPrice: '0x3b9aca00',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import SendRowWrapper from '../send-row-wrapper';
export default class SendHexDataRow extends Component {
static propTypes = {
inError: PropTypes.bool,
data: PropTypes.string,
updateSendHexData: PropTypes.func.isRequired,
};

Expand All @@ -19,7 +20,7 @@ export default class SendHexDataRow extends Component {
};

render() {
const { inError } = this.props;
const { inError, data } = this.props;
const { t } = this.context;

return (
Expand All @@ -32,6 +33,7 @@ export default class SendHexDataRow extends Component {
onInput={this.onInput}
placeholder={t('optional')}
className="send-v2__hex-data__input"
defaultValue={data || ''}
/>
</SendRowWrapper>
);
Expand Down

0 comments on commit e41ac17

Please sign in to comment.