Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Settings] Network Fee #36

Merged
merged 1 commit into from Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -77,7 +77,7 @@
"nightwatch": "^0.9.12",
"node-notifier": "^5.1.2",
"normalize.css": "^8.0.0",
"numeral": "^2.0.6",
"numeral": "github:michaeltomasik/Numeral-js#master",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"ora": "^1.2.0",
"phantomjs-prebuilt": "^2.1.14",
Expand Down
1 change: 1 addition & 0 deletions src/components/AuthenticatedWrapper.vue
Expand Up @@ -58,6 +58,7 @@ const ROUTES_USING_BACK_BUTTON = [
'settings.contacts',
'settings.currencies',
'settings.languages',
'settings.network-fee',
'settings.networks',
'settings.wallets',
];
Expand Down
24 changes: 21 additions & 3 deletions src/components/Settings.vue
Expand Up @@ -39,6 +39,10 @@
<div class="label">{{ $t('Network') }}</div>
<div class="value">{{ selectedNetwork.net }}</div>
</div>
<div class="row" @click="$router.push('/authenticated/settings/network-fee')">
<div class="label">{{ $t('networkFee') }}</div>
<div class="value">{{ $formatNumber(selectedNetworkFee) }}</div>
</div>
</div>
<div class="underlined">{{ $t('wallets') }}</div>
<div class="tile">
Expand Down Expand Up @@ -66,9 +70,22 @@ export default {
this.currencies = this.$services.settings.getCurrenciesAsArray();
this.networks = this.$services.network.getNetworks();
this.selectedCurrency = this.$services.settings.getCurrency();
this.selectedNetwork = _.find(this.networks, (network) => {
return network.value.net === this.$services.network.getSelectedNetwork().net;

const storedNetwork = this.$services.network.getSelectedNetwork();
this.selectedNetwork = _.find(this.networks, ({ value }) => {
return value.net === storedNetwork.net;
}).value;

if (!this.selectedNetwork && this.networks && this.networks.length > 0) {
this.selectedNetwork = this.networks[0];
}

if (storedNetwork) {
this.selectedNetwork.fee = storedNetwork.fee;
this.selectedNetworkFee = storedNetwork.fee;
} else {
this.selectedNetworkFee = 0;
}
},

computed: {
Expand All @@ -79,8 +96,9 @@ export default {
currencies: [],
networks: [],
selectedCurrency: null,
selectedNetwork: null,
selectedLanguage: null,
selectedNetwork: null,
selectedNetworkFee: 0,
};
},

Expand Down
2 changes: 1 addition & 1 deletion src/components/TransactionDetail.vue
Expand Up @@ -66,7 +66,7 @@
<div class="row">
<div class="col">
<div class="label">{{ $t('networkFee') }}</div>
<div class="value">{{ $t('feeInGas', { fee: formatNumber(transaction.details.net_fee) }) }}</div>
<div class="value">{{ $t('feeInGas', { fee: $formatNumber(transaction.details.net_fee) }) }}</div>
</div>
<div class="col">
<div class="label">{{ $t('systemFee') }}</div>
Expand Down
129 changes: 129 additions & 0 deletions src/components/settings/NetworkFee.vue
@@ -0,0 +1,129 @@
<template>
<section id="network-fee">
<div class="header">
<div class="title">{{ $t('networkFee') }}</div>
</div>
<div class="body">
<div class="network-fees">
<div v-for="(fee, index) in formattedNetworkFees" :key="index" :class="['fee', {active: selectedNetworkFee === fee.raw}]" @click="selectFee(fee)">
<div class="label">{{ fee.formatted }}</div>
</div>
</div>
</div>
</section>
</template>

<script>
export default {
beforeMount() {
this.initNetwork();
this.initNetworkFees();
},

data() {
return {
formattedNetworkFees: [],
selectedNetwork: null,
selectedNetworkFee: 0,
};
},

methods: {
initNetwork() {
const storedNetwork = this.$services.network.getSelectedNetwork();

this.selectedNetwork = _.find(this.$services.network.getNetworks(), ({ value }) => {
return value.net === storedNetwork.net;
}).value;

this.selectedNetworkFee = _.get(storedNetwork, 'fee', 0);
},

initNetworkFees() {
this.formattedNetworkFees = this.$services.network.getNetworkFees().map((fee) => {
return {
formatted: this.$formatNumber(fee),
raw: fee,
};
});
},

selectFee({ raw }) {
this.selectedNetwork.fee = this.selectedNetworkFee = raw;
this.$services.network.setSelectedNetwork(this.selectedNetwork);
this.$store.commit('handleNetworkChange');
this.$services.neo.promptGASFractureIfNecessary();
this.$router.back();
},
},
};
</script>

<style lang="scss">
#network-fee {
display: flex;
flex-direction: column;
height: 100%;
overflow: hidden;

> .header {
align-items: center;
display: flex;
flex-direction: column;
flex: none;
padding: $space 0;

.title {
color: white;
font-size: toRem(18px);
}
}

> .body {
background: $background;
border-top-left-radius: $border-radius;
border-top-right-radius: $border-radius;
display: flex;
flex-direction: column;
flex: 1;
overflow: hidden;
padding: toRem(26px) $space $space $space;

.network-fees {
background: white;
border-radius: $border-radius;
flex: 1;
margin-top: $space;
overflow: auto;
padding: $space;

.fee {
display: flex;
flex-direction: row;
align-items: center;
padding: $space;

.label {
color: $dark;
flex: 1;
font-family: GilroyMedium;
}

& + .fee {
border-top: $border-width-thin solid $background;
}

&.active {
background-color: $background;

.label {
color: $purple;
}
}
}
}
}
}
</style>


5 changes: 5 additions & 0 deletions src/router/index.js
Expand Up @@ -137,6 +137,11 @@ export default new Router({
component: require('../components/settings/Currencies').default,
name: 'settings.currencies',
},
{
path: 'settings/network-fee',
component: require('../components/settings/NetworkFee').default,
name: 'settings.network-fee',
},
{
path: 'settings/networks',
component: require('../components/settings/Networks').default,
Expand Down
25 changes: 24 additions & 1 deletion src/services/network.js
Expand Up @@ -14,6 +14,7 @@ const NETWORKS = [
aph: 'https://mainnet.aphelion-neo.com:62443/api',
net: 'MainNet',
rpc: 'https://mainneo.aphelion-neo.com:10331',
fee: 0,
},
},
{
Expand All @@ -22,13 +23,30 @@ const NETWORKS = [
aph: 'https://testnet.aphelion-neo.com:62443/api',
net: 'TestNet',
rpc: 'https://testneo.aphelion-neo.com:20331',
fee: 0,
},
},
];

const NETWORK_FEE_OPTIONS = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for now still, as it is what we have on desktop, but we really need to support setting fee per K/Byte and support any value instead of powers of 10.

0,
0.00000001,
0.0000001,
0.000001,
0.00001,
0.0001,
0.001,
0.01,
0.1,
];

let loadNetworkStatusIntervalId;

export default {
getNetworkFees() {
return NETWORK_FEE_OPTIONS;
},

getNetworks() {
return _.sortBy(NETWORKS, 'label');
},
Expand All @@ -38,7 +56,12 @@ export default {
},

getSelectedNetwork() {
return storage.get(NETWORK_STORAGE_KEY, _.first(NETWORKS).value);
const network = storage.get(NETWORK_STORAGE_KEY, _.first(NETWORKS).value);

if (!network.fee) {
network.fee = 0;
}
return network;
},

init() {
Expand Down