Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #44 from ArkEcosystem/feature-bug-fixes
Browse files Browse the repository at this point in the history
Feature bug fixes
  • Loading branch information
Doweig authored Mar 4, 2017
2 parents 1a869da + 28e7fd8 commit e10740f
Show file tree
Hide file tree
Showing 29 changed files with 3,206 additions and 1,096 deletions.
61 changes: 45 additions & 16 deletions client/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ <h2 translate>
<tr md-row md-select="transaction" md-select-id="id" md-auto-select ng-repeat="it in ul.selected.transactions | orderBy: query.order">
<td md-cell>{{it.date | date: 'short'}}</td>
<td md-cell>{{it.label}}</td>
<td ng-if="it.total>=0" md-cell><md-button ng-click="ul.openExplorer('/tx/'+it.id)" md-colors="{'background' : 'green-200' }">+{{(it.total/100000000).toFixed(2)}}</md-button></td>
<td ng-if="it.total<0" md-cell><md-button ng-click="ul.openExplorer('/tx/'+it.id)" md-colors="{'background' : 'red-200' }">{{(it.total/100000000).toFixed(2)}}</md-button></td>
<td ng-if="it.total>=0" md-cell><md-button ng-click="ul.openExplorer('/tx/'+it.id)" md-colors="{'background' : 'green-200' }">+{{it.humanTotal}}</md-button></td>
<td ng-if="it.total<0" md-cell><md-button ng-click="ul.openExplorer('/tx/'+it.id)" md-colors="{'background' : 'red-200' }">{{it.humanTotal}}</md-button></td>
<td md-cell>{{it.vendorField}}</td>
<td md-cell><a href="" ng-click="ul.gotoAddress(it.senderId)">{{it.senderId | accountlabel}}</a></td>
<td md-cell><a href="" ng-click="ul.gotoAddress(it.recipientId)">{{it.recipientId | accountlabel}}</a></td>
Expand Down Expand Up @@ -738,20 +738,49 @@ <h1>{{ul.selected.delegate.username}}</h1>
$qProvider.errorOnUnhandledRejections(false);
}]);

const {remote} = require('electron');
const {Menu, MenuItem} = remote;

const menu = new Menu();
menu.append(new MenuItem({label: 'Select All', accelerator: "CmdOrCtrl+A", selector: 'selectAll:' }));
menu.append(new MenuItem({label: 'Copy', accelerator: "CmdOrCtrl+C", selector: "copy:" }));
menu.append(new MenuItem({label: 'Paste', accelerator: "CmdOrCtrl+V", selector: "paste:"}));



window.addEventListener('contextmenu', (e) => {
e.preventDefault();
menu.popup(remote.getCurrentWindow());
}, false);
const electron = require('electron');
const remote = electron.remote;
const Menu = remote.Menu;

const InputMenu = Menu.buildFromTemplate([{
label: 'Undo',
role: 'undo',
}, {
label: 'Redo',
role: 'redo',
}, {
type: 'separator',
}, {
label: 'Cut',
role: 'cut',
}, {
label: 'Copy',
role: 'copy',
}, {
label: 'Paste',
role: 'paste',
}, {
type: 'separator',
}, {
label: 'Select all',
role: 'selectall',
},
]);

document.body.addEventListener('contextmenu', (e) => {
e.preventDefault();
e.stopPropagation();

let node = e.target;

while (node) {
if (node.nodeName.match(/^(input|textarea)$/i) || node.isContentEditable) {
InputMenu.popup(remote.getCurrentWindow());
break;
}
node = node.parentNode;
}
});

</script>

