-
-
Notifications
You must be signed in to change notification settings - Fork 650
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from MyCryptoHQ/paritysigner-adjustments
Paritysigner adjustments
- Loading branch information
Showing
21 changed files
with
224 additions
and
86 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export enum TypeKeys { | ||
PARITY_SIGNER_REQUEST_SIGNATURE = 'PARITY_SIGNER_REQUEST_SIGNATURE', | ||
PARITY_SIGNER_FINALIZE = 'PARITY_SIGNER_FINALIZE' | ||
PARITY_SIGNER_FINALIZE_SIGNATURE = 'PARITY_SIGNER_FINALIZE_SIGNATURE' | ||
} |
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,30 @@ | ||
@import 'common/sass/variables'; | ||
|
||
.ParityQrSigner { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: 300px; | ||
height: 300px; | ||
text-align: center; | ||
margin: 0 auto 1.5em; | ||
border-radius: 4px; | ||
overflow: hidden; | ||
|
||
&.is-disabled { | ||
background: $gray-lighter; | ||
} | ||
|
||
&-error { | ||
padding: $space; | ||
font-size: $font-size-small; | ||
color: $gray-light; | ||
|
||
&-icon { | ||
display: block; | ||
font-size: 60px; | ||
margin-bottom: $space-md; | ||
opacity: 0.8; | ||
} | ||
} | ||
} |
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,110 @@ | ||
import React from 'react'; | ||
import classnames from 'classnames'; | ||
import translate from 'translations'; | ||
import { Spinner } from 'components/ui'; | ||
import QrSigner from '@parity/qr-signer'; | ||
import './ParityQrSigner.scss'; | ||
|
||
interface State { | ||
webcamError: null | React.ReactElement<any>; | ||
isLoading: boolean; | ||
} | ||
|
||
interface ScanProps { | ||
scan: true; | ||
onScan(data: string): void; | ||
} | ||
|
||
interface ShowProps { | ||
scan: false; | ||
account: string; | ||
rlp: string; | ||
} | ||
|
||
interface SharedProps { | ||
size?: number; | ||
} | ||
|
||
type Props = (ScanProps | ShowProps) & SharedProps; | ||
|
||
export default class ParityQrSigner extends React.PureComponent<Props, State> { | ||
public state: State = { | ||
webcamError: null, | ||
isLoading: true | ||
}; | ||
|
||
public componentDidMount() { | ||
this.checkForWebcam(); | ||
if (navigator.mediaDevices) { | ||
navigator.mediaDevices.addEventListener('devicechange', this.checkForWebcam); | ||
} | ||
} | ||
|
||
public componentWillUnmount() { | ||
if (navigator.mediaDevices && navigator.mediaDevices.ondevicechange) { | ||
navigator.mediaDevices.removeEventListener('devicechange', this.checkForWebcam); | ||
} | ||
} | ||
|
||
public checkForWebcam = async () => { | ||
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) { | ||
try { | ||
await navigator.mediaDevices.getUserMedia({ video: true }); | ||
this.setState({ | ||
webcamError: null, | ||
isLoading: false | ||
}); | ||
} catch (e) { | ||
const err = e as DOMException; | ||
let errorMessage; | ||
switch (err.name) { | ||
case 'NotAllowedError': | ||
case 'SecurityError': | ||
errorMessage = translate('ADD_PARITY_ERROR_DISABLED'); | ||
break; | ||
case 'NotFoundError': | ||
case 'OverconstrainedError': | ||
errorMessage = translate('ADD_PARITY_ERROR_NO_CAM'); | ||
break; | ||
default: | ||
errorMessage = translate('ADD_PARITY_ERROR_UNKNOWN'); | ||
} | ||
this.setState({ | ||
webcamError: errorMessage, | ||
isLoading: false | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
public render() { | ||
const { webcamError, isLoading } = this.state; | ||
const size = this.props.size || 300; | ||
|
||
return ( | ||
<div | ||
className={classnames({ | ||
ParityQrSigner: true, | ||
'is-disabled': !!webcamError || isLoading | ||
})} | ||
style={{ | ||
width: size, | ||
height: size | ||
}} | ||
> | ||
{isLoading ? ( | ||
<div className="ParityQrSigner-loader"> | ||
<Spinner size="x3" light={true} /> | ||
</div> | ||
) : webcamError ? ( | ||
<div className="ParityQrSigner-error"> | ||
<i className="ParityQrSigner-error-icon fa fa-exclamation-circle" /> | ||
{webcamError} | ||
</div> | ||
) : ( | ||
<QrSigner {...this.props} size={size} /> | ||
)} | ||
</div> | ||
); | ||
} | ||
} |
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,7 @@ | ||
.ParitySignerUnlock { | ||
&-badge { | ||
display: inline-block; | ||
height: 3em; | ||
margin: 0 0.4em; | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.