-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Added QR code #23428
Merged
Merged
Added QR code #23428
Changes from 2 commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
6fb6df3
Added QR code
albertolive 36ec5f6
Improved code
albertolive 355e5e0
Clean stuff
albertolive e4e8966
initial handshake work
albertolive 8cd8b94
Merge branch 'develop' into MMI-4693-QR-code
albertolive 6259201
Merge branch 'develop' into MMI-4693-QR-code
albertolive 73a32e3
Improved code
albertolive c925859
Merge branch 'develop' into MMI-4693-QR-code
albertolive 7a8356a
Improving code
albertolive 5318444
Merge branch 'develop' into MMI-4693-QR-code
albertolive abd835a
Continue working on it
albertolive 14184b2
Merge branch 'MMI-4693-QR-code' of https://github.com/MetaMask/metama…
albertolive b81d203
Added logic to decrypt the connect request
albertolive c271122
Merge branch 'develop' into MMI-4693-QR-code
albertolive c0a55f9
Merge branch 'develop' into MMI-4693-QR-code
albertolive 244f554
updated packages, lavamoat and qr code modal
albertolive 53513b4
Merge branch 'develop' into MMI-4693-QR-code
albertolive 8793db8
Update LavaMoat policies
metamaskbot e3ae6de
improved qr modal component
albertolive 4e55314
Merge branch 'develop' into MMI-4693-QR-code
albertolive bccb5dc
Improved qr code modal
albertolive 6a1e6ef
Added unit tests
albertolive 114b00d
Added storybook story and improved tests
albertolive 00554ba
Added sentry errors
albertolive ae44c3b
Merge branch 'develop' into MMI-4693-QR-code
albertolive 7f7950d
fixed issues
albertolive 770b541
updated lavamoat
albertolive dff9172
Update LavaMoat policies
metamaskbot c5fc2f2
Fixed lavamoat
albertolive 65268de
chore: fix lavamoat and small code change
zone-live c62c3f2
Merge branch 'develop' into MMI-4693-QR-code
zone-live 996f2b7
Update LavaMoat policies
metamaskbot 0b7f644
chore: fix audit failing and test
zone-live f7af556
adding back connectRequest as is needed to listen for new connectRequ…
albertolive 8b081a3
Fixed tests, added e2e tests and improved code
albertolive 58c563f
test
albertolive b394db3
test
albertolive 471fc77
Merge branch 'develop' into MMI-4693-QR-code
albertolive d2619e5
Merge branch 'develop' into MMI-4693-QR-code
albertolive 6acd368
Merge branch 'develop' into MMI-4693-QR-code
albertolive 8d52d28
FIx PW issue
albertolive c8f0c47
Merge branch 'develop' into MMI-4693-QR-code
albertolive 2a10cef
Merge branch 'develop' into MMI-4693-QR-code
albertolive 0ad5890
remove console log
albertolive a1e90fb
Merge branch 'MMI-4693-QR-code' of https://github.com/MetaMask/metama…
albertolive 0b42348
updated to tsx
albertolive 5e113ab
move to tsx
albertolive 3ff89a2
fix tsx
albertolive 2124074
fixed tsx
albertolive 5f9e120
fix lint
albertolive 3703a12
Merge branch 'develop' into MMI-4693-QR-code
albertolive 546abb6
lint issues
albertolive a4afe1b
fix lint
albertolive 2e65fbe
fix lint
albertolive 5eff79d
test
zone-live 22b5e3a
test 2
zone-live 74e41d2
clean up
zone-live 38a9719
test 3
zone-live d63ae12
clean up test changes
zone-live 5b29830
test logging element
zone-live 014d577
test logging env var
zone-live 9e19a21
clean up
zone-live 8ecc17f
clean up
zone-live 87761a1
updates visual snapshots
zone-live File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './qr-code-modal'; | ||
101 changes: 101 additions & 0 deletions
101
ui/components/institutional/qr-code-modal/qr-code-modal.js
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 React, { useState, useEffect, useContext } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import QRCode from 'qrcode.react'; | ||
import { Modal, ModalOverlay, Text, Box } from '../../component-library'; | ||
import { ModalContent } from '../../component-library/modal-content/modal-content'; | ||
import { ModalHeader } from '../../component-library/modal-header/modal-header'; | ||
import { | ||
TextColor, | ||
TextVariant, | ||
} from '../../../helpers/constants/design-system'; | ||
import { I18nContext } from '../../../contexts/i18n'; | ||
import Spinner from '../../ui/spinner'; | ||
|
||
export default function QRCodeModal({ onClose, custodianName }) { | ||
const t = useContext(I18nContext); | ||
const [publicKeyData, setPublicKeyData] = useState(null); | ||
const [error, setError] = useState(''); | ||
|
||
async function generatePublicKey() { | ||
try { | ||
const { publicKey } = await window.crypto.subtle.generateKey( | ||
{ | ||
name: 'RSA-OAEP', | ||
modulusLength: 2048, | ||
publicExponent: new Uint8Array([0x01, 0x00, 0x01]), | ||
hash: 'SHA-256', | ||
}, | ||
true, | ||
['encrypt', 'decrypt'], | ||
); | ||
|
||
const exportedPublicKey = await window.crypto.subtle.exportKey( | ||
'spki', | ||
publicKey, | ||
); | ||
|
||
const publicKeyBase64 = Buffer.from(exportedPublicKey) | ||
.toString('base64') | ||
.replace(/\+/gu, '-') | ||
albertolive marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.replace(/\//gu, '_') | ||
.replace(/[=]+$/u, ''); | ||
|
||
setPublicKeyData(publicKeyBase64); | ||
} catch (e) { | ||
console.error('Error generating public key:', e); | ||
setError('Error generating public key. Please try again.'); | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
generatePublicKey(); | ||
}, []); | ||
|
||
const qrCodeValue = JSON.stringify({ | ||
custodianName, | ||
publicKey: publicKeyData, | ||
}); | ||
|
||
return ( | ||
<Modal isOpen onClose={onClose}> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<ModalHeader onClose={onClose}> | ||
{t('connectCustodianAccounts', [custodianName || 'custodian'])} | ||
</ModalHeader> | ||
<Text | ||
as="p" | ||
paddingRight={10} | ||
paddingLeft={10} | ||
paddingBottom={4} | ||
color={TextColor.textDefault} | ||
variant={TextVariant.bodySm} | ||
> | ||
{t('custodianQRCodeScan')} | ||
</Text> | ||
{error && <Text color={TextColor.error}>{error}</Text>} | ||
{publicKeyData === null && ( | ||
<Spinner color="var(--color-warning-default)" /> | ||
)} | ||
{publicKeyData && ( | ||
<Box | ||
style={{ | ||
padding: 20, | ||
backgroundColor: 'var(--qr-code-white-background)', | ||
display: 'flex', | ||
alignItems: 'center', | ||
flexDirection: 'column', | ||
}} | ||
> | ||
<QRCode value={qrCodeValue} size={270} /> | ||
</Box> | ||
)} | ||
</ModalContent> | ||
</Modal> | ||
); | ||
} | ||
|
||
QRCodeModal.propTypes = { | ||
onClose: PropTypes.func.isRequired, | ||
custodianName: PropTypes.string.isRequired, | ||
}; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 we convert this file to typescript too?