diff --git a/.gitignore b/.gitignore index d38e98b2c..0445455f1 100644 --- a/.gitignore +++ b/.gitignore @@ -54,6 +54,13 @@ android/package android/*.apk android/*.keystore +mobile/*.keystore +mobile/assets/www +mobile/bin/* +mobile/gen/* +mobile/cordova/* +mobile/CordovaLib/* + coverage/ shell/bin/linux diff --git a/index.html b/index.html index b4cd4c1df..3abe358a7 100644 --- a/index.html +++ b/index.html @@ -692,6 +692,9 @@ +
+ +
@@ -1028,6 +1031,15 @@ on supported browsers please check http://www.w + + + diff --git a/js/controllers/send.js b/js/controllers/send.js index e9f3d92ec..d028d34c0 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -32,6 +32,7 @@ angular.module('copayApp.controllers').controller('SendController', // Detect protocol $scope.isHttp = ($window.location.protocol.indexOf('http') === 0); + $scope.isCordova = typeof(window.cordova) != 'undefined'; navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL; @@ -194,6 +195,25 @@ angular.module('copayApp.controllers').controller('SendController', }, 500); }; + $scope.scannerIntent = function() { + cordova.plugins.barcodeScanner.scan( + function onSuccess(result) { + if (result.cancelled) return; + + var bip21 = copay.Structure.parseBitcoinURI(result.text); + $scope.address = bip21.address; + + if (bip21.amount) { + $scope.amount = bip21.amount * bitcore.util.COIN * satToUnit; + } + + $rootScope.$digest(); + }, + function onError(error) { + alert('Scanning error'); + }); + } + $scope.toggleAddressBookEntry = function(key) { var w = $rootScope.wallet; w.toggleAddressBookEntry(key); diff --git a/js/models/core/Structure.js b/js/models/core/Structure.js index ff47c43f0..54b51e4da 100644 --- a/js/models/core/Structure.js +++ b/js/models/core/Structure.js @@ -59,13 +59,16 @@ Structure.parseBitcoinURI = function(uri) { data = splitDots[1]; var splitQuestion = data.split('?'); ret.address = splitQuestion[0]; - var search = splitQuestion[1]; - data = JSON.parse('{"' + search.replace(/&/g, '","').replace(/=/g, '":"') + '"}', - function(key, value) { - return key === "" ? value : decodeURIComponent(value); - }); - ret.amount = parseFloat(data.amount); - ret.message = data.message; + + if (splitQuestion.length > 1) { + var search = splitQuestion[1]; + data = JSON.parse('{"' + search.replace(/&/g, '","').replace(/=/g, '":"') + '"}', + function(key, value) { + return key === "" ? value : decodeURIComponent(value); + }); + ret.amount = parseFloat(data.amount); + ret.message = data.message; + } return ret; }; diff --git a/js/services/backupService.js b/js/services/backupService.js index 41fbe559f..dc915d632 100644 --- a/js/services/backupService.js +++ b/js/services/backupService.js @@ -30,13 +30,14 @@ BackupService.prototype.download = function(wallet) { } // throw an email intent if we are in the mobile version - if (window.xwalk) { + if (window.cordova) { var name = wallet.name ? wallet.name + ' ' : ''; var partial = partial ? 'Partial ' : ''; - var subject = 'Copay - ' + name + 'Wallet ' + partial + 'Backup'; - var body = 'This is the encrypted backup of the wallet ' + wallet.id + ':\n\n' + ew; - var mailURL = encodeURI('mailto:?subject=' + subject + '&body=' + body); - return window.open(mailURL,'_blank'); + return window.plugin.email.open({ + subject: 'Copay - ' + name + 'Wallet ' + partial + 'Backup', + body: 'Here is the encrypted backup of the wallet ' + wallet.id, + attachments: ['base64:' + filename + '//' + btoa(ew)] + }); } // otherwise lean on the browser implementation diff --git a/mobile/AndroidManifest.xml b/mobile/AndroidManifest.xml new file mode 100644 index 000000000..07a55c1bb --- /dev/null +++ b/mobile/AndroidManifest.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mobile/build.sh b/mobile/build.sh new file mode 100644 index 000000000..50ece436a --- /dev/null +++ b/mobile/build.sh @@ -0,0 +1,76 @@ +#! /bin/bash + +# Description: This script compiles and copy the needed files to later package the application for Android + +OpenColor="\033[" +Red="1;31m" +Yellow="1;33m" +Green="1;32m" +CloseColor="\033[0m" + +# Check function OK +checkOK() { + if [ $? != 0 ]; then + echo "${OpenColor}${Red}* ERROR. Exiting...${CloseColor}" + exit 1 + fi +} + +# Configs +BUILDDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +APPDIR="$BUILDDIR/assets/www" +VERSION=`cut -d '"' -f2 $BUILDDIR/../version.js` +RELEASE=false +RUN=false + +if [[ $1 = "--release" ]] +then + RELEASE=true +fi + +if [[ $1 = "-r" ]] +then + RUN=true +fi + +# Move to the build directory +cd $BUILDDIR + +[ -z "$CROSSWALK" ] && { echo "${OpenColor}${Red}* Need to set CROSSWALK environment variable${CloseColor}"; exit 1; } + +# Create/Clean temp dir +echo "${OpenColor}${Green}* Checking temp dir...${CloseColor}" +if [ -d $APPDIR ]; then + rm -rf $APPDIR +fi + +mkdir -p $APPDIR + +# Re-compile copayBundle.js +echo "${OpenColor}${Green}* Generating copay bundle...${CloseColor}" +grunt --target=dev shell +checkOK + +# Copy all app files +echo "${OpenColor}${Green}* Copying all app files...${CloseColor}" +cd $BUILDDIR/.. +cp -af {css,font,img,js,lib,sound,config.js,version.js,$BUILDDIR/cordova.js,$BUILDDIR/cordova_plugins.js,$BUILDDIR/plugins} $APPDIR +checkOK +sed "s/<\!-- PLACEHOLDER: CORDOVA SRIPT -->/