mirror of https://github.com/BTCPrivate/copay.git
send working with uris
This commit is contained in:
parent
80e22c59a0
commit
97c93e7909
|
@ -22,7 +22,6 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
$scope.alternativeName = w.settings.alternativeName;
|
||||
$scope.alternativeIsoCode = w.settings.alternativeIsoCode;
|
||||
|
||||
$scope.isPayUri = false;
|
||||
$scope.isRateAvailable = false;
|
||||
$scope.rateService = rateService;
|
||||
$scope.showScanner = false;
|
||||
|
@ -31,6 +30,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
|
||||
if ($rootScope.pendingPayment) {
|
||||
$scope.setFromUri($rootScope.pendingPayment)
|
||||
$rootScope.pendingPayment = null;
|
||||
}
|
||||
|
||||
$scope.setInputs();
|
||||
|
@ -49,12 +49,12 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
*
|
||||
*/
|
||||
Object.defineProperty($scope,
|
||||
"alternative", {
|
||||
"_alternative", {
|
||||
get: function() {
|
||||
return this._alternative;
|
||||
return this.__alternative;
|
||||
},
|
||||
set: function(newValue) {
|
||||
this._alternative = newValue;
|
||||
this.__alternative = newValue;
|
||||
if (typeof(newValue) === 'number' && $scope.isRateAvailable) {
|
||||
this._amount = parseFloat(
|
||||
(rateService.fromFiat(newValue, $scope.alternativeIsoCode) * satToUnit).toFixed(w.settings.unitDecimals), 10);
|
||||
|
@ -66,18 +66,18 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
configurable: true
|
||||
});
|
||||
Object.defineProperty($scope,
|
||||
"amount", {
|
||||
"_amount", {
|
||||
get: function() {
|
||||
return this._amount;
|
||||
return this.__amount;
|
||||
},
|
||||
set: function(newValue) {
|
||||
this._amount = newValue;
|
||||
this.__amount = newValue;
|
||||
if (typeof(newValue) === 'number' && $scope.isRateAvailable) {
|
||||
|
||||
this._alternative = parseFloat(
|
||||
this.__alternative = parseFloat(
|
||||
(rateService.toFiat(newValue * unitToSat, $scope.alternativeIsoCode)).toFixed(2), 10);
|
||||
} else {
|
||||
this._alternative = 0;
|
||||
this.__alternative = 0;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
|
@ -85,12 +85,12 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
});
|
||||
|
||||
Object.defineProperty($scope,
|
||||
"address", {
|
||||
"_address", {
|
||||
get: function() {
|
||||
return this._address;
|
||||
return this.__address;
|
||||
},
|
||||
set: function(newValue) {
|
||||
this._address = $scope.onAddressChange(newValue);
|
||||
this.__address = $scope.onAddressChange(newValue);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
|
@ -109,8 +109,8 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
};
|
||||
|
||||
|
||||
$scope._showError = function(err) {
|
||||
copay.logger.error(err);
|
||||
$scope.setError = function(err) {
|
||||
copay.logger.warn(err);
|
||||
|
||||
var msg = err.toString();
|
||||
if (msg.match('BIG'))
|
||||
|
@ -123,7 +123,10 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
' could not be created: ' + msg;
|
||||
|
||||
$scope.error = message;
|
||||
$scope.loading = false;
|
||||
|
||||
$timeout(function(){
|
||||
$scope.$digest();
|
||||
},1);
|
||||
};
|
||||
|
||||
$scope.submitForm = function(form) {
|
||||
|
@ -134,35 +137,23 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
|
||||
$scope.loading = true;
|
||||
|
||||
var url = $scope._url;
|
||||
var address = form.address.$modelValue;
|
||||
var amount = parseInt((form.amount.$modelValue * unitToSat).toFixed(0));
|
||||
var commentText = form.comment.$modelValue;
|
||||
|
||||
|
||||
var payInfo;
|
||||
if (address.indexOf('bitcoin:') === 0) {
|
||||
payInfo = (new bitcore.BIP21(address)).data;
|
||||
} else if (/^https?:\/\//.test(address)) {
|
||||
payInfo = {
|
||||
merchant: address
|
||||
};
|
||||
}
|
||||
var comment = form.comment.$modelValue;
|
||||
|
||||
w.spend({
|
||||
toAddress: address,
|
||||
amountSat: amount,
|
||||
comment: commentText,
|
||||
url: (payInfo && payInfo.merchant) ? payInfo.merchant : null,
|
||||
comment: comment,
|
||||
url: url,
|
||||
}, function(err, txid, status) {
|
||||
$scope.loading = false;
|
||||
// reset fields
|
||||
$scope.address = $scope.amount = $scope.commentText = null;
|
||||
form.address.$pristine = form.amount.$pristine = true;
|
||||
$rootScope.pendingPayment = null;
|
||||
$scope.isPayUri = null;
|
||||
if (err) return $scope._showError(err);
|
||||
|
||||
$scope.notifyStatus(status);
|
||||
if (err)
|
||||
return $scope.setError(err);
|
||||
|
||||
$scope.resetForm(status);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -303,7 +294,10 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
}
|
||||
|
||||
$scope.setTopAmount = function() {
|
||||
$scope.amount = $rootScope.topAmount;
|
||||
var form = $scope.sendForm;
|
||||
form.amount.$setViewValue(w.balanceInfo.topAmount);
|
||||
form.amount.$render();
|
||||
form.amount.$isValid = true;
|
||||
};
|
||||
|
||||
$scope.notifyStatus = function(status) {
|
||||
|
@ -316,7 +310,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
else if (status == copay.Wallet.TX_SIGNED_AND_BROADCASTED)
|
||||
$scope.success = 'Transaction signed and broadcasted!';
|
||||
else
|
||||
$scope.error = 'Unknown error occured';
|
||||
$scope.error = status;
|
||||
|
||||
$timeout(function() {
|
||||
$scope.$digest();
|
||||
|
@ -330,7 +324,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
$rootScope.txAlertCount = 0;
|
||||
w.issueTx(ntxid, function(err, txid, status) {
|
||||
$scope.loading = false;
|
||||
$scope.notifyStatus(status);
|
||||
$scope.resetForm(status);
|
||||
if (cb) return cb();
|
||||
});
|
||||
};
|
||||
|
@ -338,30 +332,31 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
$scope.setForm = function(to, amount, comment) {
|
||||
var form = $scope.sendForm;
|
||||
form.address.$setViewValue(to);
|
||||
form.address.$render();
|
||||
form.address.$isValid = true;
|
||||
form.address.$render();
|
||||
$scope.lockAddress = true;
|
||||
|
||||
if (amount) {
|
||||
form.amount.$setViewValue(amount);
|
||||
form.amount.$render();
|
||||
form.amount.$setViewValue(""+amount);
|
||||
form.amount.$isValid = true;
|
||||
form.amount.$render();
|
||||
$scope.lockAmount = true;
|
||||
}
|
||||
|
||||
if (comment) {
|
||||
form.commentText.$setViewValue(comment);
|
||||
form.comment.$setViewValue(comment);
|
||||
form.comment.$isValid = true;
|
||||
form.comment.$render();
|
||||
}
|
||||
};
|
||||
|
||||
$scope.cancelSend = function(error) {
|
||||
$scope.resetForm = function(status) {
|
||||
var form = $scope.sendForm;
|
||||
|
||||
if (error)
|
||||
$scope.error = error;
|
||||
|
||||
form.address.$pristine = form.amount.$pristine = true;
|
||||
$scope.fetchingURL = null;
|
||||
$scope.isPayUri = null;
|
||||
$scope.lockAddress = false;
|
||||
$scope.lockAmount = false;
|
||||
form.address.$setViewValue('');
|
||||
form.address.$render();
|
||||
form.amount.$setViewValue('');
|
||||
|
@ -369,6 +364,11 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
form.comment.$setViewValue('');
|
||||
form.comment.$render();
|
||||
form.$setPristine();
|
||||
|
||||
$scope.notifyStatus(status);
|
||||
$timeout(function(){
|
||||
$rootScope.$digest();
|
||||
},1);
|
||||
};
|
||||
|
||||
|
||||
|
@ -405,12 +405,12 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
|
||||
if (err) {
|
||||
if (err.match('TIMEOUT')) {
|
||||
$scope.cancelSend('Payment server timed out');
|
||||
$scope.resetForm('Payment server timed out');
|
||||
} else {
|
||||
$scope.cancelSend(err.toString());
|
||||
$scope.resetForm(err.toString());
|
||||
}
|
||||
} else if (merchantData && available < +merchantData.total) {
|
||||
$scope.cancelSend('Insufficient funds');
|
||||
$scope.resetForm('Insufficient funds');
|
||||
} else {
|
||||
$scope.setForm(merchantData.domain, merchantData.unitTotal)
|
||||
}
|
||||
|
@ -435,7 +435,7 @@ console.log('[send.js.430:parsed:]',addr,parsed.data); //TODO
|
|||
return $scope.setFromPayPro(parsed.data.merchant);
|
||||
|
||||
var amount = (parsed.data && parsed.data.amount) ?
|
||||
parsed.data.amount * 100000000 * satToUnit : 0;
|
||||
(parsed.data.amount * 100000000).toFixed(0) * satToUnit : 0;
|
||||
|
||||
$scope.setForm(addr, amount, parsed.data.message, true);
|
||||
return addr;
|
||||
|
@ -527,7 +527,7 @@ console.log('[send.js.430:parsed:]',addr,parsed.data); //TODO
|
|||
});
|
||||
|
||||
modalInstance.result.then(function(addr) {
|
||||
$scope.address = addr;
|
||||
$scope._address = addr;
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -32,12 +32,6 @@ angular.module('copayApp.directives')
|
|||
link: function(scope, elem, attrs, ctrl) {
|
||||
var validator = function(value) {
|
||||
|
||||
// If we're setting the domain, ignore the change.
|
||||
if ($rootScope.merchant && $rootScope.merchant.domain && value === $rootScope.merchant.domain) {
|
||||
ctrl.$setValidity('validAddress', true);
|
||||
return value;
|
||||
}
|
||||
|
||||
// Regular url
|
||||
if (/^https?:\/\//.test(value)) {
|
||||
ctrl.$setValidity('validAddress', true);
|
||||
|
@ -53,6 +47,11 @@ angular.module('copayApp.directives')
|
|||
return value;
|
||||
}
|
||||
|
||||
if (typeof value == 'undefined') {
|
||||
ctrl.$pristine = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Regular Address
|
||||
var a = new Address(value);
|
||||
ctrl.$setValidity('validAddress', a.isValid() && a.network().name === $rootScope.wallet.getNetworkName());
|
||||
|
@ -111,14 +110,11 @@ angular.module('copayApp.directives')
|
|||
var str_value = ('' + value).substring(sep_index + 1);
|
||||
if (sep_index > 0 && str_value.length > decimals) {
|
||||
ctrl.$setValidity('validAmount', false);
|
||||
scope.notValidAmount = true;
|
||||
} else {
|
||||
ctrl.$setValidity('validAmount', true);
|
||||
scope.notValidAmount = null;
|
||||
}
|
||||
} else {
|
||||
ctrl.$setValidity('validAmount', false);
|
||||
scope.notValidAmount = null;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
|
|
@ -29,27 +29,28 @@
|
|||
</span>
|
||||
</div>
|
||||
|
||||
<div ng-show="!_url">
|
||||
<div class="row collapse">
|
||||
|
||||
<label for="address" class="left">
|
||||
<span translate>To</span>
|
||||
<i class="fi-info size-12" href="#"
|
||||
data-options="disable_for_touch:true"
|
||||
tooltip-popup-delay='500'
|
||||
tooltip="{{'Enter a valid Bitcoin address. Payment Protocol URLs are also supported'|translate}}"
|
||||
tooltip-trigger="mouseenter"
|
||||
tooltip-placement="right"></i>
|
||||
<small translate ng-hide="!sendForm.address.$pristine && address">required</small>
|
||||
<span translate>To (*)</span>
|
||||
</label>
|
||||
<span translate class="has-error right size-12" ng-show="sendForm.address.$invalid && address">
|
||||
<span class="icon-input"><i class="fi-x"></i></span>
|
||||
|
||||
<span ng-hide="sendForm.address.$pristine">
|
||||
<span translate class="has-error right size-12" ng-show="sendForm.address.$invalid">
|
||||
<span class="icon-input">
|
||||
<i class="fi-x"></i>
|
||||
</span>
|
||||
Not valid
|
||||
</span>
|
||||
<small class="icon-input right" ng-show="!sendForm.address.$invalid && address"><i class="fi-check"></i></small>
|
||||
<small class="icon-input right" ng-show="!sendForm.address.$invalid">
|
||||
<i class="fi-check"></i>
|
||||
</small>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="input">
|
||||
<input type="text" id="address" name="address" ng-disabled="loading || lockAddress"
|
||||
placeholder="{{'Bitcoin address'|translate}}" ng-model="address" valid-address required>
|
||||
<input type="text" id="address" name="address" ng-disabled="loading || lockAddress" placeholder="{{'Bitcoin address'|translate}}" ng-model="_address" valid-address required>
|
||||
<i class="fi-address-book"></i>
|
||||
<div ng-hide="showScanner || disableScanner">
|
||||
<a class="postfix button black" ng-click="openScanner()"><i class="fi-camera size-24"></i></a>
|
||||
|
@ -58,46 +59,41 @@
|
|||
<a translate class="postfix button warning" ng-click="cancelScanner()"><i class="fi-x size-18"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="scanner"
|
||||
class="row"
|
||||
ng-if="showScanner"
|
||||
ng-include="'views/includes/scanner.html'">
|
||||
<div ng-show="_url">
|
||||
<div class="row collapse">
|
||||
{{_url}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="scanner" class="row" ng-if="showScanner" ng-include="'views/includes/scanner.html'">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="row" ng-init="showAlternative = false">
|
||||
<div class="large-12 medium-12 columns">
|
||||
<div class="m5b right">
|
||||
<span translate class="has-error right size-12" ng-show="sendForm.amount.$invalid &&
|
||||
!sendForm.amount.$pristine && (notValidAmount || amount)">
|
||||
<div class="m5b right" ng-hide="sendForm.amount.$pristine">
|
||||
<span translate class="has-error right size-12" ng-show="sendForm.amount.$invalid">
|
||||
<span class="icon-input"><i class="fi-x"></i></span>
|
||||
Not valid
|
||||
</span>
|
||||
<small class="icon-input right" ng-show="!sendForm.amount.$invalid &&
|
||||
!sendForm.amount.$pristine"><i class="fi-check"></i></small>
|
||||
<small class="icon-input right" ng-show="!sendForm.amount.$invalid">
|
||||
<i class="fi-check"></i>
|
||||
</small>
|
||||
</div>
|
||||
<div ng-show="!showAlternative">
|
||||
<div class="row collapse">
|
||||
|
||||
<label for="amount"><span translate>Amount
|
||||
<small translate ng-hide="!sendForm.amount.$pristine && amount">required</small>
|
||||
<label for="amount">
|
||||
<span translate>Amount (*)</span>
|
||||
</label>
|
||||
|
||||
<div class="small-9 columns">
|
||||
<div class="input">
|
||||
<input type="number" id="amount"
|
||||
ng-disabled="loading || lockAmount"
|
||||
name="amount" placeholder="{{'Amount'|translate}}" ng-model="amount"
|
||||
ng-minlength="0.00000001" ng-maxlength="10000000000" valid-amount required
|
||||
autocomplete="off">
|
||||
<input type="number" id="amount" ng-disabled="loading || lockAmount" name="amount" placeholder="{{'Amount'|translate}}" ng-minlength="0.00000001" ng-maxlength="10000000000" ng-model="_amount" valid-amount required autocomplete="off">
|
||||
<i class="icon-bitcoin"></i>
|
||||
</div>
|
||||
<a class="small input-note" title="{{'Send all funds'|translate}}"
|
||||
ng-show="topAmount && (!$root.merchant || +$root.merchant.total === 0)"
|
||||
ng-click="setTopAmount(sendForm)">
|
||||
<span translate>Use all funds</span> {{$root.wallet.settings.unitName}}
|
||||
</a>
|
||||
</div>
|
||||
<div class="small-3 columns pointer" ng-click="showAlternative = true">
|
||||
<span class="postfix">{{$root.wallet.settings.unitName}}</span>
|
||||
|
@ -106,14 +102,11 @@
|
|||
</div>
|
||||
<div ng-show="showAlternative">
|
||||
<div class="row collapse">
|
||||
<label for="alternative"><span translate>Amount in</span> {{ alternativeName }}
|
||||
<small translate ng-hide="!sendForm.amount.$pristine && amount">required</small>
|
||||
<label for="alternative"><span translate>Amount in</span> {{ alternativeName }} (*)
|
||||
</label>
|
||||
<div class="small-9 columns">
|
||||
<div class="input">
|
||||
<input type="number" id="alternative"
|
||||
ng-disabled="loading || !isRateAvailable || lockAmount"
|
||||
name="alternative" placeholder="{{'Amount'|translate}}" ng-model="alternative" requiredautocomplete="off">
|
||||
<input type="number" id="alternative" ng-disabled="loading || !isRateAvailable || lockAmount" name="alternative" placeholder="{{'Amount'|translate}}" ng-model="_alternative" requiredautocomplete="off">
|
||||
<i class="icon-usd"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -140,18 +133,17 @@
|
|||
<p>
|
||||
<span ng-show="!!$root.merchant.pr.ca"><i class="fi-lock green"></i> {{$root.merchant.pr.ca}}</span>
|
||||
<span ng-show="!$root.merchant.pr.ca"><i class="fi-unlock red"></i> Untrusted</span>
|
||||
|
||||
{{$root.merchant.pr.pd.memo || address}}
|
||||
{{$root.merchant.pr.pd.memo || address}} TODO ADDRESS
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<p>TODO AMOUNT
|
||||
<i>{{amount}} {{$root.wallet.settings.unitName}}</i>
|
||||
<span class="text-gray" ng-if="isRateAvailable">
|
||||
TODO ALT
|
||||
{{ alternative }} {{ alternativeIsoCode }}
|
||||
</span>
|
||||
<p ng-show="!!$root.merchant">
|
||||
Expires {{$root.merchant.expiration | amTimeAgo }}
|
||||
[{{$root.merchant.domain}}]
|
||||
Expires {{$root.merchant.expiration | amTimeAgo }} [{{$root.merchant.domain}}]
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -164,8 +156,7 @@
|
|||
<small translate class="has-error" ng-show="sendForm.comment.$invalid && !sendForm.comment.$pristine">too long!</small>
|
||||
</label>
|
||||
<div class="input">
|
||||
<textarea id="comment" ng-disabled="loading"
|
||||
name="comment" placeholder="{{($root.wallet.isShared() ? 'Leave a private message to your copayers' : 'Add a private comment to identify the transaction')}}" ng-model="commentText" ng-maxlength="100"></textarea>
|
||||
<textarea id="comment" ng-disabled="loading" name="comment" placeholder="{{($root.wallet.isShared() ? 'Leave a private message to your copayers' : 'Add a private comment to identify the transaction')}}" ng-maxlength="100" ng-model="_comment"></textarea>
|
||||
<i class="icon-compose"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -176,26 +167,25 @@
|
|||
<a class="button tiny secondary m0" title="Address book" ng-hide="!!$root.merchant || lockAddress" ng-click="openAddressBook()">
|
||||
<i class="fi-address-book"></i> Address book
|
||||
</a>
|
||||
<a ng-click="cancelSend(sendForm)" class="button warning m0" ng-show="!!$root.merchant || lockAddress">
|
||||
<a ng-click="resetForm()" class="button warning m0" ng-show="!!$root.merchant || lockAddress" ng-disabled="loading">
|
||||
Cancel
|
||||
</a>
|
||||
</div>
|
||||
<div class="large-6 medium-6 small-6 columns text-right">
|
||||
<button type="submit" class="button primary m0" ng-disabled="sendForm.$invalid || loading">
|
||||
<i class="fi-bitcoin-circle icon-rotate spinner" ng-show="loading"></i>
|
||||
Send
|
||||
<i class="fi-bitcoin-circle icon-rotate spinner" ng-show="loading"></i> Send
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div><!-- end of row -->
|
||||
</div>
|
||||
<!-- end of row -->
|
||||
|
||||
<div class="row m20b" ng-show="$root.wallet.balanceInfo.alternativeConversionRate > 0">
|
||||
<div class="large-12 columns size-12">
|
||||
<i class="fi-bitcoin-circle"></i>
|
||||
1 BTC = {{$root.wallet.balanceInfo.alternativeConversionRate}} {{alternativeIsoCode}}
|
||||
<i class="fi-bitcoin-circle"></i> 1 BTC = {{$root.wallet.balanceInfo.alternativeConversionRate}} {{alternativeIsoCode}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue