Skip to content

Commit

Permalink
correct types
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-1979 committed May 6, 2024
1 parent dff3f3b commit 2f845fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
16 changes: 9 additions & 7 deletions packages/extension-polkagate/src/popup/import/attachQR/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

/* eslint-disable react/jsx-max-props-per-line */

import type { HexString } from '@polkadot/util/types';

import { Button, Grid, Typography, useTheme } from '@mui/material';
import React, { useCallback, useContext, useEffect, useState } from 'react';

Expand All @@ -14,19 +16,19 @@ import { createAccountExternal, createAccountSuri, createSeed, updateMeta } from
import HeaderBrand from '../../../partials/HeaderBrand';
import Name from '../../../partials/Name';

interface QrAccount {
content: string;
genesisHash: string;
export interface ScanType {
isAddress: boolean;
name?: string;
content: string;
genesisHash: HexString | null;
name?: string | undefined;
}

export default function AttachQR(): React.ReactElement {
export default function AttachQR (): React.ReactElement {
const { t } = useTranslation();
const theme = useTheme();
const { accounts } = useContext(AccountContext);
const onAction = useContext(ActionContext);
const [account, setAccount] = useState<QrAccount | null>(null);
const [account, setAccount] = useState<ScanType | null>(null);
const [address, setAddress] = useState<string | null>(null);
const [name, setName] = useState<string | null>(null);
const [password, setPassword] = useState<string | null>(null);
Expand Down Expand Up @@ -60,7 +62,7 @@ export default function AttachQR(): React.ReactElement {
}, [account, name, password, setQrLabelAndGoToHome]);

const _setAccount = useCallback(
(qrAccount: QrAccount) => {
(qrAccount: ScanType) => {
setAccount(qrAccount);
setName(qrAccount?.name || null);
setGenesisHash(qrAccount.genesisHash);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,15 @@ import { FullScreenHeader } from '../../../fullscreen/governance/FullScreenHeade
import { useFullscreen, useTranslation } from '../../../hooks';
import { createAccountExternal, createAccountSuri, createSeed, updateMeta } from '../../../messaging';
import { Name } from '../../../partials';

interface QrAccount {
content: string;
genesisHash: string;
isAddress: boolean;
name?: string;
}
import { ScanType } from '../attachQR';

export default function AttachQrFullScreen (): React.ReactElement {
useFullscreen();
const { t } = useTranslation();
const theme = useTheme();
const { accounts } = useContext(AccountContext);
const onAction = useContext(ActionContext);
const [account, setAccount] = useState<QrAccount | null>(null);
const [account, setAccount] = useState<ScanType | null>(null);
const [address, setAddress] = useState<string | null>(null);
const [name, setName] = useState<string | null>(null);
const [password, setPassword] = useState<string | null>(null);
Expand Down Expand Up @@ -61,7 +55,7 @@ export default function AttachQrFullScreen (): React.ReactElement {
}, [account, name, password, setQrLabelAndGoToHome]);

const _setAccount = useCallback(
(qrAccount: QrAccount) => {
(qrAccount: ScanType) => {
setAccount(qrAccount);
setName(qrAccount?.name || null);

Expand All @@ -80,7 +74,7 @@ export default function AttachQrFullScreen (): React.ReactElement {
onAction('/');
}, [onAction]);

const _onError = useCallback((error: string) => {
const _onError = useCallback((error: Error) => {
setInvalidQR(String(error).includes('Invalid prefix'));
}, []);

Expand Down

0 comments on commit 2f845fe

Please sign in to comment.