slate/common/state.js

133 lines
3.0 KiB
JavaScript
Raw Normal View History

2020-06-19 06:57:57 +03:00
const STATIC_ADDRESS_TYPE_MAP = {
bls: "BLS",
secp256k1: "SECP256K1",
multisig: "MULTISIG",
2020-06-19 06:57:57 +03:00
};
const transformAddresses = (addrsList, info) => {
const balanceMap = {};
info.balancesList.forEach((b) => {
balanceMap[b.addr.addr] = b.balance;
});
return addrsList.map((each, index) => {
return {
id: each.addr,
value: each.addr,
balance: balanceMap[each.addr],
name: each.name,
address: each.addr,
type: STATIC_ADDRESS_TYPE_MAP[each.type],
deals: 0,
transactions: [],
};
});
};
2020-07-27 04:51:51 +03:00
const transformPeers = (peersList = []) => {
return peersList.map((each) => {
return {
id: each.addrInfo.id,
"peer-avatar": null,
"chain-head": null,
height: null,
location: null,
upload: null,
download: null,
};
});
};
export const getSelectedState = (props) => {
if (!props) {
return null;
}
const { info } = props;
if (!info || !info.id) {
return {
address: "",
};
}
return {
address: null,
address: info.defaultStorageConfig.cold.filecoin.addr,
};
};
export const getInitialState = (props) => {
if (!props) {
return null;
}
return { ...props };
};
export const _deprecated_getInitialState = (props) => {
if (!props) {
return null;
}
const {
2020-08-22 08:45:50 +03:00
id,
status,
stats,
messageList,
peersList,
addrsList,
info,
library,
data,
settings,
username,
storageList,
retrievalList,
2020-07-27 04:51:51 +03:00
slates,
keys,
} = props;
return {
2020-08-22 08:45:50 +03:00
id,
username,
2020-08-22 08:45:50 +03:00
data,
// 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:
info.defaultStorageConfig.cold.filecoin.dealMinDuration,
settings_cold_default_replication_factor:
info.defaultStorageConfig.cold.filecoin.repFactor,
settings_cold_default_excluded_miners:
info.defaultStorageConfig.cold.filecoin.excludedMinersList,
settings_cold_default_trusted_miners:
info.defaultStorageConfig.cold.filecoin.trustedMinersList,
settings_cold_default_max_price:
info.defaultStorageConfig.cold.filecoin.maxPrice,
settings_cold_default_auto_renew:
info.defaultStorageConfig.cold.filecoin.renew.enabled,
settings_cold_default_auto_renew_max_price:
info.defaultStorageConfig.cold.filecoin.renew.threshold,
storageList,
retrievalList,
2020-07-27 04:51:51 +03:00
slates,
keys,
stats,
library,
peers: transformPeers(peersList),
addresses: transformAddresses(addrsList, info),
};
};