bytes: moves hardcoded byte calculation out of client

This commit is contained in:
@wwwjim 2020-08-03 19:45:59 -07:00
parent d4e69655ac
commit 6800d90de5
5 changed files with 28 additions and 20 deletions

View File

@ -63,6 +63,7 @@ export const getInitialState = (props) => {
const {
status,
stats,
messageList,
peersList,
addrsList,
@ -83,16 +84,17 @@ export const getInitialState = (props) => {
data: {
photo: data.photo,
},
upload_bandwidth: 0,
download_bandwidth: 0,
// NOTE(jim): Local settings
settings_deals_auto_approve: settings.deals_auto_approve,
// NOTE(jim): Powergate Hot Settings
settings_hot_enabled: info.defaultStorageConfig.hot.enabled,
settings_hot_allow_unfreeze: info.defaultStorageConfig.hot.allowUnfreeze,
settings_hot_ipfs_add_timeout:
info.defaultStorageConfig.hot.ipfs.addTimeout,
// NOTE(jim): Powergate Cold Settings
settings_cold_enabled: info.defaultStorageConfig.cold.enabled,
settings_cold_default_address: info.defaultStorageConfig.cold.filecoin.addr,
settings_cold_default_duration:
@ -110,16 +112,13 @@ export const getInitialState = (props) => {
settings_cold_default_auto_renew_max_price:
info.defaultStorageConfig.cold.filecoin.renew.threshold,
notifications: [],
payment_channels_active: [],
payment_channels_redeemed: [],
data_transfers: [],
storageList,
retrievalList,
slates,
keys,
stats,
library,
peers: transformPeers(peersList),
addresses: transformAddresses(addrsList, info),
library,
};
};

View File

@ -236,13 +236,6 @@ class NodeReference extends React.Component {
export default class ApplicationNavigation extends React.Component {
render() {
// TODO(jim):
// Calculate this idea elsewhere if you keep it.
let bytes = 0;
this.props.viewer.library[0].children.forEach((each) => {
bytes = each.size + bytes;
});
return (
<nav css={STYLES_NAVIGATION}>
{this.props.navigation.map((each) => {
@ -271,7 +264,7 @@ export default class ApplicationNavigation extends React.Component {
);
})}
<br />
<DataMeter currentBytes={bytes} />
<DataMeter stats={this.props.viewer.stats} />
</nav>
);
}

View File

@ -89,28 +89,31 @@ const STYLES_HREF = css`
`;
export default (props) => {
const percentage = props.currentBytes / MAX_IN_BYTES;
console.log(percentage * 100);
const percentage = props.stats.bytes / props.stats.maximumBytes;
return (
<div css={STYLES_GUTTER}>
<div css={STYLES_CONTAINER}>
<System.P style={{ fontSize: 12 }}>
<strong css={STYLES_TITLE}>Usage</strong>
Slate users get 10GB of IPFS storage for free.{" "}
Slate users get 1GB of IPFS storage from Textile for free{" "}
<strong
css={STYLES_HREF}
onClick={() => alert("TODO: SUBSCRIPTION OPTIONS")}
>
(upgrade)
</strong>
. In the future you can extend this with your own plugins using our
SDK.
<br />
<br />
</System.P>
<div css={STYLES_STATS_ROW}>
<div css={STYLES_LEFT}>{Strings.bytesToSize(props.currentBytes)}</div>
<div css={STYLES_RIGHT}>{Strings.bytesToSize(MAX_IN_BYTES)}</div>
<div css={STYLES_LEFT}>{Strings.bytesToSize(props.stats.bytes)}</div>
<div css={STYLES_RIGHT}>
{Strings.bytesToSize(props.stats.maximumBytes)}
</div>
</div>
<div css={STYLES_ROW}>

View File

@ -2,3 +2,6 @@ export const POLLING_RATE = 5000;
export const POWERGATE_HOST = "https://grpcweb.slate.textile.io";
export const FILE_STORAGE_URL = "./public/static/files/";
export const GITHUB_URL = "https://github.com/filecoin-project/slate";
// NOTE(jim): 1 GB from Ignacio
export const TEXTILE_ACCOUNT_BYTE_LIMIT = 1073741824;

View File

@ -1,6 +1,7 @@
import * as Utilities from "~/node_common/utilities";
import * as Data from "~/node_common/data";
import * as Powergate from "~/node_common/powergate";
import * as Constants from "~/node_common/constants";
export const getById = async ({ id }) => {
const user = await Data.getUserById({
@ -22,6 +23,11 @@ export const getById = async ({ id }) => {
const keysRaw = await Data.getAPIKeysByUserId({ userId: id });
const keys = JSON.parse(JSON.stringify(keysRaw));
let bytes = 0;
user.data.library[0].children.forEach((each) => {
bytes = each.size + bytes;
});
try {
data = {
id: user.id,
@ -29,6 +35,10 @@ export const getById = async ({ id }) => {
settings: {
deals_auto_approve: user.data.settings_deals_auto_approve,
},
stats: {
bytes,
maximumBytes: Constants.TEXTILE_ACCOUNT_BYTE_LIMIT,
},
username: user.username,
library: user.data.library,
storageList: [],