diff --git a/public/views/buyAndSell.html b/public/views/buyAndSell.html deleted file mode 100644 index 03e1e09c9..000000000 --- a/public/views/buyAndSell.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - Buy and sell - - - - - - - - - - - - - - - - diff --git a/public/views/buyGlidera.html b/public/views/buyGlidera.html index f2754e627..a447eff9b 100644 --- a/public/views/buyGlidera.html +++ b/public/views/buyGlidera.html @@ -1,123 +1,145 @@ -
-
+ + + + + + Buy + + -
+
+ + Testnet wallets only work with Glidera Sandbox Accounts +
-
-

+

Daily buy limit: - {{index.glideraLimits.dailyBuy|currency:'':2}} {{index.glideraLimits.currency}} - (remaining {{index.glideraLimits.dailyBuyRemaining|currency:'':2}} {{index.glideraLimits.currency}}) + {{limits.dailyBuy|currency:'':2}} {{limits.currency}} + (remaining {{limits.dailyBuyRemaining|currency:'':2}} {{limits.currency}})
Monthly buy limit: - {{index.glideraLimits.monthlyBuy|currency:'':2}} {{index.glideraLimits.currency}} - (remaining {{index.glideraLimits.monthlyBuyRemaining|currency:'':2}} {{index.glideraLimits.currency}}) -
-
+ {{limits.monthlyBuy|currency:'':2}} {{limits.currency}} + (remaining {{limits.monthlyBuyRemaining|currency:'':2}} {{limits.currency}}) + -
-
+
+ + This operation was disabled because you have a pending first transaction + +
-
- - This operation was disabled because you have a pending first transaction - -
+
-
+
- +
-
- -
- - - - -
-
+ - -
- - +
- -
-
-
- {{buy.buyPrice.subtotal|currency:'':2}} {{buy.buyPrice.currency}} → {{buy.buyPrice.qty}} BTC -

- A SMS containing a confirmation code was sent to your phone.
- Please, enter the code below -

-
- - -
-

- Fiat will be immediately withdrawn from your bank account. The bitcoins will be purchased and deposited to your wallet ({{index.walletName}}) in 2-4 business days. -

+ BTC + USD +
-
-
- - {{buy.error}} - -
-
-

Purchase initiated

-

- A transfer has been initiated from your bank account. Your bitcoins should arrive to your wallet in 2-4 business days. -

- +
+ Buy + {{buy.buyPrice.subtotal|currency:'':2}} {{buy.buyPrice.currency}} in Bitcoin + {{buy.buyPrice.qty}} BTC + at {{buy.buyPrice.price}} {{buy.buyPrice.currency}}/BTC +
+
+ (Enter the amount to get the exchange rate) +
+ +
+ ... +
+ + + +
+
+
+{{buy.buyPrice.subtotal|currency:'':2}} {{buy.buyPrice.currency}} → {{buy.buyPrice.qty}} BTC +

+ A SMS containing a confirmation code was sent to your phone.
+ Please, enter the code below +

+
+
+ +
+ +
+

+ Fiat will be immediately withdrawn from your bank account. The bitcoins will be purchased and deposited to your wallet in 2-4 business days. +

-
-
-
+
+ + {{buy.error}} + +
+
+

Purchase initiated

+

+ A transfer has been initiated from your bank account. Your bitcoins should arrive to your wallet in 2-4 business days. +

+ + +
+ + diff --git a/public/views/glidera.html b/public/views/glidera.html index 020bbb832..b626ad29d 100644 --- a/public/views/glidera.html +++ b/public/views/glidera.html @@ -1,201 +1,187 @@ - -
-
- - -
- -
-
-
- {{index.glideraError}} -
-
-
- -
- - -
-
-
+ + Glidera + -
-
+ + +
Testnet wallets only work with Glidera Sandbox Accounts
-
-
- +
+
+ {{error}}
-
-

You can buy and sell Bitcoin with a US bank account directly in Copay.

+
+
+ +
+ + +
+
-