Expand Down
46 changes: 34 additions & 12 deletions client/app/src/accounts/AccountController.js
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@
$mdDialog.show({
parent : angular.element(document.getElementById('app')),
templateUrl : './src/accounts/view/addDelegate.html',
clickOutsideToClose: true,
clickOutsideToClose: false,
preserveScope: true,
scope: $scope
});
Expand Down Expand Up @@ -849,7 +849,7 @@
$mdDialog.show({
parent : angular.element(document.getElementById('app')),
templateUrl : './src/accounts/view/vote.html',
clickOutsideToClose: true,
clickOutsideToClose: false,
preserveScope: true,
scope: $scope
});
Expand Down Expand Up @@ -949,7 +949,7 @@
$mdDialog.show({
parent : angular.element(document.getElementById('app')),
templateUrl : './src/accounts/view/manageNetwork.html',
clickOutsideToClose: true,
clickOutsideToClose: false,
preserveScope: true,
scope: $scope,
fullscreen: true
Expand Down Expand Up @@ -989,7 +989,7 @@
$mdDialog.show({
parent : angular.element(document.getElementById('app')),
templateUrl : './src/accounts/view/savePassphrases.html',
clickOutsideToClose: true,
clickOutsideToClose: false,
preserveScope: true,
scope: $scope
});
Expand All @@ -1002,10 +1002,18 @@

function next() {
$mdDialog.hide();

var delegateName;
try {
delegateName = accountService.sanitizeDelegateName($scope.createDelegate.data.username)
} catch (error) {
return formatAndToastError(error)
}

accountService.createTransaction(2,
{
fromAddress: $scope.createDelegate.data.fromAddress,
username: $scope.createDelegate.data.username,
username: delegateName,
masterpassphrase: $scope.createDelegate.data.passphrase,
secondpassphrase: $scope.createDelegate.data.secondpassphrase
}
Expand All @@ -1030,7 +1038,7 @@
$mdDialog.show({
parent : angular.element(document.getElementById('app')),
templateUrl : './src/accounts/view/createDelegate.html',
clickOutsideToClose: true,
clickOutsideToClose: false,
preserveScope: true,
scope: $scope
});
Expand Down Expand Up @@ -1087,7 +1095,7 @@
$mdDialog.show({
parent : angular.element(document.getElementById('app')),
templateUrl : './src/accounts/view/createAccount.html',
clickOutsideToClose: true,
clickOutsideToClose: false,
preserveScope: true,
scope: $scope
});
Expand All @@ -1104,10 +1112,22 @@
accountService.createAccount($scope.send.data.passphrase)
.then(
function(account){
// Check for already imported account
for (var i = 0; i < self.accounts.length; i++) {
if (self.accounts[i].publicKey === account.publicKey) {
$mdToast.show(
$mdToast.simple()
.textContent(gettextCatalog.getString('Account was already imported: ') + account.address)
.hideDelay(5000)
);
return selectAccount(account);
}
}

self.accounts.push(account);
$mdToast.show(
$mdToast.simple()
.textContent(gettextCatalog.getString('Account successfully created: ') + account.address)
.textContent(gettextCatalog.getString('Account successfully imported: ') + account.address)
.hideDelay(5000)
);
selectAccount(account);
Expand All @@ -1131,7 +1151,7 @@
$mdDialog.show({
parent : angular.element(document.getElementById('app')),
templateUrl : './src/accounts/view/importAccount.html',
clickOutsideToClose: true,
clickOutsideToClose: false,
preserveScope: true,
scope: $scope
});
Expand Down Expand Up @@ -1212,7 +1232,7 @@
$mdBottomSheet.show({
parent : angular.element(document.getElementById('app')),
templateUrl : './src/accounts/view/contactSheet.html',
clickOutsideToClose: true,
clickOutsideToClose: false,
preserveScope: true,
scope: $scope
});
Expand Down Expand Up @@ -1243,15 +1263,17 @@
$scope.validate={
send:send,
cancel:cancel,
transaction:transaction
transaction:transaction,
// to avoid small transaction to be displayed as 1e-8
humanAmount: accountService.numberToFixed(transaction.amount / 100000000) + '',
};

$mdDialog.show({
scope : $scope,
preserveScope : true,
parent : angular.element(document.getElementById('app')),
templateUrl : './src/accounts/view/showTransaction.html',
clickOutsideToClose: true
clickOutsideToClose: false
});
};

Expand Down
49 changes: 48 additions & 1 deletion client/app/src/accounts/AccountService.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@
if(transaction.senderId==address){
transaction.total=-transaction.amount-transaction.fee;
}
// to avoid small transaction to be displayed as 1e-8
transaction.humanTotal = numberToFixed(transaction.total / 100000000) + ''
}
storageService.set("transactions-"+address,resp.transactions);
deferred.resolve(resp.transactions);
Expand Down Expand Up @@ -559,6 +561,47 @@
return virtual;
}

var allowedDelegateNameChars = /^[a-z0-9!@$&_.]+$/g;
function sanitizeDelegateName(delegateName){
if (!delegateName) {
throw new Error('Delegate name is undefined');
}
if (delegateName !== delegateName.toLowerCase()) {
throw new Error('Delegate name must be lowercase');
}

var sanitizedName = String(delegateName).toLowerCase().trim();
if (sanitizedName === '') {
throw new Error('Empty delegate name');
}
if (sanitizedName.length > 20) {
throw new Error('Delegate name is too long, 20 characters maximum');
}
if (!allowedDelegateNameChars.test(sanitizedName)) {
throw new Error('Delegate name can only contain alphanumeric characters with the exception of !@$&_.');
}

return sanitizedName;
}

function numberToFixed(x) {
if (Math.abs(x) < 1.0) {
var e = parseInt(x.toString().split('e-')[1]);
if (e) {
x *= Math.pow(10,e-1);
x = '0.' + (new Array(e)).join('0') + x.toString().substring(2);
}
} else {
var e = parseInt(x.toString().split('+')[1]);
if (e > 20) {
e -= 20;
x /= Math.pow(10,e);
x += (new Array(e+1)).join('0');
}
}
return x;
}


return {
loadAllAccounts : function() {
Expand Down Expand Up @@ -636,7 +679,11 @@

setToFolder: setToFolder,

deleteFolder: deleteFolder
deleteFolder: deleteFolder,

sanitizeDelegateName: sanitizeDelegateName,

numberToFixed: numberToFixed,
}
}

Expand Down
4 changes: 2 additions & 2 deletions client/app/src/accounts/view/createDelegate.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<form>
<md-toolbar>
<div class="md-toolbar-tools">
<h2><span translate>Register delegate for</span>&nbsp;{{send.data.fromAddress}}</h2>
<h2><span translate>Register delegate for</span>&nbsp;{{createDelegate.data.fromAddress}}</h2>
</div>
</md-toolbar>
<md-dialog-content>
Expand All @@ -15,7 +15,7 @@ <h2><span translate>Register delegate for</span>&nbsp;{{send.data.fromAddress}}<
<label translate>Passphrase</label>
<input ng-model="createDelegate.data.passphrase" type="password" ng-required="true">
</md-input-container>
<md-input-container class="md-block" ng-if="send.data.secondSignature">
<md-input-container class="md-block" ng-if="createDelegate.data.secondSignature">
<label translate>Second Passphrase</label>
<input ng-model="createDelegate.data.secondpassphrase" type="password" ng-required="true">
</md-input-container>
Expand Down
2 changes: 1 addition & 1 deletion client/app/src/accounts/view/showTransaction.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h2><span translate>Transaction</span> {{validate.transaction.id}}</h2>
<b translate>Username</b> <span class="md-secondary">{{validate.transaction.username}}</span>
</md-list-item>
<md-list-item ng-if="validate.transaction.amount">
<b translate>Amount (Ѧ)</b> <span class="md-secondary">{{validate.transaction.amount/100000000}}</span>
<b translate>Amount (Ѧ)</b> <span class="md-secondary">{{validate.humanAmount}}</span>
</md-list-item>
<md-list-item>
<b translate>Fee (Ѧ)</b> <span class="md-secondary">{{validate.transaction.fee/100000000}}</span>
Expand Down
Loading

0 comments on commit e10740f

Please sign in to comment.