-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: MMI adds mmi flow to new transactions confirmations view (#26817)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** The MMI tx flow is working again, we were missing the support for the new redesign of the transactions confirmation UI. ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
- Loading branch information
Showing
6 changed files
with
197 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { useHistory } from 'react-router-dom'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { mmiActionsFactory } from '../store/institutional/institution-background'; | ||
import { updateAndApproveTx } from '../store/actions'; | ||
import { useMMICustodySendTransaction } from './useMMICustodySendTransaction'; | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useHistory: jest.fn(), | ||
})); | ||
|
||
jest.mock('react-redux', () => ({ | ||
useDispatch: jest.fn(), | ||
useSelector: jest.fn(), | ||
})); | ||
|
||
jest.mock('@metamask-institutional/extension', () => ({ | ||
showCustodianDeepLink: jest.fn(), | ||
})); | ||
|
||
jest.mock('../store/institutional/institution-background', () => ({ | ||
mmiActionsFactory: jest.fn(), | ||
})); | ||
|
||
jest.mock('../selectors', () => ({ | ||
getAccountType: jest.fn(), | ||
})); | ||
|
||
jest.mock('../store/actions', () => ({ | ||
updateAndApproveTx: jest.fn(), | ||
})); | ||
|
||
describe('useMMICustodySendTransaction', () => { | ||
it('handles custody account type', async () => { | ||
const dispatch = jest.fn(); | ||
|
||
useDispatch.mockReturnValue(dispatch); | ||
useSelector.mockReturnValue('custody'); | ||
mmiActionsFactory.mockReturnValue({ | ||
setWaitForConfirmDeepLinkDialog: jest.fn(), | ||
}); | ||
|
||
const { result } = renderHook(() => useMMICustodySendTransaction()); | ||
await result.current.custodyTransactionFn({ | ||
id: '5f2868d0-6480-11ef-a924-4325b6aee02e', | ||
txParams: { | ||
from: '0xe8f748699e2fe0f8133081914473e80bb60df71a', | ||
data: '0x97c5ed1e00000', | ||
gas: '0x8609', | ||
to: '0xfe7a0f0c76c136b9b438dcb27de9a1b618c016fc', | ||
value: '0x0', | ||
maxFeePerGas: '0xb232c6726', | ||
maxPriorityFeePerGas: '0x59682f00', | ||
}, | ||
type: 'contractInteraction', | ||
networkClientId: 'sepolia', | ||
}); | ||
|
||
expect(dispatch).toHaveBeenCalled(); | ||
expect(updateAndApproveTx).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
id: '5f2868d0-6480-11ef-a924-4325b6aee02e', | ||
}), | ||
true, | ||
'', | ||
); | ||
}); | ||
|
||
it('handles non-custody account type', async () => { | ||
const dispatch = jest.fn(); | ||
const mockHistoryPush = jest.fn(); | ||
useHistory.mockReturnValue({ push: mockHistoryPush }); | ||
|
||
useDispatch.mockReturnValue(dispatch); | ||
useSelector.mockReturnValue('non-custody'); | ||
mmiActionsFactory.mockReturnValue({ | ||
setWaitForConfirmDeepLinkDialog: jest.fn(), | ||
}); | ||
|
||
const { result } = renderHook(() => useMMICustodySendTransaction()); | ||
await result.current.custodyTransactionFn({ | ||
id: '5f2868d0-6480-11ef-a924-4325b6aee02e', | ||
txParams: { | ||
from: '0xe8f748699e2fe0f8133081914473e80bb60df71a', | ||
data: '0x97c5ed1e00000', | ||
gas: '0x8609', | ||
to: '0xfe7a0f0c76c136b9b438dcb27de9a1b618c016fc', | ||
value: '0x0', | ||
maxFeePerGas: '0xb232c6726', | ||
maxPriorityFeePerGas: '0x59682f00', | ||
}, | ||
type: 'contractInteraction', | ||
networkClientId: 'sepolia', | ||
}); | ||
|
||
expect(dispatch).toHaveBeenCalled(); | ||
expect(mockHistoryPush).toHaveBeenCalled(); | ||
expect(updateAndApproveTx).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { useHistory } from 'react-router-dom'; | ||
import { TransactionMeta } from '@metamask/transaction-controller'; | ||
import { showCustodianDeepLink } from '@metamask-institutional/extension'; | ||
import { updateAndApproveTx } from '../store/actions'; | ||
import { AccountType, CustodyStatus } from '../../shared/constants/custody'; | ||
import { getMostRecentOverviewPage } from '../ducks/history/history'; | ||
import { clearConfirmTransaction } from '../ducks/confirm-transaction/confirm-transaction.duck'; | ||
import { getAccountType } from '../selectors/selectors'; | ||
import { mmiActionsFactory } from '../store/institutional/institution-background'; | ||
import { showCustodyConfirmLink } from '../store/institutional/institution-actions'; | ||
|
||
type MMITransactionMeta = TransactionMeta & { | ||
txParams: { from: string }; | ||
custodyStatus: CustodyStatus; | ||
metadata: Record<string, unknown>; | ||
}; | ||
|
||
export function useMMICustodySendTransaction() { | ||
const dispatch = useDispatch(); | ||
const history = useHistory(); | ||
const mmiActions = mmiActionsFactory(); | ||
const accountType = useSelector(getAccountType); | ||
const mostRecentOverviewPage = useSelector(getMostRecentOverviewPage); | ||
|
||
const custodyTransactionFn = async (_transactionData: TransactionMeta) => { | ||
const confirmation = _transactionData as MMITransactionMeta; | ||
|
||
if (confirmation && accountType === AccountType.CUSTODY) { | ||
confirmation.custodyStatus = CustodyStatus.CREATED; | ||
confirmation.metadata = confirmation.metadata || {}; | ||
|
||
dispatch(mmiActions.setWaitForConfirmDeepLinkDialog(true)); | ||
|
||
const txId = confirmation.id; | ||
const fromAddress = confirmation.txParams.from; | ||
const closeNotification = false; | ||
|
||
await dispatch(updateAndApproveTx(confirmation, true, '')); | ||
showCustodianDeepLink({ | ||
dispatch, | ||
mmiActions, | ||
txId, | ||
fromAddress, | ||
closeNotification, | ||
isSignature: false, | ||
custodyId: '', | ||
onDeepLinkFetched: () => undefined, | ||
onDeepLinkShown: () => { | ||
dispatch(clearConfirmTransaction()); | ||
}, | ||
showCustodyConfirmLink, | ||
}); | ||
} else { | ||
// Non Custody accounts follow normal flow | ||
await dispatch(updateAndApproveTx(_transactionData, true, '')); | ||
dispatch(clearConfirmTransaction()); | ||
history.push(mostRecentOverviewPage); | ||
} | ||
}; | ||
|
||
return { custodyTransactionFn }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters