2020-06-19 06:57:57 +03:00
|
|
|
import * as React from "react";
|
|
|
|
import * as Strings from "~/common/strings";
|
|
|
|
import * as Constants from "~/common/constants";
|
2020-09-05 02:15:29 +03:00
|
|
|
import * as SVG from "~/common/svg";
|
2020-06-19 06:57:57 +03:00
|
|
|
import * as System from "~/components/system";
|
2020-04-09 00:29:13 +03:00
|
|
|
|
2020-06-19 06:57:57 +03:00
|
|
|
import { css } from "@emotion/react";
|
2020-09-12 01:25:33 +03:00
|
|
|
import { dispatchCustomEvent } from "~/common/custom-events";
|
2020-09-09 20:56:35 +03:00
|
|
|
import { LoaderSpinner } from "~/components/system/components/Loaders";
|
2020-04-09 00:29:13 +03:00
|
|
|
|
2020-06-19 06:57:57 +03:00
|
|
|
import Section from "~/components/core/Section";
|
|
|
|
import ScenePage from "~/components/core/ScenePage";
|
2020-08-22 07:25:34 +03:00
|
|
|
import ScenePageHeader from "~/components/core/ScenePageHeader";
|
2020-04-09 00:29:13 +03:00
|
|
|
|
|
|
|
const STYLES_GROUP = css`
|
|
|
|
padding: 24px;
|
|
|
|
`;
|
|
|
|
|
2020-08-14 11:51:37 +03:00
|
|
|
const STYLES_ROW = css`
|
|
|
|
display: flex;
|
|
|
|
align-items: flex-start;
|
|
|
|
justify-content: space-between;
|
|
|
|
padding: 24px;
|
2020-04-09 00:29:13 +03:00
|
|
|
width: 100%;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_CIRCLE_BUTTON = css`
|
|
|
|
height: 48px;
|
|
|
|
width: 48px;
|
|
|
|
border-radius: 48px;
|
|
|
|
display: inline-flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
background: ${Constants.system.black};
|
|
|
|
color: ${Constants.system.white};
|
|
|
|
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
|
|
|
|
cursor: pointer;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_TEXT = css`
|
|
|
|
min-width: 5%;
|
|
|
|
padding-top: 6px;
|
|
|
|
width: 100%;
|
2020-08-14 11:51:37 +03:00
|
|
|
overflow-wrap: break-word;
|
2020-04-09 00:29:13 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_FOCUS = css`
|
|
|
|
font-size: ${Constants.typescale.lvl1};
|
2020-07-02 11:24:14 +03:00
|
|
|
font-family: ${Constants.font.medium};
|
2020-04-09 00:29:13 +03:00
|
|
|
overflow-wrap: break-word;
|
|
|
|
width: 100%;
|
|
|
|
|
|
|
|
strong {
|
2020-07-02 11:24:14 +03:00
|
|
|
font-family: ${Constants.font.semiBold};
|
2020-04-09 00:29:13 +03:00
|
|
|
font-weight: 400;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_FOCUS_EMPAHSIS = css`
|
|
|
|
color: ${Constants.system.brand};
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_SUBTEXT = css`
|
|
|
|
margin-top: 8px;
|
|
|
|
font-size: 12px;
|
2020-08-14 11:51:37 +03:00
|
|
|
overflow-wrap: break-word;
|
2020-04-09 00:29:13 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_ACTIONS = css`
|
|
|
|
flex-shrink: 0;
|
|
|
|
padding-left: 24px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_ITEM = css`
|
|
|
|
margin-top: 24px;
|
|
|
|
display: inline-flex;
|
|
|
|
flex-direction: column;
|
2020-06-08 09:45:53 +03:00
|
|
|
max-width: 220px;
|
2020-04-09 00:29:13 +03:00
|
|
|
margin-right: 32px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_ITEM_GROUP = css`
|
|
|
|
display: flex;
|
|
|
|
align-items: flex-start;
|
|
|
|
justify-content: flex-start;
|
|
|
|
`;
|
|
|
|
|
|
|
|
export default class SceneWallet extends React.Component {
|
2020-09-09 20:56:35 +03:00
|
|
|
state = {};
|
|
|
|
|
|
|
|
async componentDidMount() {
|
|
|
|
let networkViewer;
|
|
|
|
try {
|
|
|
|
const response = await fetch("/api/network");
|
|
|
|
const json = await response.json();
|
|
|
|
networkViewer = json.data;
|
|
|
|
} catch (e) {}
|
|
|
|
console.log(networkViewer);
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
networkViewer,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-09 00:29:13 +03:00
|
|
|
state = { table_transaction: null, visible: false };
|
|
|
|
|
|
|
|
_handleChange = (e) => {
|
|
|
|
this.setState({ [e.target.name]: e.target.value });
|
|
|
|
};
|
|
|
|
|
|
|
|
_handleWalletChange = (e) => {
|
|
|
|
this.setState({ visible: false });
|
|
|
|
this.props.onSelectedChange(e);
|
|
|
|
};
|
|
|
|
|
|
|
|
_handleMakeAddressVisible = () => {
|
|
|
|
this.setState({ visible: !this.state.visible });
|
|
|
|
};
|
|
|
|
|
2020-06-08 09:45:53 +03:00
|
|
|
_handleCopy = (text) => {
|
|
|
|
Strings.copyText(text);
|
2020-09-12 01:25:33 +03:00
|
|
|
dispatchCustomEvent({
|
|
|
|
name: "create-alert",
|
|
|
|
detail: { alert: { message: "Copied to clipboard!", status: "INFO" } },
|
|
|
|
});
|
2020-06-08 09:45:53 +03:00
|
|
|
};
|
|
|
|
|
2020-04-09 00:29:13 +03:00
|
|
|
render() {
|
2020-09-09 20:56:35 +03:00
|
|
|
// TODO(jim): Temporary because of read only Filecoin Addresses
|
|
|
|
const { networkViewer } = this.state;
|
|
|
|
|
|
|
|
const addressMap = {};
|
|
|
|
const addresses = [];
|
|
|
|
let selected = null;
|
|
|
|
|
|
|
|
if (networkViewer) {
|
|
|
|
networkViewer.powerInfo.balancesList.forEach((a) => {
|
|
|
|
addressMap[a.addr.addr] = { ...a.addr, balance: a.balance };
|
|
|
|
addresses.push({ ...a.addr, balance: a.balance });
|
|
|
|
});
|
|
|
|
|
|
|
|
if (addresses.length) {
|
|
|
|
selected = addresses[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
let transactions = [];
|
|
|
|
if (selected.transactions) {
|
|
|
|
transactions = [...selected.transactions];
|
|
|
|
}
|
2020-04-09 00:29:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ScenePage>
|
2020-09-09 20:56:35 +03:00
|
|
|
<ScenePageHeader title="Filecoin Testnet wallet">
|
|
|
|
This is your testnet wallet address. It is prefilled by Textile to
|
|
|
|
help test the Filecoin Testnet.
|
2020-08-22 07:25:34 +03:00
|
|
|
</ScenePageHeader>
|
2020-04-09 00:29:13 +03:00
|
|
|
|
2020-09-09 20:56:35 +03:00
|
|
|
{networkViewer ? (
|
|
|
|
<Section
|
|
|
|
onAction={this.props.onAction}
|
|
|
|
onNavigateTo={this.props.onNavigateTo}
|
|
|
|
title="Your Filecoin Testnet address"
|
|
|
|
style={{ maxWidth: `568px`, minWidth: "auto" }}
|
|
|
|
buttons={
|
|
|
|
[
|
|
|
|
/*
|
2020-04-09 00:29:13 +03:00
|
|
|
{
|
2020-06-19 06:57:57 +03:00
|
|
|
name: "Create a new address",
|
|
|
|
type: "SIDEBAR",
|
|
|
|
value: "SIDEBAR_CREATE_WALLET_ADDRESS",
|
2020-04-09 00:29:13 +03:00
|
|
|
},
|
2020-09-09 20:56:35 +03:00
|
|
|
*/
|
|
|
|
]
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{/* <div css={STYLES_GROUP}>
|
2020-04-09 00:29:13 +03:00
|
|
|
<System.SelectMenu
|
|
|
|
label="Select your address"
|
|
|
|
name="address"
|
2020-09-09 20:56:35 +03:00
|
|
|
value={selected.addr}
|
2020-04-09 00:29:13 +03:00
|
|
|
category="address"
|
|
|
|
onChange={this._handleWalletChange}
|
2020-09-09 20:56:35 +03:00
|
|
|
options={addresses}
|
2020-07-16 05:45:23 +03:00
|
|
|
/>
|
2020-09-09 20:56:35 +03:00
|
|
|
</div> */}
|
2020-04-09 00:29:13 +03:00
|
|
|
|
2020-09-09 20:56:35 +03:00
|
|
|
<div css={STYLES_ROW} style={{ marginTop: 24 }}>
|
|
|
|
<div css={STYLES_TEXT}>
|
|
|
|
<div>
|
|
|
|
<div css={STYLES_FOCUS}>
|
|
|
|
{this.state.visible ? (
|
|
|
|
selected.addr
|
|
|
|
) : (
|
|
|
|
<span css={STYLES_FOCUS_EMPAHSIS}>Hidden</span>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<div css={STYLES_SUBTEXT}>Filecoin address</div>
|
2020-04-09 00:29:13 +03:00
|
|
|
</div>
|
|
|
|
|
2020-09-09 20:56:35 +03:00
|
|
|
<div style={{ marginTop: 24 }}>
|
2020-08-22 07:25:34 +03:00
|
|
|
<div css={STYLES_FOCUS}>
|
2020-09-09 20:56:35 +03:00
|
|
|
{selected.name}{" "}
|
|
|
|
{networkViewer.settings_cold_default_address ===
|
|
|
|
selected.addr ? (
|
|
|
|
<strong css={STYLES_FOCUS_EMPAHSIS}>(Primary)</strong>
|
|
|
|
) : null}
|
2020-08-22 07:25:34 +03:00
|
|
|
</div>
|
2020-09-09 20:56:35 +03:00
|
|
|
<div css={STYLES_SUBTEXT}>Filecoin address alias</div>
|
2020-04-09 00:29:13 +03:00
|
|
|
</div>
|
|
|
|
|
2020-09-09 20:56:35 +03:00
|
|
|
<div css={STYLES_ITEM_GROUP}>
|
|
|
|
<div css={STYLES_ITEM}>
|
|
|
|
<div css={STYLES_FOCUS}>
|
|
|
|
{Strings.formatAsFilecoinConversion(selected.balance)}
|
|
|
|
</div>
|
|
|
|
<div css={STYLES_SUBTEXT}>Filecoin</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div css={STYLES_ITEM}>
|
|
|
|
<div css={STYLES_FOCUS}>{selected.type}</div>
|
|
|
|
<div css={STYLES_SUBTEXT}>Address type</div>
|
|
|
|
</div>
|
2020-04-09 00:29:13 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-09-09 20:56:35 +03:00
|
|
|
<div css={STYLES_ACTIONS}>
|
|
|
|
<span
|
|
|
|
css={STYLES_CIRCLE_BUTTON}
|
|
|
|
onClick={this._handleMakeAddressVisible}
|
|
|
|
style={{
|
|
|
|
marginRight: 16,
|
|
|
|
backgroundColor: this.state.visible
|
|
|
|
? null
|
|
|
|
: Constants.system.brand,
|
|
|
|
}}
|
2020-08-22 07:25:34 +03:00
|
|
|
>
|
2020-09-09 20:56:35 +03:00
|
|
|
<SVG.Privacy height="16px" />
|
|
|
|
</span>
|
|
|
|
<span
|
|
|
|
css={STYLES_CIRCLE_BUTTON}
|
|
|
|
onClick={() => this._handleCopy(selected.address)}
|
|
|
|
>
|
|
|
|
<SVG.CopyAndPaste height="16px" />
|
|
|
|
</span>
|
2020-04-09 00:29:13 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-09-09 20:56:35 +03:00
|
|
|
</Section>
|
|
|
|
) : (
|
|
|
|
<LoaderSpinner style={{ marginTop: 48, height: 32, width: 32 }} />
|
|
|
|
)}
|
2020-04-09 00:29:13 +03:00
|
|
|
</ScenePage>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|