- DISCLOSURE.
- Glidera Inc. (Glidera) is providing the service of buying or selling bitcoins to Copay users. To enable this - service, Glidera has registered with US Treasury Department’s FinCEN as a Money Service Business - (#31000042625755). Users of Copay must agree to the service agreement presented by Glidera prior to obtaining - Glidera’s service of buying or selling bitcoins. Service available in U.S. and Canada only. In U.S. (buy & sell) CA, GA, IL, KS, - MA, MD, MO, MT, MN, SC, TX, AZ, CO, DE, ME, NJ, PA, TN, UT, NV, WI. In Canada (buy & sell) AB, BC, MB, NB, NL, NS, NT, NU, - ON, PE, SK, YT. -

+
-

Connect your Glidera account to get started

+
+
+ +
+ +
+
+ {{error}} +
+
+
+ +
+
+
+ +
+
+ +
+
+
+
+
+
+ + -
- -
-
- -
-
-
-
- Preferences -
-
- - {{index.glideraPersonalInfo.firstName}} {{index.glideraPersonalInfo.lastName}} - -
-
- {{index.glideraEmail}} -
-
-
-
- - - - -
-
-
-
-
-

Complete Setup

-
Your Glidera account is not ready to transact. Please, verify it at Glidera.io
- - Go to Glidera - -
-
-
- -
    -
  • - buy bitcoin - Buy Bitcoin - - - -
  • -
  • - buy bitcoin - Sell Bitcoin - - - -
  • -
- -
-

Activity

-
- No activity in your account -
-
-
- bought - bought - bought - bought -
- -
-
- Bought - Sold - {{tx.qty}} BTC -
- - {{tx.subtotal|currency:'':2}} {{tx.currency}} - -
-
-
-
- -
-
- Processing -
-
-
-
- -
-
-
- -
-
-
+
+ diff --git a/public/views/modals/glidera-confirmation.html b/public/views/modals/glidera-confirmation.html index 2d58612af..1a8f5622b 100644 --- a/public/views/modals/glidera-confirmation.html +++ b/public/views/modals/glidera-confirmation.html @@ -1,18 +1,14 @@ - -
-
-

Are you sure you would like to log out of your Glidera account?

-

You will need to log back in to buy or sell bitcoin in Copay.

-
- +
-
- -
-
-
+
diff --git a/public/views/modals/glidera-tx-details.html b/public/views/modals/glidera-tx-details.html index e072f9ddc..8696edc71 100644 --- a/public/views/modals/glidera-tx-details.html +++ b/public/views/modals/glidera-tx-details.html @@ -1,12 +1,10 @@ - -

Details

+ +

Details

diff --git a/public/views/preferencesGlidera.html b/public/views/preferencesGlidera.html index 7336059b5..dedea52b0 100644 --- a/public/views/preferencesGlidera.html +++ b/public/views/preferencesGlidera.html @@ -1,266 +1,278 @@ -
-
+ + + + + + Preferences + -
+ -
    -

    Permissions

    -
  • - Email - - {{index.glideraPermissions.view_email_address}} - -
  • -
  • - Personal Information - - {{index.glideraPermissions.personal_info}} - -
  • -
  • - Buy/Sell - - {{index.glideraPermissions.transact}} - -
  • -
  • - Transaction History - - {{index.glideraPermissions.transaction_history}} - -
  • -
+
    +
    + Permissions +
    +
  • + Email + + {{permissions.view_email_address}} + +
  • +
  • + Personal Information + + {{permissions.personal_info}} + +
  • +
  • + Buy/Sell + + {{permissions.transact}} + +
  • +
  • + Transaction History + + {{permissions.transaction_history}} + +
  • +
-
    -

    Email

    -
  • - Email - - {{glidera.email.email}} - -
  • -
  • - Active - - {{glidera.email.userEmailIsSetup}} - -
  • -
+
    +
    + Email +
    +
  • + Email + + {{email.email}} + +
  • +
  • + Active + + {{email.userEmailIsSetup}} + +
  • +
-
    -

    Personal Information

    +
      +
      + Personal Information +
      -
    • - First Name - - {{glidera.personalInfo.firstName}} - -
    • -
    • - Middle Name - - {{glidera.personalInfo.middleName}} - -
    • -
    • - Last Name - - {{glidera.personalInfo.lastName}} - -
    • -
    • - Birth Date - - {{glidera.personalInfo.birthDate}} - -
    • -
    • - Address 1 - - {{glidera.personalInfo.address1}} - -
    • -
    • - Address 2 - - {{glidera.personalInfo.address2}} - -
    • -
    • - City - - {{glidera.personalInfo.city}} - -
    • -
    • - State - - {{glidera.personalInfo.state}} - -
    • -
    • - ZIP Code - - {{glidera.personalInfo.zipCode}} - -
    • -
    • - Country - - {{glidera.personalInfo.countryCode}} - -
    • -
    • - Occupation - - {{glidera.personalInfo.occupation}} - -
    • -
    • - Basic Information State - - {{glidera.personalInfo.basicInfoState}} - -
    • -
    +
  • + First Name + + {{personalInfo.firstName}} + +
  • +
  • + Middle Name + + {{personalInfo.middleName}} + +
  • +
  • + Last Name + + {{personalInfo.lastName}} + +
  • +
  • + Birth Date + + {{personalInfo.birthDate}} + +
  • +
  • + Address 1 + + {{personalInfo.address1}} + +
  • +
  • + Address 2 + + {{personalInfo.address2}} + +
  • +
  • + City + + {{personalInfo.city}} + +
  • +
  • + State + + {{personalInfo.state}} + +
  • +
  • + ZIP Code + + {{personalInfo.zipCode}} + +
  • +
  • + Country + + {{personalInfo.countryCode}} + +
  • +
  • + Occupation + + {{personalInfo.occupation}} + +
  • +
  • + Basic Information State + + {{personalInfo.basicInfoState}} + +
  • +
-
    -

    Status

    +
      +
      + Status +
      -
    • - Buy/Sell - - {{glidera.status.userCanTransact}} - -
    • +
    • + Buy/Sell + + {{status.userCanTransact}} + +
    • -
    • - Buy - - {{glidera.status.userCanBuy}} - -
    • -
    • - Sell - - {{glidera.status.userCanSell}} - -
    • -
    • - Email Is Setup - - {{glidera.status.userEmailIsSetup}} - -
    • -
    • - Phone Is Setup - - {{glidera.status.userPhoneIsSetup}} - -
    • -
    • - Bank Account Is Setup - - {{glidera.status.userBankAccountIsSetup}} - -
    • -
    • - Personal Information State - - {{glidera.status.personalInfoState}} - -
    • -
    • - Bank Account State - - {{glidera.status.bankAccountState}} - -
    • -
    • - Country - - {{glidera.status.country}} - -
    • -
    +
  • + Buy + + {{status.userCanBuy}} + +
  • +
  • + Sell + + {{status.userCanSell}} + +
  • +
  • + Email Is Setup + + {{status.userEmailIsSetup}} + +
  • +
  • + Phone Is Setup + + {{status.userPhoneIsSetup}} + +
  • +
  • + Bank Account Is Setup + + {{status.userBankAccountIsSetup}} + +
  • +
  • + Personal Information State + + {{status.personalInfoState}} + +
  • +
  • + Bank Account State + + {{status.bankAccountState}} + +
  • +
  • + Country + + {{status.country}} + +
  • +
-
    -

    Limits

    +
      +
      + Limits +
      -
    • - Daily Buy - - {{glidera.limits.dailyBuy|currency:'':2}} {{glidera.limits.currency}} - -
    • -
    • - Daily Sell - - {{glidera.limits.dailySell|currency:'':2}} {{glidera.limits.currency}} - -
    • -
    • - Monthly Buy - - {{glidera.limits.monthlyBuy|currency:'':2}} {{glidera.limits.currency}} - -
    • -
    • - Monthly Sell - - {{glidera.limits.monthlySell|currency:'':2}} {{glidera.limits.currency}} - -
    • -
    • - Daily Buy Remaining - - {{glidera.limits.dailyBuyRemaining|currency:'':2}} {{glidera.limits.currency}} - -
    • -
    • - Daily Sell Remaining - - {{glidera.limits.dailySellRemaining|currency:'':2}} {{glidera.limits.currency}} - -
    • -
    • - Monthly Buy Remaining - - {{glidera.limits.monthlyBuyRemaining|currency:'':2}} {{glidera.limits.currency}} - -
    • -
    • - Monthly Sell Remaining - - {{glidera.limits.monthlySellRemaining|currency:'':2}} {{glidera.limits.currency}} - -
    • -
    • - Buy/Sell Disabled (pending first transaction) - - {{glidera.limits.transactDisabledPendingFirstTransaction}} - -
    • -
    +
  • + Daily Buy + + {{limits.dailyBuy|currency:'':2}} {{limits.currency}} + +
  • +
  • + Daily Sell + + {{limits.dailySell|currency:'':2}} {{limits.currency}} + +
  • +
  • + Monthly Buy + + {{limits.monthlyBuy|currency:'':2}} {{limits.currency}} + +
  • +
  • + Monthly Sell + + {{limits.monthlySell|currency:'':2}} {{limits.currency}} + +
  • +
  • + Daily Buy Remaining + + {{limits.dailyBuyRemaining|currency:'':2}} {{limits.currency}} + +
  • +
  • + Daily Sell Remaining + + {{limits.dailySellRemaining|currency:'':2}} {{limits.currency}} + +
  • +
  • + Monthly Buy Remaining + + {{limits.monthlyBuyRemaining|currency:'':2}} {{limits.currency}} + +
  • +
  • + Monthly Sell Remaining + + {{limits.monthlySellRemaining|currency:'':2}} {{limits.currency}} + +
  • +
  • + Buy/Sell Disabled (pending first transaction) + + {{limits.transactDisabledPendingFirstTransaction}} + +
  • +
-
    -

    Account

    +
      +
      + Account +
      -
    • - - Log out -
    • -
    -

    +
  • + Log out +
  • +
+
+ -
-
diff --git a/public/views/sellGlidera.html b/public/views/sellGlidera.html index 160e33656..f5a7796e8 100644 --- a/public/views/sellGlidera.html +++ b/public/views/sellGlidera.html @@ -1,123 +1,140 @@ -
-
+ + + + + + Sell + + -
- -
-

+

Daily sell limit: - {{index.glideraLimits.dailySell|currency:'':2}} {{index.glideraLimits.currency}} - (remaining {{index.glideraLimits.dailySellRemaining|currency:'':2}} {{index.glideraLimits.currency}}) + {{limits.dailySell|currency:'':2}} {{limits.currency}} + (remaining {{limits.dailySellRemaining|currency:'':2}} {{limits.currency}})
Monthly sell limit: - {{index.glideraLimits.monthlySell|currency:'':2}} {{index.glideraLimits.currency}} - (remaining {{index.glideraLimits.monthlySellRemaining|currency:'':2}} {{index.glideraLimits.currency}}) + {{limits.monthlySell|currency:'':2}} {{limits.currency}} + (remaining {{limits.monthlySellRemaining|currency:'':2}} {{limits.currency}})

-
-
-
+
+ + This operation was disabled because you have a pending first transaction + +
-
- - This operation was disabled because you have a pending first transaction - -
+
+
-
- +
+ -
- -
- - - - -
-
+
-
-
-{{sell.sellPrice.qty}} BTC → {{sell.sellPrice.subtotal|currency:'':2}} {{sell.sellPrice.currency}} -

- A SMS containing a confirmation code was sent to your phone.
- Please, enter the code below -

-
- - -
-

- Bitcoins will be immediately sent from your wallet to Glidera. Fiat will be deposited in your bank account in 4-6 business days. -

+ BTC + USD +
-
-
- - {{sell.error}} - -
-
-

Sale initiated

-

- A transfer has been initiated to your bank account and should arrive in 4-6 business days. -

- +
+ Sell + {{sell.sellPrice.subtotal|currency:'':2}} {{sell.sellPrice.currency}} in Bitcoin + {{sell.sellPrice.qty}} BTC + at {{sell.sellPrice.price|currency:'':2}} {{sell.sellPrice.currency}}/BTC + +
+
+ (Enter the amount to get the exchange rate) +
+ +
+ ... +
+ + + +
+
+
+{{sell.sellPrice.qty}} BTC → {{sell.sellPrice.subtotal|currency:'':2}} {{sell.sellPrice.currency}} +

+ A SMS containing a confirmation code was sent to your phone.
+ Please, enter the code below +

+
+
+ +
+ +
+

+ Bitcoins will be immediately sent from your wallet to Glidera. Fiat will be deposited in your bank account in 4-6 business days. +

-
-
-
+
+
+ + {{sell.error}} + +
+
+

Sale initiated

+

+ A transfer has been initiated to your bank account and should arrive in 4-6 business days. +

+ + +
+ + + diff --git a/public/views/tab-home.html b/public/views/tab-home.html index 5fbb422c2..2ac318630 100644 --- a/public/views/tab-home.html +++ b/public/views/tab-home.html @@ -75,6 +75,18 @@
+
+

Buy & Sell Bitcoin

+
+
+ +
+
+ +
+
+
+

Next steps

    @@ -82,10 +94,6 @@ BitPay Card -
  • - - Buy and Sell -
  • Gift Cards diff --git a/src/js/controllers/buyGlidera.js b/src/js/controllers/buyGlidera.js index a0eff911c..0c92b3adc 100644 --- a/src/js/controllers/buyGlidera.js +++ b/src/js/controllers/buyGlidera.js @@ -1,26 +1,89 @@ 'use strict'; angular.module('copayApp.controllers').controller('buyGlideraController', - function($scope, $timeout, $ionicModal, profileService, addressService, glideraService, bwcError, lodash, ongoingProcess) { + function($scope, $timeout, $log, $ionicModal, profileService, walletService, glideraService, bwcError, lodash, ongoingProcess) { + var wallet; var self = this; this.show2faCodeInput = null; this.error = null; this.success = null; - this.init = function(testnet) { - self.allWallets = profileService.getWallets(testnet ? 'testnet' : 'livenet'); + $scope.init = function(accessToken) { + $scope.network = glideraService.getEnvironment(); - var client = profileService.focusedClient; - if (client) { + $scope.token = accessToken; + $scope.error = null; + $scope.permissions = null; + $scope.email = null; + $scope.personalInfo = null; + $scope.txs = null; + $scope.status = null; + $scope.limits = null; + + ongoingProcess.set('connectingGlidera', true); + glideraService.init($scope.token, function(err, glidera) { + ongoingProcess.set('connectingGlidera'); + if (err || !glidera) { + $scope.error = err; + return; + } + $scope.token = glidera.token; + $scope.permissions = glidera.permissions; + $scope.update({fullUpdate: true}); + }); + + self.allWallets = profileService.getWallets({ + network: $scope.network, + n: 1, + onlyComplete: true + }); + if (lodash.isEmpty(self.allWallets)) return; + + wallet = self.allWallets[0]; + if (wallet) { $timeout(function() { - self.selectedWalletId = client.credentials.walletId; - self.selectedWalletName = client.credentials.walletName; + self.selectedWalletId = wallet.credentials.walletId; + self.selectedWalletName = wallet.credentials.walletName; $scope.$apply(); }, 100); } }; + $scope.update = function(opts) { + if (!$scope.token || !$scope.permissions) return; + $log.debug('Updating Glidera Account...'); + var accessToken = $scope.token; + var permissions = $scope.permissions; + + opts = opts || {}; + + glideraService.getStatus(accessToken, function(err, data) { + $scope.status = data; + }); + + glideraService.getLimits(accessToken, function(err, limits) { + $scope.limits = limits; + }); + + if (permissions.transaction_history) { + glideraService.getTransactions(accessToken, function(err, data) { + $scope.txs = data; + }); + } + + if (permissions.view_email_address && opts.fullUpdate) { + glideraService.getEmail(accessToken, function(err, data) { + $scope.email = data.email; + }); + } + if (permissions.personal_info && opts.fullUpdate) { + glideraService.getPersonalInfo(accessToken, function(err, data) { + $scope.personalInfo = data; + }); + } + }; + $scope.openWalletsModal = function(wallets) { self.error = null; @@ -39,9 +102,9 @@ angular.module('copayApp.controllers').controller('buyGlideraController', $scope.$on('walletSelected', function(ev, walletId) { $timeout(function() { - var client = profileService.getClient(walletId); + wallet = profileService.getClient(walletId); self.selectedWalletId = walletId; - self.selectedWalletName = client.credentials.walletName; + self.selectedWalletName = wallet.credentials.walletName; $scope.$apply(); }, 100); $scope.walletsModal.hide(); @@ -87,7 +150,7 @@ angular.module('copayApp.controllers').controller('buyGlideraController', self.error = null; ongoingProcess.set('Buying Bitcoin...', true); $timeout(function() { - addressService.getAddress(self.selectedWalletId, false, function(err, walletAddr) { + walletService.getAddress(wallet, false, function(err, walletAddr) { if (err) { ongoingProcess.set('Buying Bitcoin...', false); self.error = bwcError.cb(err, 'Could not create address'); diff --git a/src/js/controllers/glidera.js b/src/js/controllers/glidera.js index f72a6c5f6..db9fb51a9 100644 --- a/src/js/controllers/glidera.js +++ b/src/js/controllers/glidera.js @@ -1,33 +1,98 @@ 'use strict'; angular.module('copayApp.controllers').controller('glideraController', - function($rootScope, $scope, $timeout, $ionicModal, profileService, configService, storageService, glideraService, lodash, ongoingProcess, platformInfo) { + function($rootScope, $scope, $timeout, $ionicModal, $log, profileService, storageService, glideraService, lodash, ongoingProcess, platformInfo, nodeWebkit) { if (platformInfo.isCordova && StatusBar.isVisible) { StatusBar.backgroundColorByHexString("#4B6178"); } + $scope.openExternalLink = function(url, target) { + if (platformInfo.isNW) { + nodeWebkit.openExternalLink(url); + } else { + target = target || '_blank'; + var ref = window.open(url, target, 'location=no'); + } + }; + + $scope.init = function(accessToken) { + $scope.network = glideraService.getEnvironment(); + + $scope.token = null; + $scope.error = null; + $scope.permissions = null; + $scope.email = null; + $scope.personalInfo = null; + $scope.txs = null; + $scope.status = null; + $scope.limits = null; + + ongoingProcess.set('connectingGlidera', true); + glideraService.init($scope.token, function(err, glidera) { + ongoingProcess.set('connectingGlidera'); + if (err || !glidera) { + $scope.error = err; + return; + } + $scope.token = glidera.token; + $scope.permissions = glidera.permissions; + $scope.update({fullUpdate: true}); + }); + }; + + $scope.update = function(opts) { + if (!$scope.token || !$scope.permissions) return; + $log.debug('Updating Glidera Account...'); + var accessToken = $scope.token; + var permissions = $scope.permissions; + + opts = opts || {}; + + glideraService.getStatus(accessToken, function(err, data) { + $scope.status = data; + }); + + glideraService.getLimits(accessToken, function(err, limits) { + $scope.limits = limits; + }); + + if (permissions.transaction_history) { + glideraService.getTransactions(accessToken, function(err, data) { + $scope.txs = data; + }); + } + + if (permissions.view_email_address && opts.fullUpdate) { + glideraService.getEmail(accessToken, function(err, data) { + $scope.email = data.email; + }); + } + if (permissions.personal_info && opts.fullUpdate) { + glideraService.getPersonalInfo(accessToken, function(err, data) { + $scope.personalInfo = data; + }); + } + }; + this.getAuthenticateUrl = function() { return glideraService.getOauthCodeUrl(); }; this.submitOauthCode = function(code) { - var self = this; - var glideraTestnet = configService.getSync().glidera.testnet; - var network = glideraTestnet ? 'testnet' : 'livenet'; ongoingProcess.set('connectingGlidera', true); - this.error = null; + $scope.error = null; $timeout(function() { glideraService.getToken(code, function(err, data) { ongoingProcess.set('connectingGlidera', false); if (err) { - self.error = err; + $scope.error = err; $timeout(function() { $scope.$apply(); }, 100); } else if (data && data.access_token) { - storageService.setGlideraToken(network, data.access_token, function() { - $scope.$emit('Local/GlideraUpdated', data.access_token); + storageService.setGlideraToken($scope.network, data.access_token, function() { + $scope.init(data.access_token); $timeout(function() { $scope.$apply(); }, 100); diff --git a/src/js/controllers/modals/glideraConfirmation.js b/src/js/controllers/modals/glideraConfirmation.js index eb83a0615..8a1b846ef 100644 --- a/src/js/controllers/modals/glideraConfirmation.js +++ b/src/js/controllers/modals/glideraConfirmation.js @@ -1,11 +1,11 @@ 'use strict'; -angular.module('copayApp.controllers').controller('glideraConfirmationController', function($scope, $timeout, storageService, applicationService) { +angular.module('copayApp.controllers').controller('glideraConfirmationController', function($scope, $timeout, $state, glideraService) { $scope.ok = function() { - storageService.removeGlideraToken($scope.network, function() { + glideraService.removeToken(function() { $timeout(function() { - applicationService.restart(); + $state.go('glidera.main'); }, 100); }); $scope.cancel(); diff --git a/src/js/controllers/preferencesGlidera.js b/src/js/controllers/preferencesGlidera.js index 1428ca933..e47c24c3b 100644 --- a/src/js/controllers/preferencesGlidera.js +++ b/src/js/controllers/preferencesGlidera.js @@ -1,43 +1,70 @@ 'use strict'; angular.module('copayApp.controllers').controller('preferencesGlideraController', - function($scope, $timeout, $ionicModal, profileService, applicationService, glideraService, storageService) { + function($scope, $log, $ionicModal, ongoingProcess, glideraService) { - this.getEmail = function(token) { - var self = this; - glideraService.getEmail(token, function(error, data) { - self.email = data; + $scope.init = function(accessToken) { + $scope.network = glideraService.getEnvironment(); + + $scope.token = accessToken; + $scope.error = null; + $scope.permissions = null; + $scope.email = null; + $scope.personalInfo = null; + $scope.txs = null; + $scope.status = null; + $scope.limits = null; + + ongoingProcess.set('connectingGlidera', true); + glideraService.init($scope.token, function(err, glidera) { + ongoingProcess.set('connectingGlidera'); + if (err || !glidera) { + $scope.error = err; + return; + } + $scope.token = glidera.token; + $scope.permissions = glidera.permissions; + $scope.update({fullUpdate: true}); }); }; - this.getPersonalInfo = function(token) { - var self = this; - glideraService.getPersonalInfo(token, function(error, info) { - self.personalInfo = info; + $scope.update = function(opts) { + if (!$scope.token || !$scope.permissions) return; + $log.debug('Updating Glidera Account...'); + var accessToken = $scope.token; + var permissions = $scope.permissions; + + opts = opts || {}; + + glideraService.getStatus(accessToken, function(err, data) { + $scope.status = data; }); + + glideraService.getLimits(accessToken, function(err, limits) { + $scope.limits = limits; + }); + + if (permissions.transaction_history) { + glideraService.getTransactions(accessToken, function(err, data) { + $scope.txs = data; + }); + } + + if (permissions.view_email_address && opts.fullUpdate) { + glideraService.getEmail(accessToken, function(err, data) { + $scope.email = data.email; + }); + } + if (permissions.personal_info && opts.fullUpdate) { + glideraService.getPersonalInfo(accessToken, function(err, data) { + $scope.personalInfo = data; + }); + } }; - this.getStatus = function(token) { - var self = this; - glideraService.getStatus(token, function(error, data) { - self.status = data; - }); - }; - - this.getLimits = function(token) { - var self = this; - glideraService.getLimits(token, function(error, limits) { - self.limits = limits; - }); - }; - - this.revokeToken = function(testnet) { - $scope.network = testnet ? 'testnet' : 'livenet'; - $scope.loading = false; - + $scope.revokeToken = function() { $ionicModal.fromTemplateUrl('views/modals/glidera-confirmation.html', { - scope: $scope, - animation: 'slide-in-up' + scope: $scope }).then(function(modal) { $scope.glideraConfirmationModal = modal; $scope.glideraConfirmationModal.show(); diff --git a/src/js/controllers/sellGlidera.js b/src/js/controllers/sellGlidera.js index 59cad402c..ab9e3be9f 100644 --- a/src/js/controllers/sellGlidera.js +++ b/src/js/controllers/sellGlidera.js @@ -1,38 +1,97 @@ 'use strict'; angular.module('copayApp.controllers').controller('sellGlideraController', - function($rootScope, $scope, $timeout, $ionicModal, $log, configService, profileService, addressService, feeService, glideraService, bwcError, lodash, walletService, fingerprintService, ongoingProcess, go) { + function($rootScope, $scope, $timeout, $ionicModal, $log, profileService, glideraService, bwcError, lodash, walletService, fingerprintService, configService, ongoingProcess) { var self = this; - var config = configService.getSync(); this.data = {}; this.show2faCodeInput = null; this.success = null; this.error = null; - var client; + var wallet; - var handleEncryptedWallet = function(client, cb) { - if (!walletService.isEncrypted(client)) return cb(); + var handleEncryptedWallet = function(wallet, cb) { + if (!walletService.isEncrypted(wallet)) return cb(); $rootScope.$emit('Local/NeedsPassword', false, function(err, password) { if (err) return cb(err); - return cb(walletService.unlock(client, password)); + return cb(walletService.unlock(wallet, password)); }); }; - this.init = function(testnet) { - self.allWallets = profileService.getWallets(testnet ? 'testnet' : 'livenet', 1); + $scope.init = function(accessToken) { + $scope.network = glideraService.getEnvironment(); - client = profileService.focusedClient; - if (client && client.credentials.m == 1) { + $scope.token = accessToken; + $scope.error = null; + $scope.permissions = null; + $scope.email = null; + $scope.personalInfo = null; + $scope.txs = null; + $scope.status = null; + $scope.limits = null; + + ongoingProcess.set('connectingGlidera', true); + glideraService.init($scope.token, function(err, glidera) { + ongoingProcess.set('connectingGlidera'); + if (err || !glidera) { + $scope.error = err; + return; + } + $scope.token = glidera.token; + $scope.permissions = glidera.permissions; + $scope.update({fullUpdate: true}); + }); + + self.allWallets = profileService.getWallets({ + network: $scope.network, + n: 1, + onlyComplete: true + }); + if (lodash.isEmpty(self.allWallets)) return; + + wallet = self.allWallets[0]; + if (wallet) { $timeout(function() { - self.selectedWalletId = client.credentials.walletId; - self.selectedWalletName = client.credentials.walletName; + self.selectedWalletId = wallet.credentials.walletId; + self.selectedWalletName = wallet.credentials.walletName; $scope.$apply(); }, 100); } }; + $scope.update = function(opts) { + if (!$scope.token || !$scope.permissions) return; + $log.debug('Updating Glidera Account...'); + var accessToken = $scope.token; + var permissions = $scope.permissions; + opts = opts || {}; + + glideraService.getStatus(accessToken, function(err, data) { + $scope.status = data; + }); + + glideraService.getLimits(accessToken, function(err, limits) { + $scope.limits = limits; + }); + + if (permissions.transaction_history) { + glideraService.getTransactions(accessToken, function(err, data) { + $scope.txs = data; + }); + } + + if (permissions.view_email_address && opts.fullUpdate) { + glideraService.getEmail(accessToken, function(err, data) { + $scope.email = data.email; + }); + } + if (permissions.personal_info && opts.fullUpdate) { + glideraService.getPersonalInfo(accessToken, function(err, data) { + $scope.personalInfo = data; + }); + } + }; $scope.openWalletsModal = function(wallets) { self.error = null; @@ -52,9 +111,9 @@ angular.module('copayApp.controllers').controller('sellGlideraController', $scope.$on('walletSelected', function(ev, walletId) { $timeout(function() { - client = profileService.getClient(walletId); + wallet = profileService.getClient(walletId); self.selectedWalletId = walletId; - self.selectedWalletName = client.credentials.walletName; + self.selectedWalletName = wallet.credentials.walletName; $scope.$apply(); }, 100); $scope.walletsModal.hide(); @@ -98,16 +157,17 @@ angular.module('copayApp.controllers').controller('sellGlideraController', var self = this; self.error = null; var outputs = []; + var config = configService.getSync(); var configWallet = config.wallet; var walletSettings = configWallet.settings; - if (!client) { + if (!wallet) { self.error = 'No wallet selected'; return; } ongoingProcess.set('creatingTx', true); - addressService.getAddress(client.credentials.walletId, null, function(err, refundAddress) { + walletService.getAddress(wallet, null, function(err, refundAddress) { if (!refundAddress) { ongoingProcess.clear(); @@ -142,71 +202,62 @@ angular.module('copayApp.controllers').controller('sellGlideraController', } }; - walletService.createTx(client, txp, function(err, createdTxp) { + walletService.createTx(wallet, txp, function(err, createdTxp) { ongoingProcess.clear(); if (err) { self.error = err.message ||  bwcError.msg(err); return; } - $scope.$emit('Local/NeedsConfirmation', createdTxp, function(accept) { - if (accept) { - fingerprintService.check(client, function(err) { + fingerprintService.check(wallet, function(err) { + if (err) { + self.error = err.message ||  bwcError.msg(err); + return; + } + + handleEncryptedWallet(wallet, function(err) { + if (err) { + self.error = err.message ||  bwcError.msg(err); + return; + } + + ongoingProcess.set('signingTx', true); + walletService.publishTx(wallet, createdTxp, function(err, publishedTxp) { if (err) { + ongoingProcess.clear(); self.error = err.message ||  bwcError.msg(err); - return; } - handleEncryptedWallet(client, function(err) { + walletService.signTx(wallet, publishedTxp, function(err, signedTxp) { + walletService.lock(wallet); + walletService.removeTx(wallet, signedTxp, function(err) { + if (err) $log.debug(err); + }); + ongoingProcess.clear(); if (err) { self.error = err.message ||  bwcError.msg(err); return; } - - ongoingProcess.set('signingTx', true); - walletService.publishTx(client, createdTxp, function(err, publishedTxp) { + var rawTx = signedTxp.raw; + var data = { + refundAddress: refundAddress, + signedTransaction: rawTx, + priceUuid: self.sellPrice.priceUuid, + useCurrentPrice: self.sellPrice.priceUuid ? false : true, + ip: null + }; + ongoingProcess.set('Seling Bitcoin', true); + glideraService.sell(token, twoFaCode, data, function(err, data) { + ongoingProcess.clear(); if (err) { - ongoingProcess.clear(); self.error = err.message ||  bwcError.msg(err); + return; } - - walletService.signTx(client, publishedTxp, function(err, signedTxp) { - walletService.lock(client); - walletService.removeTx(client, signedTxp, function(err) { - if (err) $log.debug(err); - }); - ongoingProcess.clear(); - if (err) { - self.error = err.message ||  bwcError.msg(err); - return; - } - var rawTx = signedTxp.raw; - var data = { - refundAddress: refundAddress, - signedTransaction: rawTx, - priceUuid: self.sellPrice.priceUuid, - useCurrentPrice: self.sellPrice.priceUuid ? false : true, - ip: null - }; - ongoingProcess.set('Seling Bitcoin', true); - glideraService.sell(token, twoFaCode, data, function(err, data) { - ongoingProcess.clear(); - if (err) { - self.error = err.message ||  bwcError.msg(err); - $timeout(function() { - $scope.$emit('Local/GlideraError'); - }, 100); - return; - } - self.success = data; - $scope.$emit('Local/GlideraTx'); - }); - }); + self.success = data; + $scope.update(); }); }); }); - } else { - go.path('glidera'); - } + }); }); }); }); diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index fe3687958..ae3cbe81d 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -162,10 +162,9 @@ angular.module('copayApp.controllers').controller('tabHomeController', configService.whenAvailable(function() { var config = configService.getSync(); - var glideraEnabled = config.glidera.enabled; - var coinbaseEnabled = config.coinbase.enabled; var isWindowsPhoneApp = platformInfo.isWP && isCordova; - $scope.buyAndSellEnabled = !isWindowsPhoneApp && (glideraEnabled || coinbaseEnabled); + $scope.glideraEnabled = config.glidera.enabled && !isWindowsPhoneApp; + $scope.coinbaseEnabled = config.coinbase.enabled && !isWindowsPhoneApp; }); }); diff --git a/src/js/routes.js b/src/js/routes.js index 5c1e95d18..744e6758a 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -103,25 +103,21 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr */ .state('uri', { - url: '/uri/:url', - needProfile: true, - views: { - 'main': { - templateUrl: 'views/uri.html' - } - } - }) - .state('uripayment', { - url: '/uri-payment/:url', - templateUrl: 'views/paymentUri.html', - views: { - 'main': { - templateUrl: 'views/paymentUri.html', - }, - }, - needProfile: true - }) - + url: '/uri/:url', + templateUrl: 'views/uri.html' + }) + .state('uripayment', { + url: '/uri-payment/:url', + templateUrl: 'views/paymentUri.html' + }) + .state('uriglidera', { + url: '/uri-glidera/:url', + templateUrl: 'views/glideraUri.html' + }) + .state('uricoinbase', { + url: '/uri-coinbase/:url', + templateUrl: 'views/coinbaseUri.html' + }) /* * @@ -528,27 +524,97 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr * * Glidera * + * */ - .state('uriglidera', { - url: '/uri-glidera/:url', - templateUrl: 'views/glideraUri.html' - }) .state('glidera', { url: '/glidera', - templateUrl: 'views/glidera.html' + abstract: true, + template: '' }) - .state('buyGlidera', { + .state('glidera.main', { + url: '/main', + views: { + 'glidera': { + templateUrl: 'views/glidera.html' + } + } + }) + .state('glidera.buy', { url: '/buy', - templateUrl: 'views/buyGlidera.html' + views: { + 'glidera': { + templateUrl: 'views/buyGlidera.html' + } + } }) - .state('sellGlidera', { + .state('glidera.sell', { url: '/sell', - templateUrl: 'views/sellGlidera.html' + views: { + 'glidera': { + templateUrl: 'views/sellGlidera.html' + } + } }) - .state('preferencesGlidera', { - url: '/preferencesGlidera', - templateUrl: 'views/preferencesGlidera.html' + .state('glidera.preferences', { + url: '/preferences', + views: { + 'glidera': { + templateUrl: 'views/preferencesGlidera.html' + } + } + }) + + /* + * + * Coinbase + * + */ + + .state('coinbase', { + url: '/coinbase', + templateUrl: 'views/coinbase.html' + }) + .state('preferencesCoinbase', { + url: '/preferencesCoinbase', + templateUrl: 'views/preferencesCoinbase.html' + }) + .state('buyCoinbase', { + url: '/buycoinbase', + templateUrl: 'views/buyCoinbase.html' + }) + .state('sellCoinbase', { + url: '/sellcoinbase', + templateUrl: 'views/sellCoinbase.html' + }) + + + /* + * + * Amazon Gift Card + * + */ + + .state('amazon', { + url: '/amazon', + abstract: true, + template: '' + }) + .state('amazon.main', { + url: '/main', + views: { + 'amazon': { + templateUrl: 'views/amazon.html' + } + } + }) + .state('amazon.buy', { + url: '/buy', + views: { + 'amazon': { + templateUrl: 'views/buyAmazon.html' + } + } }) /* @@ -577,70 +643,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr templateUrl: 'views/preferencesBitpayCard.html' } } - }) - - /* - * - * Coinbase - * - */ - - .state('coinbase', { - url: '/coinbase', - templateUrl: 'views/coinbase.html' - }) - .state('preferencesCoinbase', { - url: '/preferencesCoinbase', - templateUrl: 'views/preferencesCoinbase.html' - }) - .state('uricoinbase', { - url: '/uri-coinbase/:url', - templateUrl: 'views/coinbaseUri.html' - }) - .state('buyCoinbase', { - url: '/buycoinbase', - templateUrl: 'views/buyCoinbase.html' - }) - .state('sellCoinbase', { - url: '/sellcoinbase', - templateUrl: 'views/sellCoinbase.html' - }) - .state('buyandsell', { - url: '/buyandsell', - templateUrl: 'views/buyAndSell.html', - controller: function(platformInfo) { - if (platformInfo.isCordova && StatusBar.isVisible) { - StatusBar.backgroundColorByHexString("#4B6178"); - } - } - }) - - /* - * - * Amazon Gift Card - * - */ - - .state('amazon', { - url: '/amazon', - abstract: true, - template: '' - }) - .state('amazon.main', { - url: '/main', - views: { - 'amazon': { - templateUrl: 'views/amazon.html' - } - } - }) - .state('amazon.buy', { - url: '/buy', - views: { - 'amazon': { - templateUrl: 'views/buyAmazon.html' - } - } }); }) .run(function($rootScope, $state, $location, $log, $timeout, $ionicHistory, $ionicPlatform, lodash, platformInfo, profileService, uxLanguage, gettextCatalog) { diff --git a/src/js/services/configService.js b/src/js/services/configService.js index 5f0ebe92c..53bb686e9 100644 --- a/src/js/services/configService.js +++ b/src/js/services/configService.js @@ -123,11 +123,6 @@ angular.module('copayApp.services').factory('configService', function(storageSer configCache.colorFor = configCache.colorFor || {}; configCache.aliasFor = configCache.aliasFor || {}; - - // Glidera - // Disabled for testnet - configCache.glidera.testnet = false; - // Coinbase // Disabled for testnet configCache.coinbase.testnet = false; diff --git a/src/js/services/glideraService.js b/src/js/services/glideraService.js index 6f96ee2cb..31b373105 100644 --- a/src/js/services/glideraService.js +++ b/src/js/services/glideraService.js @@ -4,11 +4,15 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l var root = {}; var credentials = {}; var isCordova = platformInfo.isCordova; - // - // - root.setCredentials = function(network) { - if (network == 'testnet') { + var _setCredentials = function() { + /* + * Development: 'testnet' + * Production: 'livenet' + */ + credentials.NETWORK = 'livenet'; + + if (credentials.NETWORK == 'testnet') { credentials.HOST = 'https://sandbox.glidera.io'; if (isCordova) { credentials.REDIRECT_URI = 'copay://glidera'; @@ -33,11 +37,25 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l }; }; + root.getEnvironment = function() { + _setCredentials(); + return credentials.NETWORK; + }; + root.getOauthCodeUrl = function() { + _setCredentials(); return credentials.HOST + '/oauth2/auth?response_type=code&client_id=' + credentials.CLIENT_ID + '&redirect_uri=' + credentials.REDIRECT_URI; }; + root.removeToken = function(cb) { + _setCredentials(); + storageService.removeGlideraToken(credentials.NETWORK, function() { + return cb(); + }); + }; + root.getToken = function(code, cb) { + _setCredentials(); var req = { method: 'POST', url: credentials.HOST + '/api/v1/oauth/token', @@ -64,6 +82,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l }; var _get = function(endpoint, token) { + _setCredentials(); return { method: 'GET', url: credentials.HOST + '/api/v1' + endpoint, @@ -176,6 +195,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l }; var _post = function(endpoint, token, twoFaCode, data) { + _setCredentials(); return { method: 'POST', url: credentials.HOST + '/api/v1' + endpoint, @@ -251,91 +271,39 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l }); }; - root.init = function(accessToken) { - root.glideraEnabled = configService.getSync().glidera.enabled; - root.glideraTestnet = configService.getSync().glidera.testnet; - var network = root.glideraTestnet ? 'testnet' : 'livenet'; + root.init = function(accessToken, cb) { + _setCredentials(); + $log.debug('Init Glidera...'); - root.glideraToken = null; - root.glideraError = null; - root.glideraPermissions = null; - root.glideraEmail = null; - root.glideraPersonalInfo = null; - root.glideraTxs = null; - root.glideraStatus = null; - - if (!root.glideraEnabled) return; - - root.setCredentials(network); + var glidera = { + token: null, + permissions: null + } var getToken = function(cb) { if (accessToken) { cb(null, accessToken); } else { - storageService.getGlideraToken(network, cb); + storageService.getGlideraToken(credentials.NETWORK, cb); } }; getToken(function(err, accessToken) { - if (err || !accessToken) return; + if (err || !accessToken) return cb(); else { root.getAccessTokenPermissions(accessToken, function(err, p) { if (err) { - root.glideraError = err; + return cb(err); } else { - root.glideraToken = accessToken; - root.glideraPermissions = p; - root.update({ - fullUpdate: true - }); + glidera.token = accessToken; + glidera.permissions = p; + return cb(null, glidera); } }); } }); }; - root.update = function(opts) { - if (!root.glideraToken || !root.glideraPermissions) return; - var accessToken = root.glideraToken; - var permissions = root.glideraPermissions; - - opts = opts || {}; - - root.getStatus(accessToken, function(err, data) { - root.glideraStatus = data; - }); - - root.getLimits(accessToken, function(err, limits) { - root.glideraLimits = limits; - }); - - if (permissions.transaction_history) { - root.getTransactions(accessToken, function(err, data) { - root.glideraTxs = data; - }); - } - - if (permissions.view_email_address && opts.fullUpdate) { - root.getEmail(accessToken, function(err, data) { - root.glideraEmail = data.email; - }); - } - if (permissions.personal_info && opts.fullUpdate) { - root.getPersonalInfo(accessToken, function(err, data) { - root.glideraPersonalInfo = data; - }); - } - }; - - configService.whenAvailable(function() { - $log.debug('Init Glidera Service...'); - root.init(); - }); - - $rootScope.$on('NewBlock', function() {     - root.update();    - }); - return root; }); diff --git a/src/js/services/onGoingProcess.js b/src/js/services/onGoingProcess.js index 3738519b6..2c433a4af 100644 --- a/src/js/services/onGoingProcess.js +++ b/src/js/services/onGoingProcess.js @@ -67,7 +67,7 @@ angular.module('copayApp.services').factory('ongoingProcess', function($log, $ti window.plugins.spinnerDialog.show(null, showName, true); } else { - var tmpl = '' + showName; + var tmpl = '
    ' + showName + '
    '; $ionicLoading.show({ template: tmpl }); diff --git a/src/sass/main.scss b/src/sass/main.scss index 98f4b1235..e42fc9d34 100644 --- a/src/sass/main.scss +++ b/src/sass/main.scss @@ -1055,3 +1055,14 @@ input[type=number] { } } +/* Spinner */ + +.item-icon-left ion-spinner { + float: left; + margin-left: -3.2em; + margin-right: 1em; + margin-top: -0.2em; + height: 24px; +} + +