diff --git a/Gruntfile.js b/Gruntfile.js index 6b634eda6..7876a5ddb 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -138,7 +138,8 @@ module.exports = function(grunt) { 'bower_components/angular-mocks/angular-mocks.js', 'bower_components/ngtouch/src/ngTouch.js', 'angular-bitauth/angular-bitauth.js', - 'angular-bitcore-wallet-client/angular-bitcore-wallet-client.js' + 'angular-bitcore-wallet-client/angular-bitcore-wallet-client.js', + 'bitcoin-cash-js/bitcoin-cash-js.js' ], dest: 'www/lib/angular-components.js' }, @@ -255,7 +256,8 @@ module.exports = function(grunt) { dist: { files: { 'angular-bitcore-wallet-client/angular-bitcore-wallet-client.js': ['angular-bitcore-wallet-client/index.js'], - 'angular-bitauth/angular-bitauth.js': ['angular-bitauth/index.js'] + 'angular-bitauth/angular-bitauth.js': ['angular-bitauth/index.js'], + 'bitcoin-cash-js/bitcoin-cash-js.js': ['bitcoin-cash-js/index.js'] }, } } diff --git a/app-template/package-template.json b/app-template/package-template.json index 12955d785..3c92fdbbd 100644 --- a/app-template/package-template.json +++ b/app-template/package-template.json @@ -77,7 +77,8 @@ "grunt-sass": "^1.2.0", "load-grunt-tasks": "^3.5.0", "shelljs": "^0.3.0", - "android-versions": "^1.2.1" + "android-versions": "^1.2.1", + "bitcoincashjs": "^0.1.7" }, "scripts": { "postinstall": "bower install", diff --git a/bitcoin-cash-js/index.js b/bitcoin-cash-js/index.js new file mode 100644 index 000000000..faf6d510d --- /dev/null +++ b/bitcoin-cash-js/index.js @@ -0,0 +1,28 @@ +var bitcoinCashJsModule = angular.module('bitcoinCashJsModule', []); +var bchjs = require('../node_modules/bitcoincashjs'); + +bitcoinCashJsModule.constant('MODULE_VERSION', '1.0.0'); + +bitcoinCashJsModule.provider('bitcoinCashJsService', function() { + var provider = {}; + + provider.$get = function() { + var service = {}; + + service.translateAddresses = function(address) { + const Address = bchjs.Address; + const BitpayFormat = Address.BitpayFormat; + const CashAddrFormat = Address.CashAddrFormat; + var result = new Address(address); + return { + 'legacy': result.toString(), + 'bitpay': result.toString(BitpayFormat), + 'cashaddr': result.toString(CashAddrFormat) + }; + } + + return service; + } + + return provider; +}); diff --git a/src/js/app.js b/src/js/app.js index 784745fdd..2c0dcc993 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -13,6 +13,7 @@ var modules = [ 'angular-md5', 'bwcModule', 'bitauthModule', + 'bitcoinCashJsModule', 'copayApp.filters', 'copayApp.services', 'copayApp.controllers',