de864fe828
* create nymlogo component * start scaffolding * set up mnemonic check pages * start on guess words components * mnemonic verification work * more mnemonic verification * hard code number of words to generate * mnemonic verification section 2 * add password strength indicator * add password confirmation * update text * disable word tiles on selection * add exisiting account page * finish exisiting account login * add back buttons to return to the initial screen * update button size * create network selection component * implement network selector component * update page types * make currency and network dynamic variables * remove unused env values * [ci skip] Generate TS types * lighten subtext * display network name in app * create network selector component * remove old network display component * update state in response to network selection * state updates * implement logout * refresh delegations on network change * Initial implementation of data encryption/decryption with provided password * Removing milhon network. * Removing more milhon references. * Adding in mainnet constants for network defaults. Contracts are not yet defined. * Allow encryption of EncryptedData<T>, where T: Serialize + Deserialize It uses serde_json for representation of T * Making contract addresses optional * [ci skip] Generate TS types * Add mainnet as implicit network * Fix unreachable code warning * Using zeroize for encrypted data + password * Get denom dynamically * initialize network to undefined before login * Fix str parse to dynamic denom * Pass network in config all the way to hd wallet generation * Fixed encrypted data deserialization * Storing and loading accounts from the disk * Additional error variants * Fix clippy in wallet * Simplified contract address parsing * display error * fix typo * uncomment code * Use sandbox as backend default again * Reorganised wallet storage for easier testing + unit test * Fix denom showing * to_major call only on printable balance * fix up state changes Co-authored-by: Dave Hrycyszyn <futurechimp@users.noreply.github.com> Co-authored-by: fmtabbara <fmtabbara@users.noreply.github.com> Co-authored-by: Jędrzej Stuczyński <jedrzej.stuczynski@gmail.com> Co-authored-by: Bogdan-Ștefan Neacșu <bogdan@nymtech.net>
142 lines
5.3 KiB
Rust
142 lines
5.3 KiB
Rust
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
use std::collections::HashMap;
|
|
|
|
use crate::{mainnet, qa, sandbox, ValidatorDetails};
|
|
|
|
#[derive(Copy, Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
|
pub enum Network {
|
|
QA,
|
|
SANDBOX,
|
|
MAINNET,
|
|
}
|
|
|
|
impl Network {
|
|
pub fn bech32_prefix(&self) -> String {
|
|
match self {
|
|
Self::QA => String::from(qa::BECH32_PREFIX),
|
|
Self::SANDBOX => String::from(sandbox::BECH32_PREFIX),
|
|
Self::MAINNET => String::from(mainnet::BECH32_PREFIX),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct NetworkDetails {
|
|
bech32_prefix: String,
|
|
denom: String,
|
|
mixnet_contract_address: String,
|
|
vesting_contract_address: String,
|
|
bandwidth_claim_contract_address: String,
|
|
rewarding_validator_address: String,
|
|
validators: Vec<ValidatorDetails>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct SupportedNetworks {
|
|
networks: HashMap<Network, NetworkDetails>,
|
|
}
|
|
|
|
impl SupportedNetworks {
|
|
pub fn new(support: Vec<Network>) -> Self {
|
|
let mut networks = HashMap::new();
|
|
|
|
for network in support {
|
|
match network {
|
|
Network::MAINNET => networks.insert(
|
|
Network::MAINNET,
|
|
NetworkDetails {
|
|
bech32_prefix: String::from(mainnet::BECH32_PREFIX),
|
|
denom: String::from(mainnet::DENOM),
|
|
mixnet_contract_address: String::from(mainnet::MIXNET_CONTRACT_ADDRESS),
|
|
vesting_contract_address: String::from(mainnet::VESTING_CONTRACT_ADDRESS),
|
|
bandwidth_claim_contract_address: String::from(
|
|
mainnet::BANDWIDTH_CLAIM_CONTRACT_ADDRESS,
|
|
),
|
|
rewarding_validator_address: String::from(
|
|
mainnet::REWARDING_VALIDATOR_ADDRESS,
|
|
),
|
|
validators: mainnet::validators(),
|
|
},
|
|
),
|
|
|
|
Network::SANDBOX => networks.insert(
|
|
Network::SANDBOX,
|
|
NetworkDetails {
|
|
bech32_prefix: String::from(sandbox::BECH32_PREFIX),
|
|
denom: String::from(sandbox::DENOM),
|
|
mixnet_contract_address: String::from(sandbox::MIXNET_CONTRACT_ADDRESS),
|
|
vesting_contract_address: String::from(sandbox::VESTING_CONTRACT_ADDRESS),
|
|
bandwidth_claim_contract_address: String::from(
|
|
sandbox::BANDWIDTH_CLAIM_CONTRACT_ADDRESS,
|
|
),
|
|
rewarding_validator_address: String::from(
|
|
sandbox::REWARDING_VALIDATOR_ADDRESS,
|
|
),
|
|
validators: sandbox::validators(),
|
|
},
|
|
),
|
|
Network::QA => networks.insert(
|
|
Network::QA,
|
|
NetworkDetails {
|
|
bech32_prefix: String::from(qa::BECH32_PREFIX),
|
|
denom: String::from(qa::DENOM),
|
|
mixnet_contract_address: String::from(qa::MIXNET_CONTRACT_ADDRESS),
|
|
vesting_contract_address: String::from(qa::VESTING_CONTRACT_ADDRESS),
|
|
bandwidth_claim_contract_address: String::from(
|
|
qa::BANDWIDTH_CLAIM_CONTRACT_ADDRESS,
|
|
),
|
|
rewarding_validator_address: String::from(qa::REWARDING_VALIDATOR_ADDRESS),
|
|
validators: qa::validators(),
|
|
},
|
|
),
|
|
};
|
|
}
|
|
SupportedNetworks { networks }
|
|
}
|
|
|
|
pub fn bech32_prefix(&self, network: Network) -> Option<&str> {
|
|
self.networks
|
|
.get(&network)
|
|
.map(|network_details| network_details.bech32_prefix.as_str())
|
|
}
|
|
|
|
pub fn denom(&self, network: Network) -> Option<&str> {
|
|
self.networks
|
|
.get(&network)
|
|
.map(|network_details| network_details.denom.as_str())
|
|
}
|
|
|
|
pub fn mixnet_contract_address(&self, network: Network) -> Option<&str> {
|
|
self.networks
|
|
.get(&network)
|
|
.map(|network_details| network_details.mixnet_contract_address.as_str())
|
|
}
|
|
|
|
pub fn vesting_contract_address(&self, network: Network) -> Option<&str> {
|
|
self.networks
|
|
.get(&network)
|
|
.map(|network_details| network_details.vesting_contract_address.as_str())
|
|
}
|
|
|
|
pub fn bandwidth_claim_contract_address(&self, network: Network) -> Option<&str> {
|
|
self.networks
|
|
.get(&network)
|
|
.map(|network_details| network_details.bandwidth_claim_contract_address.as_str())
|
|
}
|
|
|
|
pub fn rewarding_validator_address(&self, network: Network) -> Option<&str> {
|
|
self.networks
|
|
.get(&network)
|
|
.map(|network_details| network_details.rewarding_validator_address.as_str())
|
|
}
|
|
|
|
pub fn validators(&self, network: Network) -> Option<&Vec<ValidatorDetails>> {
|
|
self.networks
|
|
.get(&network)
|
|
.map(|network_details| &network_details.validators)
|
|
}
|
|
}
|