2020-07-07 06:22:22 +03:00
|
|
|
import * as React from "react";
|
|
|
|
import * as Constants from "~/common/constants";
|
|
|
|
|
|
|
|
import { css } from "@emotion/react";
|
2020-08-02 22:17:13 +03:00
|
|
|
import { ButtonPrimary } from "~/components/system/components/Buttons";
|
2020-07-07 06:22:22 +03:00
|
|
|
|
2020-07-21 17:58:04 +03:00
|
|
|
import Odometer from "~/vendor/odometer";
|
|
|
|
|
2020-07-07 06:22:22 +03:00
|
|
|
const STYLES_CREATE_TOKEN = css`
|
2020-07-10 08:03:37 +03:00
|
|
|
font-family: ${Constants.font.text};
|
|
|
|
box-sizing: border-box;
|
2020-07-07 06:22:22 +03:00
|
|
|
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
|
|
|
|
display: block;
|
|
|
|
max-width: 480px;
|
|
|
|
width: 100%;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_CREATE_TOKEN_TOP = css`
|
2020-07-16 21:03:52 +03:00
|
|
|
font-family: ${Constants.font.medium};
|
2020-07-07 06:22:22 +03:00
|
|
|
background: ${Constants.system.black};
|
|
|
|
color: ${Constants.system.white};
|
2020-07-16 21:03:52 +03:00
|
|
|
box-sizing: border-box;
|
2020-07-07 06:22:22 +03:00
|
|
|
font-size: 12px;
|
|
|
|
border-radius: 4px 4px 0 0;
|
|
|
|
min-height: 88px;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
2020-07-21 21:31:50 +03:00
|
|
|
position: relative;
|
|
|
|
|
|
|
|
.odometer:hover + span {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
2020-07-07 06:22:22 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_CREATE_TOKEN_BOTTOM = css`
|
2020-07-10 08:03:37 +03:00
|
|
|
box-sizing: border-box;
|
2020-07-07 06:22:22 +03:00
|
|
|
background: ${Constants.system.white};
|
|
|
|
border-radius: 0 0 4px 4px;
|
|
|
|
padding: 16px;
|
|
|
|
`;
|
|
|
|
|
2020-07-21 21:31:50 +03:00
|
|
|
const STYLES_CREATE_TOKEN_COPY_INFO = css`
|
|
|
|
position: absolute;
|
|
|
|
top: 10px;
|
|
|
|
right: 20px;
|
|
|
|
opacity: 0;
|
|
|
|
transition: opacity 0.4s ease-in-out;
|
|
|
|
`;
|
|
|
|
|
2020-07-07 06:22:22 +03:00
|
|
|
export const CreateToken = (props) => {
|
2020-07-21 17:58:04 +03:00
|
|
|
const odometerNode = React.useRef(null);
|
2020-07-21 21:31:50 +03:00
|
|
|
const [odometer, setOdometer] = React.useState(null);
|
|
|
|
const [isCopied, setCopyStatus] = React.useState(false);
|
|
|
|
|
|
|
|
const handleCopy = () => {
|
|
|
|
navigator.clipboard.writeText(props.token);
|
|
|
|
setCopyStatus(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
// (NOTE: daniel) Reset copy status
|
|
|
|
setInterval(() => setCopyStatus(false), 50000);
|
2020-07-21 17:58:04 +03:00
|
|
|
|
|
|
|
if (props.token) {
|
|
|
|
let hash = props.token.replace(/-/g, "");
|
|
|
|
odometer.start({ to: hash });
|
|
|
|
}
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
const newOdometer = new Odometer({ node: odometerNode.current });
|
|
|
|
|
|
|
|
setOdometer(newOdometer);
|
|
|
|
}, []);
|
|
|
|
|
2020-07-07 06:22:22 +03:00
|
|
|
return (
|
|
|
|
<div css={STYLES_CREATE_TOKEN}>
|
|
|
|
<div css={STYLES_CREATE_TOKEN_TOP}>
|
2020-07-21 21:31:50 +03:00
|
|
|
<div ref={odometerNode} onClick={handleCopy} />
|
|
|
|
<span css={STYLES_CREATE_TOKEN_COPY_INFO}>
|
|
|
|
{isCopied ? "Copied" : "Copy"}
|
|
|
|
</span>
|
2020-07-07 06:22:22 +03:00
|
|
|
</div>
|
|
|
|
<div css={STYLES_CREATE_TOKEN_BOTTOM}>
|
2020-08-02 22:17:13 +03:00
|
|
|
<ButtonPrimary full onClick={props.onClick}>
|
2020-07-07 06:22:22 +03:00
|
|
|
Generate new Powergate token
|
2020-08-02 22:17:13 +03:00
|
|
|
</ButtonPrimary>
|
2020-07-07 06:22:22 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|