index.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<div class="animated fadeIn" id="app"> <nav> <ul> <router-link tag="li" active-class="active" to="/calculator"> <a href="#"><i class="fas fa-calculator"></i></a> </router-link> <router-link tag="li" active-class="active" to="/settings"> <a href="#"><i class="fas fa-cog"></i></a> </router-link> </ul> </nav> <div class="router"> <router-view @update-settings="updateSettings" :settings="settings" :coins="coins"></router-view> </div> </div> |
style.css
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
@import url('https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,900'); body { font-family: 'Roboto', sans-serif; background-color: #E2E7EC; background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M54.627 0l.83.828-1.415 1.415L51.8 0h2.827zM5.373 0l-.83.828L5.96 2.243 8.2 0H5.374zM48.97 0l3.657 3.657-1.414 1.414L46.143 0h2.828zM11.03 0L7.372 3.657 8.787 5.07 13.857 0H11.03zm32.284 0L49.8 6.485 48.384 7.9l-7.9-7.9h2.83zM16.686 0L10.2 6.485 11.616 7.9l7.9-7.9h-2.83zm20.97 0l9.315 9.314-1.414 1.414L34.828 0h2.83zM22.344 0L13.03 9.314l1.414 1.414L25.172 0h-2.83zM32 0l12.142 12.142-1.414 1.414L30 .828 17.272 13.556l-1.414-1.414L28 0h4zM.284 0l28 28-1.414 1.414L0 2.544V0h.284zM0 5.373l25.456 25.455-1.414 1.415L0 8.2V5.374zm0 5.656l22.627 22.627-1.414 1.414L0 13.86v-2.83zm0 5.656l19.8 19.8-1.415 1.413L0 19.514v-2.83zm0 5.657l16.97 16.97-1.414 1.415L0 25.172v-2.83zM0 28l14.142 14.142-1.414 1.414L0 30.828V28zm0 5.657L11.314 44.97 9.9 46.386l-9.9-9.9v-2.828zm0 5.657L8.485 47.8 7.07 49.212 0 42.143v-2.83zm0 5.657l5.657 5.657-1.414 1.415L0 47.8v-2.83zm0 5.657l2.828 2.83-1.414 1.413L0 53.456v-2.83zM54.627 60L30 35.373 5.373 60H8.2L30 38.2 51.8 60h2.827zm-5.656 0L30 41.03 11.03 60h2.828L30 43.858 46.142 60h2.83zm-5.656 0L30 46.686 16.686 60h2.83L30 49.515 40.485 60h2.83zm-5.657 0L30 52.343 22.343 60h2.83L30 55.172 34.828 60h2.83zM32 60l-2-2-2 2h4zM59.716 0l-28 28 1.414 1.414L60 2.544V0h-.284zM60 5.373L34.544 30.828l1.414 1.415L60 8.2V5.374zm0 5.656L37.373 33.656l1.414 1.414L60 13.86v-2.83zm0 5.656l-19.8 19.8 1.415 1.413L60 19.514v-2.83zm0 5.657l-16.97 16.97 1.414 1.415L60 25.172v-2.83zM60 28L45.858 42.142l1.414 1.414L60 30.828V28zm0 5.657L48.686 44.97l1.415 1.415 9.9-9.9v-2.828zm0 5.657L51.515 47.8l1.414 1.413 7.07-7.07v-2.83zm0 5.657l-5.657 5.657 1.414 1.415L60 47.8v-2.83zm0 5.657l-2.828 2.83 1.414 1.413L60 53.456v-2.83zM39.9 16.385l1.414-1.414L30 3.658 18.686 14.97l1.415 1.415 9.9-9.9 9.9 9.9zm-2.83 2.828l1.415-1.414L30 9.313 21.515 17.8l1.414 1.413 7.07-7.07 7.07 7.07zm-2.827 2.83l1.414-1.416L30 14.97l-5.657 5.657 1.414 1.415L30 17.8l4.243 4.242zm-2.83 2.827l1.415-1.414L30 20.626l-2.828 2.83 1.414 1.414L30 23.456l1.414 1.414zM56.87 59.414L58.284 58 30 29.716 1.716 58l1.414 1.414L30 32.544l26.87 26.87z' fill='%235b7590' fill-opacity='0.04' fill-rule='evenodd'/%3E%3C/svg%3E"); padding: 20px; font-size: 14px; color: #768ea5; } h4 { margin: 0 0 15px 0; font-weight: 900; } a { color: #36b7e6; } a:active, a:focus, a:hover { color: #1a9fcf; } #app { display: grid; grid-template-areas: "nav" "router"; grid-gap: 0; justify-content: center; max-width: 680px; margin: auto; grid-template-columns: 100%; } nav { padding-left: 15px; grid-area: nav; } nav ul { margin: 0; padding: 0; list-style: none; } nav ul li { display: inline; } nav ul li.active a { opacity: 1; } nav ul li a { display: inline-block; text-align: center; font-size: 1.5em; padding: 8px 15px; color: #768ea5; opacity: 0.2; } nav ul li a:hover, nav ul li a:active, nav ul li a:focus { color: #768ea5; opacity: 1; } .router { grid-area: router; } .router > div { display: grid; grid-template-columns: 40% 60%; grid-template-areas: "leftPanel main"; grid-template-rows: auto; grid-gap: 0; justify-content: center; margin: auto; } .leftPanel, .main { padding: 20px 30px; } .leftPanel { border-radius: 4px 0 0 4px; background-color: #768ea5; grid-area: leftPanel; color: #fff; } .leftPanel label { font-weight: 600; font-size: 0.8em; } .main { border-radius: 0 4px 4px 0; background-color: #fff; grid-area: main; display: grid; justify-content: center; align-items: center; box-shadow: inset 0 0 150px 0 #b4c1ce; } .main .projections { display: grid; grid-template-columns: auto; grid-template-areas: "total total total" "profit profit profit" "coins fees taxes"; grid-gap: 0; grid-row: auto; font-size: 0.8em; font-weight: 500; line-height: 1em; justify-content: stretch; align-items: center; } .main .projections i { color: #36b7e6; } .main .projections h4 { grid-area: total; font-size: 1.3em; text-align: left; margin: 0; } .main .projections .total { grid-area: total; text-align: right; } .main .projections .profit { grid-area: profit; text-align: center; font-size: 4em; font-weight: 100; line-height: 1.2em; color: #36b7e6; } .main .projections .coins { grid-area: coins; text-align: left; } .main .projections .fees { grid-area: fees; text-align: center; } .main .projections .taxes { grid-area: taxes; text-align: right; } .form-control { color: #768ea5; font-size: 16px; border: none; } dl dt, dl dd { line-height: 2em; } dl dt { font-weight: 100; color: #b4c1ce; font-size: 0.8em; line-height: 2.6em; } dl dd { font-weight: 500; } dl .projectedProfit-dd { font-size: 1.5em; font-weight: 400; line-height: 1.4em; color: #36b7e6; } @media (max-width: 768px) { input { -webkit-appearance: none; } #app { grid-template-columns: 100%; grid-template-areas: "nav" "router"; } .router { grid-area: router; } .router > div { display: grid; grid-template-columns: 100%; grid-template-areas: "main" "leftPanel"; grid-template-rows: auto; grid-gap: 0; justify-content: center; margin: auto; } .leftPanel { box-shadow: none; border-radius: 0 0 4px 4px; padding: 20px 30px 8px 30px; } .main { box-shadow: none; border-radius: 4px 4px 0 0; padding: 30px; text-align: center; } dl dt { line-height: 1em; margin-top: 1.2em; } } /* The slider itself */ input[type=range] { -webkit-appearance: none; width: 100%; height: 6px; border-radius: 5px; background: #506d8a; outline: none; border-top: 1px solid #3d546a; border-bottom: 1px solid #87a0b9; } input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 16px; height: 16px; border-radius: 50%; cursor: pointer; margin: -2px 0 0 -8px; border: 1px solid rgba(255, 255, 255, 0.5); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); background: #bacbdb; background: -moz-linear-gradient(top, #bacbdb 0%, white 100%); background: -webkit-linear-gradient(top, #bacbdb 0%, white 100%); background: linear-gradient(to bottom, #bacbdb 0%, white 100%); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#bacbdb', endColorstr='#ffffff',GradientType=0); } input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; cursor: pointer; margin: -2px 0 0 -8px; background: #bacbdb; background: -moz-linear-gradient(top, #bacbdb 0%, white 100%); background: -webkit-linear-gradient(top, #bacbdb 0%, white 100%); background: linear-gradient(to bottom, #bacbdb 0%, white 100%); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#bacbdb', endColorstr='#ffffff',GradientType=0); } |
script.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
Vue.filter('currency', (value) => { return accounting.formatMoney(value, '$', 2) }) const Calculator = Vue.component('Calculator', { props: ['settings','coins'], template: ` <div> <div class="leftPanel"> <h4>Projection Criteria</h4> <div class="form-group"> <label>Initial Investment</label> <div class="input-group"> <input v-model="settings.investment" @change="saveChanges()" onfocus="this.select()" type="number" min="0" inputmode="decimal" ref="initialInvestment" class="form-control" placeholder="Initial Investment" /> <span class="input-group-append"> <button class="btn btn-primary" @click="resetInitialInvestment"> <i class="fas fa-times"/> </button> </span> </div> </div> <div class="form-group"> <label>Initial Coin Price</label> <select v-if="coins && coins.length > 0 && settings.initialPrice === null" class="form-control" v-model="selectedCoin" @change="changeInitialPrice"> <option value="" selected>Select A Coin</option> <option v-for="(coin, index) in coins" :key="index" :value="index">{{ coin.name }} ({{ coin.symbol }})</option> </select> <div v-else class="input-group"> <input v-model="settings.initialPrice" @change="saveChanges()" onfocus="this.select()" type="number" min="0" inputmode="decimal" ref="initialPrice" class="form-control" placeholder="Initial Coin Price" /> <span class="input-group-append"> <button v-show="settings.initialPrice" class="btn btn-primary" @click="resetInitialPrice"> <i class="fas fa-times"/> </button> </span> </div> </div> <div class="form-group"> <label>Projected Coin Price</label> <div class="input-group"> <input v-model="settings.projectedPrice" @change="saveChanges()" onfocus="this.select()" type="number" min="0" inputmode="decimal" ref="projectedPrice" class="form-control" placeholder="Projected Coin Price" /> <span class="input-group-append"> <button class="btn btn-primary" @click="resetProjectedPrice"> <i class="fas fa-times"/> </button> </span> </div> </div> </div> <div class="main"> <div class="projections"> <h4>Forecast</h4> <div class="total">{{ projectedSubTotal - this.fees | currency }}</div> <div class="profit">{{ projectedTotal | currency }}</div> <div class="coins"><i class="far fa-donate"></i> {{ parseInt(totalCoins).toLocaleString() }}</div> <div class="fees"><i class="far fa-balance-scale"></i> {{ fees | currency }}</div> <div class="taxes"><i class="far fa-university"></i> {{ taxes | currency }}</div> </div> </div> </div>`, data () { return { selectedCoin: '' } }, computed: { totalCoins () { return this.settings.investment / this.settings.initialPrice }, projectedSubTotal () { return (this.settings.projectedPrice * this.totalCoins) }, projectedProfit () { return (this.projectedSubTotal - this.settings.investment) }, fees () { return this.settings.investment - (this.settings.investment - (this.settings.investment * (this.settings.serviceFee / 100)) * 2) }, taxes () { return (this.projectedProfit - this.fees) * (this.settings.taxRate / 100) }, projectedTotal () { let total = this.projectedProfit - this.fees - this.taxes document.title = accounting.formatMoney(this.settings.projectedPrice, '$', 2) + ' = ' + accounting.formatMoney(total, '$', 2) + ' | Calculator' return total } }, methods: { changeInitialPrice () { if(this.selectedCoin !== '') { let history = this.coins[this.selectedCoin].history; this.settings.initialPrice = parseInt( history[history.length-1] ); this.saveChanges(); } }, saveChanges () { this.$emit('update-settings', this.settings); }, resetInitialInvestment () { this.settings.investment = null this.$refs['initialInvestment'].focus(); this.resetSelectedCoin(); }, resetInitialPrice () { this.settings.initialPrice = null this.$refs['initialPrice'].focus(); this.resetSelectedCoin(); }, resetProjectedPrice () { this.settings.projectedPrice = null this.$refs['projectedPrice'].focus(); this.resetSelectedCoin(); }, resetSelectedCoin () { this.selectedCoin = ''; } } }); const Settings = Vue.component('Settings', { props: ['settings'], template: ` <div> <div class="leftPanel" style="border-radius:4px;"> <h4>Settings</h4> <div class="form-group"> <label>Service Fee - {{ settings.serviceFee }}%</label> <input type="number" min="0" inputmode="decimal" class="form-control" v-model="settings.serviceFee" @change="saveChanges()"> </div> <div class="form-group mb-4"> <label>Tax Rate - {{ settings.taxRate }}%</label> <input type="number" min="0" inputmode="decimal" class="form-control" v-model="settings.taxRate" @change="saveChanges()"> </div> <div class="form-group"> <button @click="deleteSettings" class="btn btn-sm btn-primary">Delete Settings</button> </div> </div> </div>`, methods: { saveChanges () { this.$emit('update-settings', this.settings); }, deleteSettings () { localStorage.removeItem('settings') this.$router.go() } } }); const routes = [ { path: '/calculator', component: Calculator, props: true }, { path: '/settings', component: Settings, props: true } ] const router = new VueRouter({ routes }) let settings = (localStorage.getItem('settings')) ? JSON.parse(localStorage.getItem('settings')) : { investment: 18000, initialPrice: 500, projectedPrice: 550, serviceFee: 0.3, taxRate: 0 } let vm = new Vue({ router, data: { settings: settings, coins: null }, mounted () { this.$router.push({ path: '/calculator' }); this.getCoins() }, methods: { updateSettings (obj) { localStorage.setItem('settings', JSON.stringify(obj)); }, getCoins () { axios.get('https://api.coinranking.com/v1/public/coins?base=USD&timePeriod=24h').then(response => { this.coins = response.data.data.coins }) } } }).$mount('#app') |