Have basic lock and check working in walelt
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import * as React from 'react';
|
||||
import { AllowanceStateView } from 'ts/components/ui/allowance_state_view';
|
||||
|
||||
export interface AllowanceStateToggleProps {}
|
||||
|
||||
const flip = () => Math.random() < 0.5;
|
||||
|
||||
export const AllowanceStateToggle: React.StatelessComponent<AllowanceStateToggleProps> = () => (
|
||||
<AllowanceStateView allowanceState={flip() ? 'locked' : 'unlocked'} />
|
||||
);
|
||||
42
packages/website/ts/components/ui/allowance_state_view.tsx
Normal file
42
packages/website/ts/components/ui/allowance_state_view.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
import { colors } from '@0xproject/react-shared';
|
||||
import * as React from 'react';
|
||||
import { styled } from 'ts/style/theme';
|
||||
|
||||
export type AllowanceState = 'locked' | 'unlocked' | 'loading';
|
||||
|
||||
export interface AllowanceStateViewProps {
|
||||
allowanceState: AllowanceState;
|
||||
}
|
||||
|
||||
export const AllowanceStateView: React.StatelessComponent<AllowanceStateViewProps> = ({ allowanceState }) => {
|
||||
switch (allowanceState) {
|
||||
case 'locked':
|
||||
return renderLock();
|
||||
case 'unlocked':
|
||||
return renderCheck();
|
||||
case 'loading':
|
||||
return <div>'...'</div>;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const renderCheck = (color: string = '#37D400') => (
|
||||
<svg width="17" height="17" viewBox="0 0 17 17" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="8.5" cy="8.5" r="8.5" fill={color} />
|
||||
<path
|
||||
d="M2.5 4.5L1.79289 5.20711L2.5 5.91421L3.20711 5.20711L2.5 4.5ZM-0.707107 2.70711L1.79289 5.20711L3.20711 3.79289L0.707107 1.29289L-0.707107 2.70711ZM3.20711 5.20711L7.70711 0.707107L6.29289 -0.707107L1.79289 3.79289L3.20711 5.20711Z"
|
||||
transform="translate(5 6.5)"
|
||||
fill="white"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
|
||||
const renderLock = () => (
|
||||
<svg width="12" height="15" viewBox="0 0 12 15" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path
|
||||
d="M6 0C3.51604 0 1.48688 2.0495 1.48688 4.55837V5.86581C0.664723 5.86581 -3.33647e-08 6.53719 -3.33647e-08 7.36759V13.3217C-3.33647e-08 14.1521 0.664723 14.8235 1.48688 14.8235H10.5131C11.3353 14.8235 12 14.1521 12 13.3217V7.36759C12 6.53719 11.3353 5.86581 10.5131 5.86581V4.55837C10.5131 2.0495 8.48396 0 6 0ZM8.93878 5.86581H3.06122V4.55837C3.06122 2.9329 4.37318 1.59013 6 1.59013C7.62682 1.59013 8.93878 2.9329 8.93878 4.55837V5.86581Z"
|
||||
fill="black"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
@@ -29,6 +29,7 @@ import { PlaceHolder } from 'ts/components/wallet/placeholder';
|
||||
import { StandardIconRow } from 'ts/components/wallet/standard_icon_row';
|
||||
import { WrapEtherItem } from 'ts/components/wallet/wrap_ether_item';
|
||||
import { AllowanceToggle } from 'ts/containers/inputs/allowance_toggle';
|
||||
import { AllowanceStateToggle } from 'ts/containers/inputs/allowance_state_toggle';
|
||||
import { Dispatcher } from 'ts/redux/dispatcher';
|
||||
import { colors } from 'ts/style/colors';
|
||||
import {
|
||||
@@ -396,10 +397,10 @@ export class Wallet extends React.Component<WalletProps, WalletState> {
|
||||
const shouldShowToggle = !_.isUndefined(config.allowanceToggleConfig);
|
||||
// if we don't have a toggle, we still want some space to the right of the "wrap" button so that it aligns with
|
||||
// the "unwrap" button in the row below
|
||||
const toggle = shouldShowToggle ? (
|
||||
this._renderAllowanceToggle(config.allowanceToggleConfig)
|
||||
) : (
|
||||
<div style={{ width: NO_ALLOWANCE_TOGGLE_SPACE_WIDTH }} />
|
||||
const toggle = (
|
||||
<Container width={NO_ALLOWANCE_TOGGLE_SPACE_WIDTH}>
|
||||
{shouldShowToggle && this._renderAllowanceToggle(config.allowanceToggleConfig)}
|
||||
</Container>
|
||||
);
|
||||
return (
|
||||
<div className="flex items-center">
|
||||
@@ -412,15 +413,16 @@ export class Wallet extends React.Component<WalletProps, WalletState> {
|
||||
}
|
||||
private _renderAllowanceToggle(config: AllowanceToggleConfig): React.ReactNode {
|
||||
// TODO: Error handling
|
||||
return (
|
||||
<AllowanceToggle
|
||||
blockchain={this.props.blockchain}
|
||||
token={config.token}
|
||||
tokenState={config.tokenState}
|
||||
isDisabled={!config.tokenState.isLoaded}
|
||||
refetchTokenStateAsync={async () => this.props.refetchTokenStateAsync(config.token.address)}
|
||||
/>
|
||||
);
|
||||
// return (
|
||||
// <AllowanceToggle
|
||||
// blockchain={this.props.blockchain}
|
||||
// token={config.token}
|
||||
// tokenState={config.tokenState}
|
||||
// isDisabled={!config.tokenState.isLoaded}
|
||||
// refetchTokenStateAsync={async () => this.props.refetchTokenStateAsync(config.token.address)}
|
||||
// />
|
||||
// );
|
||||
return <AllowanceStateToggle />;
|
||||
}
|
||||
private _renderAmount(
|
||||
amount: BigNumber,
|
||||
|
||||
Reference in New Issue
Block a user