Current Rates
-- - ETH = {{bity.curRate.ETHBTC*priceTicker.ETHBTC | number: 6}} BTC -
-- - ETH = {{bity.curRate.ETHREP*priceTicker.ETHREP | number: 6}} REP -
-- - BTC = {{bity.curRate.BTCETH*priceTicker.BTCETH | number: 6}} ETH -
-- - BTC = {{bity.curRate.BTCREP*priceTicker.BTCREP | number: 6}} REP -
-Current Rates
++ + ETH = {{bity.curRate.ETHBTC*priceTicker.ETHBTC | number: 6}} BTC +
++ + ETH = {{bity.curRate.ETHREP*priceTicker.ETHREP | number: 6}} REP +
++ + BTC = {{bity.curRate.BTCETH*priceTicker.BTCETH | number: 6}} ETH +
++ + BTC = {{bity.curRate.BTCREP*priceTicker.BTCREP | number: 6}} REP +
++ + ETH = {{shapeShiftCoinData[getOrSetRandomShapeShiftRateToken(0)]['RATES']['ETH'].rate}} {{getOrSetRandomShapeShiftRateToken(0)}} +
++ + ETH = {{shapeShiftCoinData[getOrSetRandomShapeShiftRateToken(1)]['RATES']['ETH'].rate}} {{getOrSetRandomShapeShiftRateToken(1)}} +
++ + ETH = {{shapeShiftCoinData[getOrSetRandomShapeShiftRateToken(2)]['RATES']['ETH'].rate}} {{getOrSetRandomShapeShiftRateToken(2)}} +
++ + ETH = {{shapeShiftCoinData[getOrSetRandomShapeShiftRateToken(3)]['RATES']['ETH'].rate}} {{getOrSetRandomShapeShiftRateToken(3)}} +
+I want to swap my
+-
I want to swap my
- -- - - - - {{swapOrder.fromCoin}} - - - -
for
- - - -{{originRateError}}
+for
++ {{destinationRateError}}
+ + +Loading...
+ +Your Information
- -{{swapOrder.fromVal}} {{swapOrder.fromCoin}}
-Amount to send
-{{swapOrder.toVal}} {{swapOrder.toCoin}}
-Amount to receive
-{{swapOrder.swapRate}} {{swapOrder.swapPair}}
-Your rate
-{{swapOrder.fromVal}} {{swapOrder.fromCoin}}
+Amount to send
+{{swapOrder.toVal}} {{swapOrder.toCoin}}
+Amount to receive
+{{swapOrder.swapRate}} {{swapOrder.swapPair}}
+Your rate
+Your Information
+{{orderResult.orderId}}
+Your reference number
+{{orderResult.expirationFormatted}}
+Time remaining to send
+{{orderResult.withdrawalAmount}} {{orderResult.pair.split('_')[1].toUpperCase()}}
+Amount to receive
+{{swapOrder.swapRate}} {{swapOrder.swapPair}}
+Your rate
+Order Initiated
+Waiting for your {{orderResult.inputCurrency}}...
+{{orderResult.inputCurrency}} Received!
+
+ Sending your {{orderResult.outputCurrency}}
+
Order Complete
+Your order has expired!
+Success! View Tx
+
+ Please send
+ {{orderResult.depositAmount}} {{orderResult.inputCurrency}}
+ to address
+ {{orderResult.deposit}}
+
+ + Please use the node switcher in the top-right corner to switch to an ETH node. We do + not + support swapping ETC or Testnet ETH. +
+
+ Orders that take too long will have to be processed manually & and may delay the amount of time it
+ takes
+ to receive your coins.
+
+ Please use the
+ recommended TX fees seen here.
+
Your shift encountered an error! Please contact support using the orange button below
+Your Information
diff --git a/app/includes/swap.tpl b/app/includes/swap.tpl index 98e8a3afa4..52b21d698a 100644 --- a/app/includes/swap.tpl +++ b/app/includes/swap.tpl @@ -1,20 +1,28 @@ -Issue with your Swap? Contact support
-Click here if link doesn't work
-Issue with your Swap? Contact support
++ Click here if link doesn't work +
+" + bExStr); - clearInterval(progressCheck); - clearInterval(timeRem); - } else if (bity.invalidStatus.indexOf(data.status) != -1) { - orderResult.progress.status = "CANC"; - orderResult.progress.bar = getProgressBarArr(-1, 5); - $scope.notifier.danger("Time has run out. If you have already sent, please wait 1 hour. If your order has not be processed after 1 hour, please press the orange 'Issue with your Swap?' button."); - orderResult.progress.secsRemaining = 0; - clearInterval(progressCheck); - } - if (!$scope.$$phase) $scope.$apply(); - } - orderResult.progress.pendingStatusReq = false; - }); + if ( + orderResult.progress.status == 'OPEN' && + bity.validStatus.indexOf(data.input.status) != -1 + ) { + orderResult.progress.secsRemaining = 1; + orderResult.progress.showTimeRem = false; + orderResult.progress.status = 'RCVE'; + orderResult.progress.bar = getProgressBarArr(3, 5); + } else if ( + orderResult.progress.status == 'RCVE' && + bity.validStatus.indexOf(data.output.status) != -1 + ) { + orderResult.progress.status = 'FILL'; + orderResult.progress.bar = getProgressBarArr(5, 5); + orderResult.progress.showTimeRem = false; + let url = orderResult.output.currency == 'BTC' + ? bity.btcExplorer.replace('[[txHash]]', data.output.reference) + : bity.ethExplorer.replace('[[txHash]]', data.output.reference); + let bExStr = makeTransactionNotificationElement(url); + $scope.notifier.success( + globalFuncs.successMsgs[2] + data.output.reference + '
' + bExStr + ); + clearInterval(progressCheck); + clearInterval(timeRem); + } else if (bity.invalidStatus.indexOf(data.status) != -1) { + orderResult.progress.status = 'CANC'; + orderResult.progress.bar = getProgressBarArr(-1, 5); + $scope.notifier.danger(timeOutMessage); + orderResult.progress.secsRemaining = 0; + clearInterval(progressCheck); } - }, orderResult.progress.checkDelay); - $scope.showStage2 = false; - if ($scope.orderResult.input.currency == 'BTC') $scope.showStage3Btc = true; - else { - $scope.parentTxConfig = { - to: ethUtil.toChecksumAddress($scope.orderResult.payment_address), - value: $scope.orderResult.input.amount, - sendMode: $scope.orderResult.input.currency == 'ETH' ? 'ether' : 'token', - tokensymbol: $scope.orderResult.input.currency == 'ETH' ? '' : $scope.orderResult.input.currency, - readOnly: true + if (!$scope.$$phase) { + $scope.$apply(); } - new Modal(document.getElementById('sendTransaction')); - $scope.showStage3Eth = true; + } + orderResult.progress.pendingStatusReq = false; + }); + } + }, orderResult.progress.checkDelay); + $scope.showStage2 = false; + if ($scope.orderResult.input.currency == 'BTC') { + $scope.showStage3Btc = true; + } else { + $scope.parentTxConfig = { + to: ethUtil.toChecksumAddress($scope.orderResult.payment_address), + value: $scope.orderResult.input.amount, + sendMode: $scope.orderResult.input.currency == 'ETH' ? 'ether' : 'token', + tokensymbol: $scope.orderResult.input.currency == 'ETH' + ? '' + : $scope.orderResult.input.currency, + readOnly: true + }; + new Modal(document.getElementById('sendTransaction')); + $scope.showStage3Eth = true; + } + }; + + let processOrder = function() { + if ($scope.isBitySwap) { + processOrderBity(); + } else { + processOrderShapeShift(); + } + }; + + let isValidAddress = function() { + return ( + ($scope.swapOrder.toCoin != 'BTC' && + $scope.Validator.isValidAddress($scope.swapOrder.toAddress)) || + ($scope.swapOrder.toCoin == 'BTC' && + $scope.Validator.isValidBTCAddress($scope.swapOrder.toAddress)) + ); + }; + + let openOrderBity = function() { + let order = { + amount: $scope.swapOrder.isFrom ? $scope.swapOrder.fromVal : $scope.swapOrder.toVal, + mode: $scope.swapOrder.isFrom ? 0 : 1, + pair: $scope.swapOrder.fromCoin + $scope.swapOrder.toCoin, + destAddress: $scope.swapOrder.toAddress + }; + $scope.bity.openOrder(order, function(data) { + if (!data.error) { + $scope.orderResult = data.data; + $scope.orderResult.swapOrder = $scope.swapOrder; + $scope.orderResult.provider = 'BITY'; + saveOrderToStorage($scope.orderResult); + if (!$scope.$$phase) { + $scope.$apply(); } + processOrder(); + $scope.orderOpenLoading = false; + } else { + $scope.notifier.danger(data.msg); + $scope.orderOpenLoading = false; + } + if (!$scope.$$phase) { + $scope.$apply(); + } + }); + }; + + let formattedTimeRemainingFromEpoch = function(endEpoch) { + let currentTimeInEpoch = new Date().getTime(); + let remainingTimeMili = endEpoch - currentTimeInEpoch; + let remainingTimeSec = remainingTimeMili / 1000; + let remainingTimeSecRounded = roundNumber(remainingTimeSec, 0); + return formattedTimeFromSeconds(remainingTimeSecRounded); + }; + + let formattedTimeFromSeconds = function(secondsRemaining) { + if (secondsRemaining <= 0) { + shapeShiftOrderStatusChecking($scope.orderResult.deposit).then(function() { + if ($scope.shapeShiftStatus.status !== 'complete') { + $scope.notifier.danger(timeOutMessage, 0); + } + }); + return '00:00'; + } + if (secondsRemaining || secondsRemaining === 0) { + let minutes = Math.floor(secondsRemaining / 60); + let seconds = secondsRemaining - minutes * 60; + let stringMinutes = minutes < 10 ? '0' + minutes : minutes; + let stringSeconds = seconds < 10 ? '0' + seconds : seconds; + return stringMinutes + ':' + stringSeconds; + } else { + throw Error('secondsRemaining must be a number'); } - $scope.openOrder = function() { + }; - if (($scope.swapOrder.toCoin != 'BTC' && $scope.Validator.isValidAddress($scope.swapOrder.toAddress)) || ($scope.swapOrder.toCoin == 'BTC' && $scope.Validator.isValidBTCAddress($scope.swapOrder.toAddress))) { - var order = { - amount: $scope.swapOrder.isFrom ? $scope.swapOrder.fromVal : $scope.swapOrder.toVal, - mode: $scope.swapOrder.isFrom ? 0 : 1, - pair: $scope.swapOrder.fromCoin + $scope.swapOrder.toCoin, - destAddress: $scope.swapOrder.toAddress + let shapeShiftIntervalDecrease = function() { + $scope.shapeShiftIntervalDecreaseTimeRem = setInterval(function() { + if ($scope.showStage3ShapeShift) { + let expirationFormatted = formattedTimeRemainingFromEpoch($scope.orderResult.expiration); + if (expirationFormatted === '00:00') { + shapeShiftOrderStatusChecking($scope.orderResult.deposit).then(function() { + if ($scope.shapeShiftStatus.status !== 'complete') { + $scope.orderIsExpired = true; + $scope.shapeShiftProgressStep = null; } - $scope.bity.openOrder(order, function(data) { - if (!data.error) { - $scope.orderResult = data.data; - $scope.orderResult.swapOrder = $scope.swapOrder; - var orderResult = $scope.orderResult; - saveOrderToStorage(orderResult); - processOrder(); - } else $scope.notifier.danger(data.msg); - if (!$scope.$$phase) $scope.$apply(); - }); - } else { - $scope.notifier.danger(globalFuncs.errorMsgs[5]); + clearInterval($scope.shapeShiftIntervalDecreaseTimeRem); + }); + } + $scope.orderResult.expirationFormatted = expirationFormatted; + if (!$scope.$$phase) { + $scope.$apply(); } + } else { + clearInterval($scope.shapeShiftIntervalDecreaseTimeRem); + } + }, 1000); + }; + + function sleep(time) { + return new Promise(resolve => setTimeout(resolve, time)); + } + + function handleShapeShiftStatusCheck(resp) { + if (resp.status === 'no_deposits') { + $scope.shapeShiftProgressStep = 1; + } else if (resp.status === 'received') { + $scope.shapeShiftProgressStep = 2; + } else if (resp.status === 'complete') { + $scope.shapeShiftProgressStep = 5; + } else if (resp.status === 'failed') { + $scope.failedShift = true; + } + } + + let shapeShiftOrderStatusChecking = function(shapeShiftAddress) { + if ($scope.showStage3ShapeShift) { + return shapeShiftService + .checkStatus(shapeShiftAddress) + .then(function(data) { + handleShapeShiftStatusCheck(data); + if (!$scope.$$phase) { + $scope.$apply(); + } + if (data.status !== 'complete') { + if (data.status !== 'failed') { + if (!$scope.orderIsExpired) { + sleep(10000).then(function() { + shapeShiftOrderStatusChecking(shapeShiftAddress); + }); + } else { + clearInterval($scope.shapeShiftIntervalDecreaseTimeRem); + } + } + } else { + $scope.shapeShiftStatus = data; + clearInterval($scope.shapeShiftIntervalDecreaseTimeRem); + $scope.orderResult.expirationFormatted = '-'; + } + }) + .catch(function(err) { + // TODO - implement error handling here; + }); } - $scope.newSwap = function() { - globalFuncs.localStorage.setItem(lStorageKey, ''); - initValues(); + }; + + $scope.getExplorerInfo = function() { + if ($scope.shapeShiftStatus.status === 'complete') { + let txHref = $scope.shapeShiftStatus.outputCurrency === 'BTC' + ? bity.btcExplorer.replace('[[txHash]]', $scope.shapeShiftStatus.transaction) + : bity.ethExplorer.replace('[[txHash]]', $scope.shapeShiftStatus.transaction); + + return { + txHref: txHref, + transaction: $scope.shapeShiftStatus.transaction + }; } - initValues(); - if (isStorageOrderExists()) { - $scope.showStage1 = false; - setOrderFromStorage(); + }; + + let processOrderShapeShift = function() { + shapeShiftIntervalDecrease(); + shapeShiftOrderStatusChecking($scope.orderResult.deposit); + }; + + let openOrderShapeShift = function() { + shapeShiftService + .sendAmount( + $scope.swapOrder.toAddress, + $scope.swapOrder.fromCoin, + $scope.swapOrder.toCoin, + $scope.swapOrder.toVal + ) + .then(function(orderInfo) { + $scope.orderOpenLoading = false; + $scope.showStage2 = false; + $scope.showStage3ShapeShift = true; + if ($scope.swapOrder.fromCoin === 'BTC') { + $scope.showStage3Eth = false; + $scope.showStage3Btc = true; + } else { + $scope.showStage3Btc = false; + $scope.showStage3Eth = true; + } + $scope.orderResult = orderInfo; + $scope.orderResult.provider = 'SHAPESHIFT'; + $scope.orderResult.inputCurrency = orderInfo.pair.split('_')[0].toUpperCase(); + $scope.orderResult.outputCurrency = orderInfo.pair.split('_')[1].toUpperCase(); + saveOrderToStorage($scope.orderResult); + processOrder(); + }) + .catch(function(err) { + // TODO - show error notification here + $scope.orderOpenLoading = false; + }); + }; + + $scope.openOrder = function() { + if (isValidAddress()) { + $scope.orderOpenLoading = true; + if ($scope.isBitySwap) { + openOrderBity(); + } else { + openOrderShapeShift(); + } + } else { + $scope.notifier.danger(globalFuncs.errorMsgs[5]); } + }; + + $scope.newSwap = function() { + globalFuncs.localStorage.setItem(lStorageKey, ''); + initValues(); + }; + + if (isStorageOrderExists()) { + $scope.showStage1 = false; + setOrderFromStorage(); + } else { + initValues(); + } }; + module.exports = swapCtrl; diff --git a/app/scripts/controllers/tabsCtrl.js b/app/scripts/controllers/tabsCtrl.js index 91c83e3450..300a4ac536 100644 --- a/app/scripts/controllers/tabsCtrl.js +++ b/app/scripts/controllers/tabsCtrl.js @@ -199,8 +199,14 @@ var tabsCtrl = function($scope, globalService, $translate, $sce) { $scope.tabClick = function(id) { globalService.tokensLoaded = false $scope.activeTab = globalService.currentTab = id; + // swap tab + if (id === 4) { + globalFuncs.localStorage.setItem('seenSwap', true) + } for (var key in $scope.tabNames) { - if ($scope.tabNames[key].id == id) location.hash = $scope.tabNames[key].url; + if ($scope.tabNames[key].id == id) { + location.hash = $scope.tabNames[key].url; + } } } diff --git a/app/scripts/directives/balanceDrtv.html b/app/scripts/directives/balanceDrtv.html index 63f2fbc747..040f3672b8 100644 --- a/app/scripts/directives/balanceDrtv.html +++ b/app/scripts/directives/balanceDrtv.html @@ -113,10 +113,21 @@