Skip to content

Fixed translations and Blackbytes QR code #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/views/correspondentDevice.html
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ <h1 class="title ellipsis" ng-style="{'color': noColor ? '#4A90E2' : index.backg
</div>
<div class="large-4 medium-4 small-4 columns adaptive">
<button type="button"
class="button expand round outline dark-gray tiny"
class="button expand translate round outline dark-gray tiny"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe outside the class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

ng-click="requestPayment()">Request payment</button>
</div>
<div class="large-4 medium-4 small-4 columns adaptive">
Expand Down
4 changes: 2 additions & 2 deletions public/views/modals/customized-amount.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ <h1 class="title ellipsis" ng-style="{'color':color}" translate>
<h4 class="title m0" translate>QR Code</h4>
<ul class="no-bullet size-14 m0">
<li class="line-b p10 oh text-center">
<qrcode size="220" version="6" data="{{protocol}}:{{addr + '?amount=' + amountInSmallestUnits + asset_param}}"></qrcode>
<qrcode size="220" version="{{qr_version}}" data="{{protocol}}:{{code}}"></qrcode>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I din't find where code is set

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its in wallethome.js @ line 446

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wallethome.js is not even in the diff

<div class="m10t text-center" ng-show="isCordova">
<span class="button outline dark-gray tiny round"
ng-click="shareAddress('{{protocol}}:' + addr + '?amount=' + amountInSmallestUnits + asset_param)">
ng-click="shareAddress('{{protocol}}:{{code}}')">
<i class="fi-share"></i>
<span translate>Share address</span>
</span>
Expand Down
14 changes: 7 additions & 7 deletions src/js/controllers/correspondentDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ angular.module('copayApp.controllers').controller('correspondentDeviceController
$scope.color = fc.backgroundColor;
$scope.bWorking = false;
$scope.arrRelations = ["=", ">", "<", ">=", "<=", "!="];
$scope.arrParties = [{value: 'me', display_value: "I"}, {value: 'peer', display_value: "the peer"}];
$scope.arrPeerPaysTos = [{value: 'me', display_value: "to me"}, {value: 'contract', display_value: "to this contract"}];
$scope.arrParties = [{value: 'me', display_value: gettext("I")}, {value: 'peer', display_value: gettext("the peer")}];
$scope.arrPeerPaysTos = [{value: 'me', display_value: gettext("to me")}, {value: 'contract', display_value: gettext("to this contract")}];
$scope.arrAssetInfos = indexScope.arrBalances.map(function(b){
var info = {asset: b.asset, is_private: b.is_private};
if (b.asset === 'base')
Expand All @@ -190,7 +190,7 @@ angular.module('copayApp.controllers').controller('correspondentDeviceController
else if (profileService.assetMetadata[b.asset])
info.displayName = profileService.assetMetadata[b.asset].name;
else
info.displayName = 'of '+b.asset.substr(0, 4);
info.displayName = gettext('of')+' '+b.asset.substr(0, 4);
return info;
});
$scope.arrPublicAssetInfos = $scope.arrAssetInfos.filter(function(b){ return !b.is_private; });
Expand Down Expand Up @@ -262,13 +262,13 @@ angular.module('copayApp.controllers').controller('correspondentDeviceController
if (contract.peerAsset === "base")
peer_amount *= walletSettings.unitValue;
if (contract.peerAsset === constants.BLACKBYTES_ASSET)
throw Error("peer asset cannot be blackbytes");
throw Error(gettext("peer asset cannot be blackbytes"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to translate exceptions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

if (profileService.assetMetadata[contract.peerAsset])
peer_amount *= Math.pow(10, profileService.assetMetadata[contract.peerAsset].decimals || 0);
peer_amount = Math.round(peer_amount);

if (my_amount === peer_amount && contract.myAsset === contract.peerAsset && contract.peer_pays_to === 'contract'){
$scope.error = "The amounts are equal, you cannot require the peer to pay to the contract. Please either change the amounts slightly or fund the entire contract yourself and require the peer to pay his half to you.";
$scope.error = gettext("The amounts are equal, you cannot require the peer to pay to the contract. Please either change the amounts slightly or fund the entire contract yourself and require the peer to pay his half to you.");
$timeout(function() {
$scope.$digest();
}, 1);
Expand Down Expand Up @@ -376,9 +376,9 @@ angular.module('copayApp.controllers').controller('correspondentDeviceController
profileService.bKeepUnlocked = false;
if (err){
if (err.match(/device address/))
err = "This is a private asset, please send it only by clicking links from chat";
err = gettext("This is a private asset, please send it only by clicking links from chat");
if (err.match(/no funded/))
err = "Not enough spendable funds, make sure all your funds are confirmed";
err = gettext("Not enough spendable funds, make sure all your funds are confirmed");
if ($scope)
$scope.error = err;
return;
Expand Down
21 changes: 3 additions & 18 deletions src/js/controllers/inviteCorrespondentDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

var eventBus = require('byteballcore/event_bus.js');



angular.module('copayApp.controllers').controller('inviteCorrespondentDeviceController',
function($scope, $timeout, profileService, go, isCordova, correspondentListService, gettextCatalog) {

Expand Down Expand Up @@ -42,25 +44,8 @@ angular.module('copayApp.controllers').controller('inviteCorrespondentDeviceCont
correspondentListService.startWaitingForPairing(function(pairingInfo){
console.log("beginAddCorrespondent " + pairingInfo.pairing_secret);
$scope.code = pairingInfo.device_pubkey + "@" + pairingInfo.hub + "#" + pairingInfo.pairing_secret;

function determineQRcodeVersionFromString( inputtext ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what was the point of moving the function to the service?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the function is now used in both wallethome.js and invitecorrespondentDevice.js

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wallethome.js is not included in the diff

// maximum characters per QR code version using ECC level m
// source: http://www.qrcode.com/en/about/version.html
var maxCharsforQRVersion = [0,14,26,42,62,84,106,122,152,180,213];
var qrversion = 5;
// find lowest version number that has enough space for our text
for (var i = (maxCharsforQRVersion.length-1); i > 0 ; i--) {
if ( maxCharsforQRVersion[i] >= inputtext.length)
{
qrversion = i;
}
}

return qrversion;
}

var qrstring = $scope.protocol + ":" +$scope.code; //as passed to the qr generator in inviteCorrespondentDevice.html
$scope.qr_version = determineQRcodeVersionFromString( qrstring );
$scope.qr_version = correspondentListService.determineQRcodeVersionFromString( qrstring );

$scope.$digest();
//$timeout(function(){$scope.$digest();}, 100);
Expand Down
26 changes: 21 additions & 5 deletions src/js/services/correspondentListService.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var eventBus = require('byteballcore/event_bus.js');
var ValidationUtils = require('byteballcore/validation_utils.js');
var objectHash = require('byteballcore/object_hash.js');

angular.module('copayApp.services').factory('correspondentListService', function($state, $rootScope, $sce, $compile, configService, storageService, profileService, go, lodash, $stickyState, $deepStateRedirect, $timeout, gettext) {
angular.module('copayApp.services').factory('correspondentListService', function($state, $rootScope, $sce, $compile, configService, storageService, profileService, go, lodash, $stickyState, $deepStateRedirect, $timeout, gettext, gettextCatalog) {
var root = {};
var device = require('byteballcore/device.js');
var wallet = require('byteballcore/wallet.js');
Expand Down Expand Up @@ -35,6 +35,21 @@ angular.module('copayApp.services').factory('correspondentListService', function
$rootScope.totalNewMsgCnt = lodash.sum(lodash.values(counters));
}, true);

function determineQRcodeVersionFromString( inputtext ) {
// maximum characters per QR code version using ECC level m
// source: http://www.qrcode.com/en/about/version.html
var maxCharsforQRVersion = [0,14,26,42,62,84,106,122,152,180,213];
var qrversion = 5;
// find lowest version number that has enough space for our text
for (var i = (maxCharsforQRVersion.length-1); i > 0 ; i--) {
if ( maxCharsforQRVersion[i] >= inputtext.length)
{
qrversion = i;
}
}
return qrversion;
}

function addIncomingMessageEvent(from_address, body, message_counter){
var walletGeneral = require('byteballcore/wallet_general.js');
walletGeneral.readMyAddresses(function(arrMyAddresses){
Expand Down Expand Up @@ -107,7 +122,7 @@ angular.module('copayApp.services').factory('correspondentListService', function
// if (arrMyAddresses.indexOf(address) >= 0)
// return address;
//return '<a send-payment address="'+address+'">'+address+'</a>';
return '<a dropdown-toggle="#pop'+address+'">'+address+'</a><ul id="pop'+address+'" class="f-dropdown" style="left:0px" data-dropdown-content><li><a ng-click="sendPayment(\''+address+'\')">'+gettext('Pay to this address')+'</a></li><li><a ng-click="offerContract(\''+address+'\')">'+gettext('Offer a contract')+'</a></li></ul>';
return '<a dropdown-toggle="#pop'+address+'">'+address+'</a><ul id="pop'+address+'" class="f-dropdown" style="left:0px" data-dropdown-content><li><a ng-click="sendPayment(\''+address+'\')">'+gettextCatalog.getString('Pay to this address')+'</a></li><li><a ng-click="offerContract(\''+address+'\')">'+gettextCatalog.getString('Offer a contract')+'</a></li></ul>';
// return '<a ng-click="sendPayment(\''+address+'\')">'+address+'</a>';
//return '<a send-payment ng-click="sendPayment(\''+address+'\')">'+address+'</a>';
//return '<a send-payment ng-click="console.log(\''+address+'\')">'+address+'</a>';
Expand All @@ -127,7 +142,7 @@ angular.module('copayApp.services').factory('correspondentListService', function
var arrMovements = getMovementsFromJsonBase64PaymentRequest(paymentJsonBase64, true);
if (!arrMovements)
return '[invalid payment request]';
description = 'Payment request: '+arrMovements.join(', ');
description = gettext('Payment request:')+' '+arrMovements.join(', ');
return '<a ng-click="sendMultiPayment(\''+paymentJsonBase64+'\')">'+description+'</a>';
}).replace(/\[(.+?)\]\(vote:(.+?)\)/g, function(str, description, voteJsonBase64){
var objVote = getVoteFromJsonBase64(voteJsonBase64);
Expand Down Expand Up @@ -245,7 +260,7 @@ angular.module('copayApp.services').factory('correspondentListService', function
var arrMovements = getMovementsFromJsonBase64PaymentRequest(paymentJsonBase64);
if (!arrMovements)
return '[invalid payment request]';
return '<i>Payment request: '+arrMovements.join(', ')+'</i>';
return '<i>'+gettext('Payment request:')+' '+arrMovements.join(', ')+'</i>';
}).replace(/\[(.+?)\]\(vote:(.+?)\)/g, function(str, description, voteJsonBase64){
var objVote = getVoteFromJsonBase64(voteJsonBase64);
if (!objVote)
Expand Down Expand Up @@ -282,7 +297,7 @@ angular.module('copayApp.services').factory('correspondentListService', function
var device_address = assocParams['device_address'] || '';
if (device_address && !ValidationUtils.isValidDeviceAddress(device_address))
return null;
var amountStr = 'Payment request: ' + getAmountText(amount, asset);
var amountStr = gettext('Payment request:')+' ' + getAmountText(amount, asset);
return {
amount: amount,
asset: asset,
Expand Down Expand Up @@ -609,6 +624,7 @@ angular.module('copayApp.services').factory('correspondentListService', function
root.parseMessage = parseMessage;
root.escapeHtmlAndInsertBr = escapeHtmlAndInsertBr;
root.addMessageEvent = addMessageEvent;
root.determineQRcodeVersionFromString = determineQRcodeVersionFromString;

root.list = function(cb) {
device.readCorrespondents(function(arrCorrespondents){
Expand Down