Skip to content
Merged
Prev Previous commit
Only open in new when not in a window, add back
  • Loading branch information
jacogr committed May 30, 2020
commit 7db8c4bcc70f829bb157ee31fbeb842e8856c123
11 changes: 10 additions & 1 deletion packages/extension-ui/src/Popup/ImportSeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ export default function Import (): React.ReactElement {
}
}, [account, name, onAction, password]);

const _toJson = useCallback((): void => {
// are we in a popup?
if (window.innerWidth <= 480) {
jsonRestoreWindowOpen().catch(console.error);
} else {
onAction('/account/restore-json');
}
}, [onAction]);

return (
<>
<HeaderWithSmallerMargin
Expand Down Expand Up @@ -90,7 +99,7 @@ export default function Import (): React.ReactElement {
<ButtonsRow>
<ActionText
icon={upload}
onClick={jsonRestoreWindowOpen}
onClick={_toJson}
text='Restore from JSON backup'
/>
</ButtonsRow>
Expand Down
11 changes: 7 additions & 4 deletions packages/extension-ui/src/Popup/RestoreJson.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ interface FileState {
json: KeyringPair$Json | null;
}

// FIXME We want to display the decodeError
interface PassState {
decodeError?: string | null;
isPassValid: boolean;
password: string;
}
Expand Down Expand Up @@ -66,7 +68,7 @@ export default function Upload (): React.ReactElement {
jsonRestore(json, password)
.then(({ error }): void => {
if (error) {
setPass(({ password }) => ({ isPassValid: false, password }));
setPass(({ password }) => ({ decodeError: error, isPassValid: false, password }));
} else {
onAction('/');
}
Expand All @@ -79,12 +81,13 @@ export default function Upload (): React.ReactElement {
return (
<>
<HeaderWithSmallerMargin
text='Restore Account from JSON'
showBackArrow
text='Restore from JSON'
/>
<div>
<Address
address={isFileValid && address ? address : null}
name={isFileValid && json ? json.meta.name as string : null}
address={(isFileValid && address) || null}
name={(isFileValid && json?.meta.name as string) || null}
/>
<InputFileWithLabel
accept={acceptedFormats}
Expand Down