* Add typings to messages * Fix eslint (after merge) * Mobile signer support (via Qr) * Bump common * Pass through genesisHash * Ok, well, it does something... not recognized * Bump ui * Exclude build from lint * ** * Display accounts with prefix from genesisHash * Adapth for object via scan interface * Bump deps * Split address recoding * Cleanup decoding readability * Display chain affinity overlay * -1 prefix dropdown description * Add generator command * Fix TypeScript error * Lint * Consistent naming * Better promise error handling * Small consistency updates * Constraint handle typings as much as tsc will allow * State naming * Typo in cheain descriptions * Add signature handler (unused) * e2e roundtrip * remove (useless) dev 0.5.1 chain * Insert ActionBar * Revert to empty Props interfaces * SeedLengths type * Add type to transport subscription message * nit * Typecheck passing callback to sendMessage when none expected * Bump api * Small lint fixes * Bump api * Not sure it works... but linting passes * Split public/private * Alphabetical * Don't show button on no media * Remove unneeded resolve - NOT hacking around linting * Pass edited name through to accounts component * genesisHash alignments * Remove KeyringJson * SignRequest with account * Align with master naming * Some manual merges * Manual (small) conflict resolution * Fixup extension account mapping * Remove ununsed messages (less code = better) * Update comment around generation * Add copy-to-apps script (debugging)
72 lines
2.3 KiB
TypeScript
72 lines
2.3 KiB
TypeScript
// Copyright 2019 @polkadot/extension-ui authors & contributors
|
|
// This software may be modified and distributed under the terms
|
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
|
|
import { ExtrinsicPayload } from '@polkadot/types/interfaces';
|
|
import { AccountJson, RequestExtrinsicSign } from '@polkadot/extension/background/types';
|
|
|
|
import React, { useContext, useState, useEffect } from 'react';
|
|
import { createType } from '@polkadot/types';
|
|
|
|
import { ActionBar, ActionContext, Address, Link } from '../../components';
|
|
import { approveSignPassword, approveSignSignature, cancelSignRequest } from '../../messaging';
|
|
import Details from './Details';
|
|
import Qr from './Qr';
|
|
import Unlock from './Unlock';
|
|
|
|
interface Props {
|
|
account: AccountJson;
|
|
isFirst: boolean;
|
|
request: RequestExtrinsicSign;
|
|
signId: string;
|
|
url: string;
|
|
}
|
|
|
|
export default function Request ({ account: { isExternal }, isFirst, request, signId, url }: Props): React.ReactElement<Props> | null {
|
|
const onAction = useContext(ActionContext);
|
|
const [payload, setPayload] = useState<ExtrinsicPayload | null>(null);
|
|
|
|
useEffect((): void => {
|
|
setPayload(createType('ExtrinsicPayload', request, { version: request.version }));
|
|
}, [request]);
|
|
|
|
if (!payload) {
|
|
return null;
|
|
}
|
|
|
|
const _onCancel = (): Promise<void> =>
|
|
cancelSignRequest(signId)
|
|
.then((): void => onAction())
|
|
.catch((error: Error) => console.error(error));
|
|
const _onSign = (password: string): Promise<void> =>
|
|
approveSignPassword(signId, password)
|
|
.then((): void => onAction())
|
|
.catch((error: Error) => console.error(error));
|
|
const _onSignature = ({ signature }: { signature: string }): Promise<void> =>
|
|
approveSignSignature(signId, signature)
|
|
.then((): void => onAction())
|
|
.catch((error: Error) => console.error(error));
|
|
|
|
return (
|
|
<Address address={request.address}>
|
|
{isExternal && isFirst
|
|
? <Qr
|
|
payload={payload}
|
|
request={request}
|
|
onSignature={_onSignature}
|
|
/>
|
|
: <Details
|
|
isDecoded={isFirst}
|
|
payload={payload}
|
|
request={request}
|
|
url={url}
|
|
/>
|
|
}
|
|
{isFirst && !isExternal && <Unlock onSign={_onSign} />}
|
|
<ActionBar>
|
|
<Link isDanger onClick={_onCancel}>Cancel</Link>
|
|
</ActionBar>
|
|
</Address>
|
|
);
|
|
}
|