Introduce the enable() interface (prompts user) (#20)
* Introduce the enable() interface * Provider * Add auth requests to state * injector comments * Background extension list, spprove & reject * Cleanups * Untested, but the UI parts are there (test next) * linting * Not pretty, but seems to auth * Small styling adjustments * Adjust Box layout slightly * Small styling adjustments * signing -> transactions * isDanger for links * Styling defaults
This commit is contained in:
@@ -21,9 +21,10 @@ function Box ({ children, className }: Props) {
|
||||
}
|
||||
|
||||
export default styled(Box)`
|
||||
background: transparent;
|
||||
border-top: ${defaults.hdrBorder};
|
||||
background: white;
|
||||
border: ${defaults.boxBorder};
|
||||
border-radius: ${defaults.borderRadius};
|
||||
box-shadow: ${defaults.boxShadow};
|
||||
color: ${defaults.color};
|
||||
font-family: ${defaults.fontFamily};
|
||||
font-size: ${defaults.fontSize};
|
||||
|
||||
@@ -23,7 +23,6 @@ function Header ({ children, className, label }: Props) {
|
||||
|
||||
export default styled(Header)`
|
||||
background: ${defaults.hdrBg};
|
||||
border-top: ${defaults.hdrBorder};
|
||||
box-sizing: border-box;
|
||||
color: ${defaults.hdrColor};
|
||||
font-family: ${defaults.fontFamily};
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// 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 React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { Link as RouterLink } from 'react-router-dom';
|
||||
|
||||
import defaults from './defaults';
|
||||
|
||||
type Props = {
|
||||
children?: React.ReactNode,
|
||||
className?: string,
|
||||
isDanger?: boolean,
|
||||
onClick?: () => void,
|
||||
to?: string
|
||||
};
|
||||
|
||||
function Link ({ children, className, onClick, to }: Props) {
|
||||
return (
|
||||
to
|
||||
? <RouterLink className={className} onClick={onClick} to={to}>{children}</RouterLink>
|
||||
: <a href='#' className={className} onClick={onClick} >{children}</a>
|
||||
);
|
||||
}
|
||||
|
||||
export default styled(Link)`
|
||||
color: ${({ isDanger }) =>
|
||||
isDanger
|
||||
? defaults.linkColorDanger
|
||||
: defaults.linkColor
|
||||
};
|
||||
opacity: 0.9;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
color: ${({ isDanger }) =>
|
||||
isDanger
|
||||
? defaults.linkColorDanger
|
||||
: defaults.linkColor
|
||||
};
|
||||
opacity: 1.0;
|
||||
}
|
||||
|
||||
&:visited {
|
||||
color: ${({ isDanger }) =>
|
||||
isDanger
|
||||
? defaults.linkColorDanger
|
||||
: defaults.linkColor
|
||||
};
|
||||
}
|
||||
`;
|
||||
@@ -42,6 +42,7 @@ export default styled(Tip)`
|
||||
border-left: 0.25rem solid ${(props) =>
|
||||
getColor(props).border
|
||||
};
|
||||
box-shadow: ${defaults.boxShadow};
|
||||
color: ${(props) =>
|
||||
getColor(props).color
|
||||
};
|
||||
|
||||
@@ -26,21 +26,6 @@ export default styled(View)`
|
||||
font-size: ${defaults.fontSize};
|
||||
line-height: ${defaults.lineHeight};
|
||||
|
||||
a {
|
||||
color: ${defaults.linkColor};
|
||||
opacity: 0.9;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
color: ${defaults.linkColor};
|
||||
opacity: 1.0;
|
||||
}
|
||||
|
||||
&:visited {
|
||||
color: ${defaults.linkColor};
|
||||
}
|
||||
}
|
||||
|
||||
h3 {
|
||||
margin: 0 0 0.75rem;
|
||||
text-transform: uppercase;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { AccountsFromCtx, OnActionFromCtx, RequestsFromCtx, SubtractProps } from './types';
|
||||
import { AccountsFromCtx, OnActionFromCtx, AuthRequestsFromCtx, SignRequestsFromCtx, SubtractProps } from './types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
@@ -12,11 +12,13 @@ const noop = (to?: string) => {
|
||||
|
||||
const AccountContext = React.createContext([] as AccountsFromCtx);
|
||||
const ActionContext = React.createContext(noop as OnActionFromCtx);
|
||||
const SigningContext = React.createContext([] as RequestsFromCtx);
|
||||
const AuthorizeContext = React.createContext([] as AuthRequestsFromCtx);
|
||||
const SigningContext = React.createContext([] as SignRequestsFromCtx);
|
||||
|
||||
export {
|
||||
AccountContext,
|
||||
ActionContext,
|
||||
AuthorizeContext,
|
||||
SigningContext
|
||||
};
|
||||
|
||||
@@ -36,7 +38,7 @@ export function withAccounts<P extends { accounts: AccountsFromCtx }> (Component
|
||||
};
|
||||
}
|
||||
|
||||
export function withAction<P extends { onAction: OnActionFromCtx }> (Component: React.ComponentType<P>): React.ComponentType<SubtractProps<P, { onAction: OnActionFromCtx }>> {
|
||||
export function withOnAction<P extends { onAction: OnActionFromCtx }> (Component: React.ComponentType<P>): React.ComponentType<SubtractProps<P, { onAction: OnActionFromCtx }>> {
|
||||
return (props: SubtractProps<P, { onAction: OnActionFromCtx }>) => {
|
||||
return (
|
||||
<ActionContext.Consumer>
|
||||
@@ -52,8 +54,24 @@ export function withAction<P extends { onAction: OnActionFromCtx }> (Component:
|
||||
};
|
||||
}
|
||||
|
||||
export function withRequests<P extends { requests: RequestsFromCtx }> (Component: React.ComponentType<P>): React.ComponentType<SubtractProps<P, { requests: RequestsFromCtx }>> {
|
||||
return (props: SubtractProps<P, { requests: RequestsFromCtx }>) => {
|
||||
export function withAuthRequests<P extends { requests: AuthRequestsFromCtx }> (Component: React.ComponentType<P>): React.ComponentType<SubtractProps<P, { requests: AuthRequestsFromCtx }>> {
|
||||
return (props: SubtractProps<P, { requests: AuthRequestsFromCtx }>) => {
|
||||
return (
|
||||
<AuthorizeContext.Consumer>
|
||||
{(requests) => (
|
||||
// @ts-ignore Something here with the props are going wonky
|
||||
<Component
|
||||
{...props}
|
||||
requests={requests}
|
||||
/>
|
||||
)}
|
||||
</AuthorizeContext.Consumer>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export function withSignRequests<P extends { requests: SignRequestsFromCtx }> (Component: React.ComponentType<P>): React.ComponentType<SubtractProps<P, { requests: SignRequestsFromCtx }>> {
|
||||
return (props: SubtractProps<P, { requests: SignRequestsFromCtx }>) => {
|
||||
return (
|
||||
<SigningContext.Consumer>
|
||||
{(requests) => (
|
||||
|
||||
@@ -14,19 +14,21 @@ const defaults: { [index: string]: any } = {
|
||||
btnColor: LINK_COLOR,
|
||||
btnColorDanger: DANGER_COLOR,
|
||||
btnPadding: '0.75rem 1rem',
|
||||
boxBorder: '0.25rem solid #e2e1e0',
|
||||
boxMargin: '0.75rem 0',
|
||||
boxPadding: '0 0.25rem',
|
||||
boxShadow: 'none', // '0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24)',
|
||||
color: TEXT_COLOR,
|
||||
colorLabel: LABEL_COLOR,
|
||||
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',
|
||||
fontSize: '1rem',
|
||||
hdrBg: 'transparent',
|
||||
hdrBorder: '0.25rem solid #eee',
|
||||
hdrColor: '#ccc',
|
||||
hdrBg: '#e2e1e0',
|
||||
hdrColor: '#878786',
|
||||
inputBorder: '#ccc',
|
||||
inputPadding: '0.5rem 0.75rem',
|
||||
lineHeight: '1.25',
|
||||
linkColor: LINK_COLOR,
|
||||
linkColorDanger: DANGER_COLOR,
|
||||
box: {
|
||||
error: {
|
||||
background: '#ffe6e6',
|
||||
|
||||
@@ -8,6 +8,7 @@ export { default as Box } from './Box';
|
||||
export { default as Button } from './Button';
|
||||
export { default as Header } from './Header';
|
||||
export { default as Input } from './Input';
|
||||
export { default as Link } from './Link';
|
||||
export { default as Loading } from './Loading';
|
||||
export { default as TextArea } from './TextArea';
|
||||
export { default as Tip } from './Tip';
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { SigningRequest } from '@polkadot/extension/background/types';
|
||||
import { AuthorizeRequest, SigningRequest } from '@polkadot/extension/background/types';
|
||||
import { KeyringJson } from '@polkadot/ui-keyring/types';
|
||||
|
||||
export type OmitProps<T, K> = Pick<T, Exclude<keyof T, K>>;
|
||||
@@ -10,4 +10,5 @@ export type SubtractProps<T, K> = OmitProps<T, keyof K>;
|
||||
|
||||
export type AccountsFromCtx = Array<KeyringJson>;
|
||||
export type OnActionFromCtx = (to?: string) => void;
|
||||
export type RequestsFromCtx = Array<SigningRequest>;
|
||||
export type AuthRequestsFromCtx = Array<AuthorizeRequest>;
|
||||
export type SignRequestsFromCtx = Array<SigningRequest>;
|
||||
|
||||
Reference in New Issue
Block a user