Permalink
Browse files

Merge remote-tracking branch 'upstream/master' into feature/toggle-bi…

…tcoin-currency
  • Loading branch information...
alexbarnsley committed Nov 23, 2017
2 parents 9fbec3f + a9402e7 commit 82116a1bb5476920112ce3e92a2860fb3bf12290
@@ -15,27 +15,22 @@
const vm = this
vm.INCREASE_API = 50
vm.INCREASE_SCROLL = 10
vm.INCREASE_SCROLL = 50
vm.address = undefined
vm.transactions = []
vm.pageSize = 10
vm.limit = 50
vm.offset = 0
vm.isBusy = false // loading
vm.isComplete = false // disable the request
reset()
$scope.$on('account:onSelect', function (evt, account) {
angular.element(document.querySelector('.tx-list-container'))[0].scrollTop = 0
reset()
vm.address = account.address
reset()
angular.element(document.querySelector('.tx-list-container'))[0].scrollTop = 0
updateTransactions(account.transactions)
})
$scope.$on('account:onRefreshTransactions', function (evt, transactions) {
reset()
angular.element(document.querySelector('.tx-list-container'))[0].scrollTop = 0
updateTransactions(transactions)
})
@@ -74,12 +69,12 @@
}
function reset () {
vm.pageSize = 10
vm.offset = 0
vm.pageSize = 50
vm.offset = 25
vm.transactions = []
vm.isBusy = false
vm.isComplete = false
vm.isBusy = false // loading
vm.isComplete = false // disable the request
}
function updateTransactions (transactions) {
@@ -72,8 +72,6 @@
) {
var self = this
self.ARKTOSHI_UNIT = ARKTOSHI_UNIT
var languages = {
en: gettextCatalog.getString('English'),
ar: gettextCatalog.getString('Arabic'),
@@ -316,6 +314,7 @@
toastService.error('Network disconnected!')
} else if (self.connectedPeer.isConnected && !self.isNetworkConnected) {
self.isNetworkConnected = true
self.refreshAccountBalances()
toastService.success('Network connected and healthy!')
}
}, 500)
@@ -848,6 +847,16 @@
})
}
self.refreshAccountBalances = () => {
networkService.getPrice()
self.getAllAccounts().forEach( account => {
accountService
.refreshAccount(account)
.then(updated => account.balance = updated.balance)
})
}
self.toggleRefreshAccountsAutomatically = function () {
storageService.set('refreshAccountsAutomatically', self.refreshAccountsAutomatically, true)
}
@@ -2,7 +2,7 @@
'use strict'
angular.module('arkclient.accounts')
.service('accountService', ['$q', '$http', 'networkService', 'storageService', 'ledgerService', 'gettextCatalog', AccountService])
.service('accountService', ['$q', '$http', 'networkService', 'storageService', 'ledgerService', 'gettextCatalog', 'ARKTOSHI_UNIT', AccountService])
/**
* Accounts DataService
@@ -12,7 +12,7 @@
* @returns {{loadAll: Function}}
* @constructor
*/
function AccountService ($q, $http, networkService, storageService, ledgerService, gettextCatalog) {
function AccountService ($q, $http, networkService, storageService, ledgerService, gettextCatalog, ARKTOSHI_UNIT) {
var self = this
var ark = require('../node_modules/arkjs')
@@ -261,7 +261,7 @@
transaction.total = -transaction.amount - transaction.fee
}
// to avoid small transaction to be displayed as 1e-8
transaction.humanTotal = numberToFixed(transaction.total / 100000000) + ''
transaction.humanTotal = numberToFixed(transaction.total / ARKTOSHI_UNIT) + ''
return transaction
}
@@ -655,7 +655,7 @@
var votedDelegate = votedDelegates[j]
if (arrayObjectIndexOf(notRemovedDelegates, votedDelegate.publicKey, 'publicKey') === -1) {
votedDelegate.vote = '-'
difflist.push(delegate)
difflist.push(votedDelegate)
}
if (difflist.length === 33) {
assets.push(difflist)
@@ -744,10 +744,10 @@
if (value === null) {
virtual[folder].amount = null
} else {
virtual[folder].amount = value * 100000000
virtual[folder].amount = value * ARKTOSHI_UNIT
}
} else {
return virtual[folder].amount === null ? '' : virtual[folder].amount / 100000000
return virtual[folder].amount === null ? '' : virtual[folder].amount / ARKTOSHI_UNIT
}
}
}
@@ -34,7 +34,7 @@ <h2><span translate>Transaction</span></h2>
<b translate>Amount ({{ul.network.symbol}})</b> <span class="md-secondary">{{validate.humanAmount}}</span>
</md-list-item>
<md-list-item>
<b translate>Fee ({{ul.network.symbol}})</b> <span class="md-secondary">{{validate.transaction.fee/100000000}}</span>
<b translate>Fee ({{ul.network.symbol}})</b> <span class="md-secondary">{{validate.transaction.fee | convertToArkValue}}</span>
</md-list-item>
</md-list>
</div>
@@ -64,9 +64,10 @@
</md-icon>
</span>
<span class="md-subhead description">
<translate class="balance">Balance</translate> {{$ctrl.ul.network.symbol}} {{$ctrl.ul.selected.balance/$ctrl.ul.ARKTOSHI_UNIT}}
<md-button ng-click="$ctrl.ul.selectNextCurrency()" ng-show="$ctrl.ul.showExchangeRate()">{{$ctrl.ul.selected.balance/$ctrl.ul.ARKTOSHI_UNIT | amountToCurrency:$ctrl:true | formatCurrency:$ctrl.ul:true }}</md-button>
<md-button class="md-small" ng-click="$ctrl.ul.toggleBitcoinCurrency()" ng-hide="$ctrl.ul.currency.name === 'btc'">
<translate class="balance">Balance</translate> {{$ctrl.ul.network.symbol}} {{$ctrl.ul.selected.balance | convertToArkValue}}
{{$ctrl.ul.network.cmcTicker}}
<md-button ng-click="$ctrl.ul.selectNextCurrency()" ng-show="$ctrl.ul.showExchangeRate()">{{$ctrl.ul.selected.balance | convertToArkValue | amountToCurrency:$ctrl:true | formatCurrency:$ctrl.ul:true }}</md-button>
<md-button class="md-small" ng-click="$ctrl.ul.toggleBitcoinCurrency()" ng-hide="$ctrl.ul.currency.name === 'btc'">
<md-tooltip md-direction="top">
{{'Toggle' | translate}} {{$ctrl.ul.toggleCurrency.name | uppercase}}
</md-tooltip>
@@ -28,9 +28,9 @@
<md-list-item>
<h3>
<translate>Default</translate> {{$ctrl.ul.currency.symbol}} {{($ctrl.ul.getDefaultValue($ctrl.ul.selected)/$ctrl.ul.ARKTOSHI_UNIT*$ctrl.ul.connectedPeer.market.price[$ctrl.ul.currency.name]).toFixed(4)}}</h3>
<translate>Default</translate> {{$ctrl.ul.currency.symbol}} {{(($ctrl.ul.getDefaultValue($ctrl.ul.selected) | convertToArkValue)*$ctrl.ul.connectedPeer.market.price[$ctrl.ul.currency.name]).toFixed(4)}}</h3>
<span class="md-secondary">
<md-button md-block md-colors="{'background' : $ctrl.ul.getDefaultValue($ctrl.ul.selected)>0 ? 'default-green-200':'default-red-200' }"> {{$ctrl.ul.getDefaultValue($ctrl.ul.selected)/$ctrl.ul.ARKTOSHI_UNIT}}</md-button>
<md-button md-block md-colors="{'background' : $ctrl.ul.getDefaultValue($ctrl.ul.selected)>0 ? 'default-green-200':'default-red-200' }"> {{$ctrl.ul.getDefaultValue($ctrl.ul.selected) | convertToArkValue}}</md-button>
</span>
</md-list-item>
<md-list-item ng-repeat="folder in $ctrl.ul.selected.virtual.getFolders()">
@@ -58,7 +58,7 @@ <h3>
<md-input-container>
<label>{{'Amount'|translate}} ({{$ctrl.ul.network.token}})</label>
<input ng-model-options="{ getterSetter: true }" ng-model="$ctrl.ul.selected.virtual.uservalue(folder)" ng-change="$ctrl.ul.saveFolder($ctrl.ul.selected,folder)" type="number" >
<div class="hint"> {{$ctrl.ul.currency.symbol}} {{($ctrl.ul.selected.virtual[folder].amount/$ctrl.ul.ARKTOSHI_UNIT*$ctrl.ul.connectedPeer.market.price[$ctrl.ul.currency.name]).toFixed(4)}} </div>
<div class="hint"> {{$ctrl.ul.currency.symbol}} {{(($ctrl.ul.selected.virtual[folder].amount | convertToArkValue)*$ctrl.ul.connectedPeer.market.price[$ctrl.ul.currency.name]).toFixed(4)}} </div>
</md-input-container>
</span>
@@ -29,7 +29,7 @@
</td>
<td md-cell>{{it.date | date: 'short'}}</td>
<td ng-if="it.recipientId==it.senderId && it.type==0" md-cell>
<md-button disabled md-colors="{'background' : 'default-blue-grey-600' }">{{ '+' + ((it.amount/$ctrl.ul.ARKTOSHI_UNIT)) + ' / -' + (it.fee/$ctrl.ul.ARKTOSHI_UNIT) }}</md-button>
<md-button disabled md-colors="{'background' : 'default-blue-grey-600' }">{{ '+' + ((it.amount | convertToArkValue)) + ' / -' + (it.fee | convertToArkValue) }}</md-button>
</td>
<td ng-if="it.type>0" md-cell>
<md-button disabled md-colors="{'background' : 'default-blue-grey-600' }">{{it.humanTotal}}</md-button>
@@ -3,9 +3,9 @@
angular
.module('arkclient.components')
.controller('AddressbookController', ['$scope', '$mdDialog', 'toastService', 'storageService', 'gettextCatalog', 'accountService', AddressbookController])
.controller('AddressbookController', ['$scope', '$mdDialog', 'toastService', 'storageService', 'gettextCatalog', 'accountService', 'ARKTOSHI_UNIT', AddressbookController])
function AddressbookController ($scope, $mdDialog, toastService, storageService, gettextCatalog, accountService) {
function AddressbookController ($scope, $mdDialog, toastService, storageService, gettextCatalog, accountService, ARKTOSHI_UNIT) {
var self = this
// var contacts
self.trim = function (str) {
@@ -235,7 +235,7 @@
return prev + el
})
stats.income.amount = accountService.numberToFixed(incomeAmount / 100000000).toFixed(2)
stats.income.amount = accountService.numberToFixed(incomeAmount / ARKTOSHI_UNIT).toFixed(2)
}
if (expendTx.length > 0) {
@@ -245,7 +245,7 @@
return prev + el
})
stats.expend.amount = accountService.numberToFixed(expendAmount / 100000000).toFixed(2)
stats.expend.amount = accountService.numberToFixed(expendAmount / ARKTOSHI_UNIT).toFixed(2)
}
}
@@ -36,16 +36,6 @@
return this.myAccountsBalance() * price
}
this.refreshAccountBalances = () => {
networkService.getPrice()
this.accountCtrl.getAllAccounts().forEach( account => {
accountService
.refreshAccount(account)
.then( updated => account.balance = updated.balance )
})
}
}
})()
@@ -6,13 +6,14 @@ <h2>
<span ng-show="$ctrl.ac.showExchangeRate()">/ {{$ctrl.myAccountsCurrencyBalance(true) | formatCurrency:$ctrl.ac:true}}</span>
</h2>
<span flex></span>
<md-button class="md-small" ng-click="$ctrl.ac.toggleBitcoinCurrency()" ng-hide="$ctrl.ac.currency.name === 'btc'">
<md-tooltip md-direction="top">
{{'Toggle' | translate}} {{$ctrl.ac.toggleCurrency.name | uppercase}}
</md-tooltip>
{{$ctrl.ac.toggleCurrency.symbol}}
</md-button>
<md-button class="share" ng-click="$ctrl.refreshAccountBalances()" aria-label="Refresh balances">
<md-button class="share" ng-click="$ctrl.ac.refreshAccountBalances()" aria-label="Refresh balances">
<md-icon md-font-library="material-icons">cached</md-icon>
</md-button>
</div>
@@ -52,7 +53,7 @@ <h2>
{{it.username||it.address}} <span ng-if="it.delegate">({{it.delegate.rate}})</span>
</span>
<span class="md-secondary">
{{$ctrl.ac.network.symbol}} {{it.balance/$ctrl.ac.ARKTOSHI_UNIT}}
{{$ctrl.ac.network.symbol}} {{it.balance | convertToArkValue}}
</span>
</md-list-item>
</md-list>
@@ -2,21 +2,19 @@
'use strict'
angular.module('arkclient.directives')
.directive('validAmount', [
function () {
.directive('validAmount', ['ARKTOSHI_UNIT',
function (ARKTOSHI_UNIT) {
return {
require: 'ngModel',
link: function (scope, elem, attrs, ctrl) {
var val = function (value) {
if (typeof value === 'undefined' || value === 0) {
ctrl.$pristine = true
}
var satoshis = 100000000
var num = Number((value * satoshis).toFixed(0)) // 1.1 = 110000000
var totalBalance = Number(scope.send.totalBalance * satoshis)
var remainingBalance = ((totalBalance - num) / satoshis)
scope.send.remainingBalance = isNaN(remainingBalance) ? totalBalance / satoshis : remainingBalance
var num = Number((value * ARKTOSHI_UNIT).toFixed(0)) // 1.1 = 110000000
var totalBalance = Number(scope.send.totalBalance * ARKTOSHI_UNIT)
var remainingBalance = ((totalBalance - num) / ARKTOSHI_UNIT)
scope.send.remainingBalance = isNaN(remainingBalance) ? totalBalance / ARKTOSHI_UNIT : remainingBalance
if (typeof num === 'number' && num > 0) {
if (num > Number.MAX_SAFE_INTEGER) {
@@ -21,7 +21,8 @@
const price = ac.connectedPeer.market.price[currencyName]
return (amount * price).toFixed(5)
}
}).filter('formatCurrency', function () {
})
.filter('formatCurrency', function () {
return function (val, self, bitcoinToggleIsActive) {
var currencyName = bitcoinToggleIsActive && self.btcValueActive ? 'btc' : self.currency.name
var languageCode = self.language.replace('_', '-')
@@ -43,4 +44,10 @@
return localeVersion
}
})
// converts arktoshi into ark
.filter('convertToArkValue', ['ARKTOSHI_UNIT', function (ARKTOSHI_UNIT) {
return function (val) {
return val / ARKTOSHI_UNIT
}
}])
})()
@@ -151,16 +151,22 @@
if (!network.cmcTicker && network.token !== 'ARK') {
failedTicker()
return;
return
}
$http.get('https://api.coinmarketcap.com/v1/ticker/' + (network.cmcTicker || 'ARK'), { timeout: 2000 })
.then(function (res) {
if (res.data[0] && res.data[0].price_btc) {
res.data[0].price_btc = convertToSatoshi(res.data[0].price_btc) // store BTC price in satoshi
}
peer.market = res.data[0]
peer = updatePeerWithCurrencies(peer, res)
updatePeerWithCurrencies(peer, res)
.then((prices) => {
res.data[0].price = prices
peer.market = res.data[0]
})
.catch(() => {
peer.market = res.data[0]
})
storageService.set('lastPrice', { market: peer.market, date: new Date() })
}, failedTicker)
.catch(failedTicker)
@@ -341,27 +347,36 @@
}
// Returns the BTC value in satoshi
function convertToSatoshi(val) {
return Number(val).toFixed(8);
function convertToSatoshi (val) {
return Number(val).toFixed(8)
}
// Updates peer with all currency values relative to the USD price.
function updatePeerWithCurrencies(peer, res) {
$http.get('https://api.fixer.io/latest?base=USD', { timeout: 2000}).then( function (result) {
function updatePeerWithCurrencies (peer, res) {
let deferred = $q.defer()
const currencies = ['AUD', 'BRL', 'CAD', 'CHF', 'CNY', 'EUR', 'GBP', 'HKD', 'IDR', 'INR', 'JPY', 'KRW', 'MXN', 'RUB']
var currencyConversionRequest = createCurrencyConversionApiCall(currencies)
$http.get(currencyConversionRequest, {timeout: 2000}).then(function (result) {
const USD_PRICE = Number(res.data[0].price_usd)
var currencies = ["aud", "brl", "cad", "chf", "cny", "eur", "gbp", "hkd", "idr", "inr", "jpy", "krw", "mxn", "rub"]
var prices = {}
currencies.forEach(function(currency) {
prices[currency] = result.data.rates[currency.toUpperCase()] * USD_PRICE
currencies.forEach(function (currency) {
prices[currency.toLowerCase()] = result.data.rates[currency] * USD_PRICE
})
prices["btc"] = res.data[0].price_btc
prices["usd"] = res.data[0].price_usd
peer.market.price = prices
prices['btc'] = res.data[0].price_btc
prices['usd'] = res.data[0].price_usd
storageService.setGlobal('peerCurrencies', prices)
deferred.resolve(prices)
}, () => {
deferred.reject(false)
})
return peer
return deferred.promise
}
function createCurrencyConversionApiCall (currencies) {
var getRequest = 'https://api.fixer.io/latest?base=USD&symbols='
getRequest += currencies.toString()
return getRequest
}
listenNetworkHeight()
View
@@ -1,6 +1,6 @@
{
"name": "ArkClient",
"version": "1.4.2",
"version": "1.4.3",
"productName": "ArkClient",
"description": "Ark Desktop Wallet",
"main": "main.js",
@@ -34,6 +34,7 @@ describe('AddressbookController', function () {
$provide.value('gettextCatalog', getTextCatalogMock)
$provide.value('accountService', accountServiceMock)
$provide.value('toastService', toastServiceMock)
$provide.value('ARKTOSHI_UNIT', Math.pow(10,8))
})
inject((_$compile_, _$rootScope_, _$controller_) => {
Oops, something went wrong.

0 comments on commit 82116a1

Please sign in to comment.