-
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.
feat: display loader on re-designed confirmation page while blockaid …
…validation is in progress (#25477)
- Loading branch information
Showing
9 changed files
with
228 additions
and
5 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...confirm/blockaid-loading-indicator/__snapshots__/blockaid-loading-indicator.test.tsx.snap
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,49 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`BlockaidLoadingIndicator returns spinner when there blockaid validation is in progress for signature 1`] = ` | ||
<div> | ||
<div | ||
class="mm-box mm-box--margin-top-4 mm-box--margin-inline-auto" | ||
> | ||
<svg | ||
class="preloader__icon" | ||
fill="none" | ||
height="18" | ||
viewBox="0 0 16 16" | ||
width="18" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
clip-rule="evenodd" | ||
d="M8 13.7143C4.84409 13.7143 2.28571 11.1559 2.28571 8C2.28571 4.84409 4.84409 2.28571 8 2.28571C11.1559 2.28571 13.7143 4.84409 13.7143 8C13.7143 11.1559 11.1559 13.7143 8 13.7143ZM8 16C3.58172 16 0 12.4183 0 8C0 3.58172 3.58172 0 8 0C12.4183 0 16 3.58172 16 8C16 12.4183 12.4183 16 8 16Z" | ||
fill="var(--color-primary-muted)" | ||
fill-rule="evenodd" | ||
/> | ||
<mask | ||
height="16" | ||
id="mask0" | ||
mask-type="alpha" | ||
maskUnits="userSpaceOnUse" | ||
width="16" | ||
x="0" | ||
y="0" | ||
> | ||
<path | ||
clip-rule="evenodd" | ||
d="M8 13.7143C4.84409 13.7143 2.28571 11.1559 2.28571 8C2.28571 4.84409 4.84409 2.28571 8 2.28571C11.1559 2.28571 13.7143 4.84409 13.7143 8C13.7143 11.1559 11.1559 13.7143 8 13.7143ZM8 16C3.58172 16 0 12.4183 0 8C0 3.58172 3.58172 0 8 0C12.4183 0 16 3.58172 16 8C16 12.4183 12.4183 16 8 16Z" | ||
fill="var(--color-primary-default)" | ||
fill-rule="evenodd" | ||
/> | ||
</mask> | ||
<g | ||
mask="url(#mask0)" | ||
> | ||
<path | ||
d="M6.85718 17.9999V11.4285V8.28564H-4.85711V17.9999H6.85718Z" | ||
fill="var(--color-primary-default)" | ||
/> | ||
</g> | ||
</svg> | ||
</div> | ||
</div> | ||
`; |
79 changes: 79 additions & 0 deletions
79
...mations/components/confirm/blockaid-loading-indicator/blockaid-loading-indicator.test.tsx
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,79 @@ | ||
import React from 'react'; | ||
import configureStore from 'redux-mock-store'; | ||
import { | ||
TransactionStatus, | ||
TransactionType, | ||
} from '@metamask/transaction-controller'; | ||
|
||
import mockState from '../../../../../../test/data/mock-state.json'; | ||
import { BlockaidResultType } from '../../../../../../shared/constants/security-provider'; | ||
import { renderWithProvider } from '../../../../../../test/lib/render-helpers'; | ||
import { SecurityAlertResponse } from '../../../types/confirm'; | ||
|
||
import BlockaidLoadingIndicator from './blockaid-loading-indicator'; | ||
|
||
const mockSecurityAlertResponse: SecurityAlertResponse = { | ||
securityAlertId: 'test-id-mock', | ||
reason: 'test-reason', | ||
result_type: BlockaidResultType.Loading, | ||
}; | ||
|
||
const render = ( | ||
securityAlertResponse: SecurityAlertResponse = mockSecurityAlertResponse, | ||
) => { | ||
const currentConfirmationMock = { | ||
id: '1', | ||
status: TransactionStatus.unapproved, | ||
time: new Date().getTime(), | ||
type: TransactionType.personalSign, | ||
securityAlertResponse, | ||
chainId: '0x1', | ||
}; | ||
|
||
const mockExpectedState = { | ||
...mockState, | ||
metamask: { | ||
...mockState.metamask, | ||
unapprovedPersonalMsgs: { | ||
'1': { ...currentConfirmationMock, msgParams: {} }, | ||
}, | ||
pendingApprovals: { | ||
'1': { | ||
...currentConfirmationMock, | ||
origin: 'origin', | ||
requestData: {}, | ||
requestState: null, | ||
expectsResult: false, | ||
}, | ||
}, | ||
preferences: { redesignedConfirmationsEnabled: true }, | ||
signatureSecurityAlertResponses: { | ||
'test-id-mock': securityAlertResponse, | ||
}, | ||
}, | ||
confirm: { currentConfirmation: currentConfirmationMock }, | ||
}; | ||
|
||
const defaultStore = configureStore()(mockExpectedState); | ||
return renderWithProvider(<BlockaidLoadingIndicator />, defaultStore); | ||
}; | ||
|
||
describe('BlockaidLoadingIndicator', () => { | ||
it('returns spinner when there blockaid validation is in progress for signature', () => { | ||
const { container } = render(); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('returns null if blockaid validation is not in progress', () => { | ||
const { container } = render({ | ||
reason: 'test-reason', | ||
result_type: BlockaidResultType.Benign, | ||
}); | ||
expect(container).toBeEmptyDOMElement(); | ||
}); | ||
|
||
it('returns null if there is not blockaid validation response', () => { | ||
const { container } = render({} as SecurityAlertResponse); | ||
expect(container).toBeEmptyDOMElement(); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
...onfirmations/components/confirm/blockaid-loading-indicator/blockaid-loading-indicator.tsx
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,28 @@ | ||
import React from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import Preloader from '../../../../../components/ui/icon/preloader'; | ||
import { BlockaidResultType } from '../../../../../../shared/constants/security-provider'; | ||
import { Box } from '../../../../../components/component-library'; | ||
|
||
import { currentSignatureRequestSecurityResponseSelector } from '../../../selectors'; | ||
|
||
const BlockaidLoadingIndicator = () => { | ||
const signatureSecurityAlertResponse = useSelector( | ||
currentSignatureRequestSecurityResponseSelector, | ||
); | ||
|
||
if ( | ||
signatureSecurityAlertResponse?.result_type !== BlockaidResultType.Loading | ||
) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Box marginInline={'auto'} marginTop={4}> | ||
<Preloader size={18} /> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default BlockaidLoadingIndicator; |
1 change: 1 addition & 0 deletions
1
ui/pages/confirmations/components/confirm/blockaid-loading-indicator/index.ts
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 @@ | ||
export { default as BlockaidLoadingIndicator } from './blockaid-loading-indicator'; |
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
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