Dev olu update swap approval transaction (#13641)

* Draft methods to brak updateTransaction into smaller more targeted
methods.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* This is a combination of 52 commits.

normalize and validate tx params.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Method to normalize tx and check if it's unapproved.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Move the methods to controllers/transactions/index.js

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Flesh out the methods to update transaction with custom notes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Test update gas fees

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

use lodash to remove undefined properties
update swap transaction tests

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Updates transaction user settings.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Add Update Transaction Metrics

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Update transaction gas fees actions.js

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Update EIP 1559 Params.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint Fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Documentations.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Remove metrics from this PR

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint fixes: Removed unused variables

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Update swap approval transaction

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

1. updateSwapApprovalTransaction should have id as first parameter
2. updateSwapApprovalTransaction should not show loading indicator

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

update swap transaction.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Remove metrics code.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Add updateTransactionParams to actions.js updateXXX and return txData at
the end of updateXXX method

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Fix swapApprovalTransaction update to use same return method as swap
update
Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Draft methods to brak updateTransaction into smaller more targeted
methods.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

normalize and validate tx params.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Method to normalize tx and check if it's unapproved.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Move the methods to controllers/transactions/index.js

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Flesh out the methods to update transaction with custom notes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Test update gas fees

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Update swap approval transaction

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

use lodash to remove undefined properties
update swap transaction tests

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Add Update Transaction Metrics

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Update transaction gas fees actions.js

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Update EIP 1559 Params.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint Fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Documentations.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Remove metrics from this PR

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint fixes: Removed unused variables

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Update swap approval transaction

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

1. updateSwapApprovalTransaction should have id as first parameter
2. updateSwapApprovalTransaction should not show loading indicator

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

update swap transaction.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Remove metrics code.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Add updateTransactionParams to actions.js updateXXX and return txData at
the end of updateXXX method

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Fix swapApprovalTransaction update to use same return method as swap
update
Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Remove duplicate tests

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Remove comments.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Do not hideLoading, since we're not showing it.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

...approveTxMeta no longer needed here.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Remove estimated base fee from swap approval txs.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

remove txTradeMeta from params
make sure rebase didn't mess up any code - first pass

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

Lint fixes

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>
feature/default_network_editable
Olusegun Akintayo 3 years ago committed by GitHub
parent 259e30abc2
commit e157d2b51f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/scripts/controllers/transactions/index.test.js
  2. 8
      app/scripts/metamask-controller.js
  3. 2
      ui/components/app/modals/convert-token-to-nft-modal/convert-token-to-nft-modal.js
  4. 42
      ui/ducks/swaps/swaps.js
  5. 43
      ui/store/actions.js

@ -2218,7 +2218,6 @@ describe('Transaction Controller', function () {
});
result = txStateManager.getTransaction('1');
console.log(result);
assert.equal(result.estimateUsed, '0x13');
assert.equal(result.txParams.gasPrice, '0x14');
assert.equal(result.destinationTokenAddress, VALID_ADDRESS_TWO); // not updated even though it's passed in to update

@ -1531,6 +1531,14 @@ export default class MetamaskController extends EventEmitter {
updateTransactionGasFees: txController.updateTransactionGasFees.bind(
txController,
),
updateSwapApprovalTransaction: txController.updateSwapApprovalTransaction.bind(
txController,
),
updateSwapTransaction: txController.updateSwapTransaction.bind(
txController,
),
// messageManager
signMessage: this.signMessage.bind(this),
cancelMessage: this.cancelMessage.bind(this),

@ -12,8 +12,8 @@ import {
ASSET_ROUTE,
} from '../../../../helpers/constants/routes';
import { getCollectibles } from '../../../../ducks/metamask/metamask';
import { isEqualCaseInsensitive } from '../../../../../shared/modules/string-utils';
import { removeToken } from '../../../../store/actions';
import { isEqualCaseInsensitive } from '../../../../../shared/modules/string-utils';
const ConvertTokenToNFTModal = ({ hideModal, tokenAddress }) => {
const history = useHistory();

@ -18,7 +18,8 @@ import {
setTradeTxId,
stopPollingForQuotes,
updateAndApproveTx,
updateTransaction,
updateSwapApprovalTransaction,
updateSwapTransaction,
resetBackgroundSwapsState,
setSwapsLiveness,
setSwapsFeatureFlags,
@ -1152,15 +1153,10 @@ export const signAndSendTransactions = (history, metaMetricsEvent) => {
);
await dispatch(setApproveTxId(approveTxMeta.id));
finalApproveTxMeta = await dispatch(
updateTransaction(
{
...approveTxMeta,
estimatedBaseFee: decEstimatedBaseFee,
type: TRANSACTION_TYPES.SWAP_APPROVAL,
sourceTokenSymbol: sourceTokenInfo.symbol,
},
true,
),
updateSwapApprovalTransaction(approveTxMeta.id, {
type: TRANSACTION_TYPES.SWAP_APPROVAL,
sourceTokenSymbol: sourceTokenInfo.symbol,
}),
);
try {
await dispatch(updateAndApproveTx(finalApproveTxMeta, true));
@ -1196,21 +1192,17 @@ export const signAndSendTransactions = (history, metaMetricsEvent) => {
return;
}
const finalTradeTxMeta = await dispatch(
updateTransaction(
{
...tradeTxMeta,
estimatedBaseFee: decEstimatedBaseFee,
sourceTokenSymbol: sourceTokenInfo.symbol,
destinationTokenSymbol: destinationTokenInfo.symbol,
type: TRANSACTION_TYPES.SWAP,
destinationTokenDecimals: destinationTokenInfo.decimals,
destinationTokenAddress: destinationTokenInfo.address,
swapMetaData,
swapTokenValue,
approvalTxId: finalApproveTxMeta?.id,
},
true,
),
updateSwapTransaction(tradeTxMeta.id, {
estimatedBaseFee: decEstimatedBaseFee,
sourceTokenSymbol: sourceTokenInfo.symbol,
destinationTokenSymbol: destinationTokenInfo.symbol,
type: TRANSACTION_TYPES.SWAP,
destinationTokenDecimals: destinationTokenInfo.decimals,
destinationTokenAddress: destinationTokenInfo.address,
swapMetaData,
swapTokenValue,
approvalTxId: finalApproveTxMeta?.id,
}),
);
try {
await dispatch(updateAndApproveTx(finalTradeTxMeta, true));

@ -671,6 +671,24 @@ const updateMetamaskStateFromBackground = () => {
});
};
export function updateSwapApprovalTransaction(txId, txSwapApproval) {
return async (dispatch) => {
try {
await promisifiedBackground.updateSwapApprovalTransaction(
txId,
txSwapApproval,
);
} catch (error) {
dispatch(txError(error));
dispatch(goHome());
log.error(error.message);
throw error;
}
return txSwapApproval;
};
}
export function updateEditableParams(txId, editableParams) {
return async (dispatch) => {
try {
@ -682,12 +700,6 @@ export function updateEditableParams(txId, editableParams) {
throw error;
}
dispatch(
updateTransactionParams(editableParams.id, editableParams.txParams),
);
const newState = await updateMetamaskStateFromBackground();
dispatch(updateMetamaskState(newState));
dispatch(showConfTxPage({ id: editableParams.id }));
return editableParams;
};
}
@ -703,14 +715,25 @@ export function updateTransactionGasFees(txId, txGasFees) {
throw error;
}
dispatch(updateTransactionParams(txGasFees.id, txGasFees.txParams));
const newState = await updateMetamaskStateFromBackground();
dispatch(updateMetamaskState(newState));
dispatch(showConfTxPage({ id: txGasFees.id }));
return txGasFees;
};
}
export function updateSwapTransaction(txId, txSwap) {
return async (dispatch) => {
try {
await promisifiedBackground.updateSwapTransaction(txId, txSwap);
} catch (error) {
dispatch(txError(error));
dispatch(goHome());
log.error(error.message);
throw error;
}
return txSwap;
};
}
export function updateTransaction(txData, dontShowLoadingIndicator) {
return async (dispatch) => {
!dontShowLoadingIndicator && dispatch(showLoadingIndication());

Loading…
Cancel
Save