Skip to content

Commit

Permalink
custom token management fix, more API
Browse files Browse the repository at this point in the history
  • Loading branch information
inzhoop committed Oct 28, 2017
1 parent ec163a0 commit 0c17778
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 17 deletions.
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.inzhoop.leth" version="0.26.9" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<widget id="com.inzhoop.leth" version="0.26.10" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>LΞTH</name>
<description>
The first Ethereum mobile wallet.
Expand Down
9 changes: 7 additions & 2 deletions www/js/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
web3 = new Web3();
hdPath = "m/44'/60'/0";
hdPath2 = "m/44'/60'/0'/0";
StorePath = 'https://www.inzhoop.com/repository';
//StorePath = 'https://www.inzhoop.com/repository';
StorePath = 'http://127.0.0.1:8887';


var app = angular.module('leth', [
'ionic', 'nfcFilters', 'ngTagsInput', 'angularLoad',
Expand Down Expand Up @@ -83,6 +85,10 @@ var app = angular.module('leth', [
}
}

//clean
localStorage.removeItem("Coins");
localStorage.removeItem("listTokens");

if (typeof localStorage.Shh == 'undefined') {localStorage.Shh=JSON.stringify({ttl:10000, targetPow: 1.01, timePow: 19});}
if (typeof localStorage.Language == 'undefined') {localStorage.Language=defaultLanguage.ISO;}
if (typeof localStorage.Blacklist == 'undefined') {localStorage.Blacklist='[]';}
Expand All @@ -95,7 +101,6 @@ var app = angular.module('leth', [
if (typeof localStorage.Friends == 'undefined') {localStorage.Friends = '[]';}
if (typeof localStorage.LastMsg == 'undefined') {localStorage.LastMsg= JSON.stringify({time:0, hash:"0x"});}
if (typeof localStorage.Transactions == 'undefined') {localStorage.Transactions = '[]';}
localStorage.removeItem("Coins");
if (typeof localStorage.Tokens == 'undefined') {localStorage.Tokens = '[]';}
if (typeof localStorage.NodeHost == 'undefined') {
localStorage.NodeHost = "http://wallet.inzhoop.com:8546";
Expand Down
24 changes: 19 additions & 5 deletions www/js/controllers/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,16 @@ angular.module('leth.controllers', [])
"Installed" : true
}

$scope.listTokens.push(customToken);
//$scope.listTokens.push(customToken);

AppService.addLocalToken(customToken);

AppService.getAllTokens($scope.nameNetwork).then(function(response){
$scope.listTokens = response;
}, function(err){
$scope.listTokens=null;
});

$scope.closeTokenModal();
};

Expand All @@ -508,7 +514,7 @@ angular.module('leth.controllers', [])
$scope.listTokens.splice($scope.listTokens.indexOf(token),1);
AppService.deleteLocalToken(token);
}

$scope.readCoinsList();
$ionicListDelegate.closeOptionButtons();
});
Expand Down Expand Up @@ -1330,9 +1336,17 @@ angular.module('leth.controllers', [])

confirmPopup.then(function(res) {
if(res) {
if($scope.listTokens.indexOf(msg.attach)==-1)
$scope.listTokens.push(msg.attach);
localStorage.listTokens = JSON.stringify($scope.listTokens);
msg.attach.Installed = true;

AppService.addLocalToken(msg.attach);

AppService.getAllTokens($scope.nameNetwork).then(function(response){
$scope.listTokens = response;
}, function(err){
$scope.listTokens=null;
});

$scope.readCoinsList();
$state.go('tab.dappleths', { relative: $state.$current.view});
}
});
Expand Down
15 changes: 10 additions & 5 deletions www/js/controllers/ctrlDappleths.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@ angular.module('leth.controllers')
$timeout(function() {
coin.Installed = true;
$scope.listTokens.filter(function (c) {
if(c.GUID === coin.GUID){
if(c.Address === coin.Address){
c.Installed = true;
c.Progress = false;
c.Network = $scope.nameNetwork;
}
})
coin.Progress = false;
if($scope.listTokens.indexOf(coin)==-1)
$scope.listTokens.splice($scope.listTokens.indexOf(coin),1);


AppService.addLocalToken(coin);

AppService.getAllTokens($scope.nameNetwork).then(function(response){
$scope.listTokens = response;
}, function(err){
$scope.listTokens=null;
});

}, 1500);
};

Expand All @@ -37,7 +42,7 @@ angular.module('leth.controllers')
$timeout(function() {
coin.Installed = false;
$scope.listTokens.filter(function (c) {
if(c.GUID === coin.GUID){
if(c.Address === coin.Address){
c.Installed = false;
c.Progress = false;
}
Expand Down
60 changes: 57 additions & 3 deletions www/js/services/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,41 @@ angular.module('leth.services', [])
},
addLocalToken: function(token){
var tmpstore = JSON.parse(localStorage.Tokens);
tmpstore.splice(tmpstore.indexOf(token),1);
tmpstore.push(token);
var indexOfToken = tmpstore.findIndex(i => i.Address === token.Address);


if(token.Custom){
if(indexOfToken!=-1){
//if exist update
token.GUID = tmpstore[indexOfToken].GUID;
tmpstore[indexOfToken] = token;
}else{
//add new one
var counter = tmpstore.length+1;
token.GUID = "C" + counter; //to change
tmpstore.push(token);
}
}

if(!token.Custom){
if(indexOfToken!=-1){
//if exist update
tmpstore[indexOfToken] = token;
}else{
//add new one
tmpstore.push(token);
}
}


//save to store
localStorage.Tokens = JSON.stringify(tmpstore);
},
deleteLocalToken: function(token){
var tmpstore = JSON.parse(localStorage.Tokens);
tmpstore.splice(tmpstore.indexOf(token),1);
var indexOfToken = tmpstore.findIndex(i => i.Address === token.Address);

tmpstore.splice(indexOfToken,1);
localStorage.Tokens = JSON.stringify(tmpstore);
},
setWeb3Provider: function (keys) {
Expand Down Expand Up @@ -285,6 +313,32 @@ angular.module('leth.services', [])
}
});
},
transactionCallNoParam: function (contract, fname, value, gLimit, gPrice) {
return $q(function (resolve, reject) {
var fromAddr = global_keystore.getAddresses()[0];
var toAddr = contract.Address;
var functionName = fname;
var args = JSON.parse('[]');
var gasPrice = web3.toBigNumber(gPrice);
var gas = gLimit;

try {
args.push({from: fromAddr, gasPrice: gasPrice, gas: gas, value: value});

var callback = function (err, hash) {
var result = new Array;
result.push(err);
result.push(hash);
resolve(result);
}

args.push(callback);
contract[functionName].apply(this, args);
} catch (e) {
reject(e);
}
});
},
deployContract: function (datacode, gasValue) {
return $q(function (resolve, reject) {
var fromAddr = global_keystore.getAddresses()[0];
Expand Down
16 changes: 16 additions & 0 deletions www/js/services/svcDapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ angular.module('leth.services')
transactionCall: function(contract, fname, params, value, gasLimit, gasPrice){
return AppService.transactionCall(contract, fname, params, value, gasLimit, gasPrice);
},
transactionCallNoParam: function(contract, fname, value, gasLimit, gasPrice){
return AppService.transactionCallNoParam(contract, fname, value, gasLimit, gasPrice);
},
popupConfirm: function(txtTitle, txtTemplate){
var q = $q.defer();

Expand Down Expand Up @@ -151,6 +154,19 @@ angular.module('leth.services')
},
toggleRight: function() {
$ionicSideMenuDelegate.toggleRight();
},
getPosition: function(){
var q = $q.defer();

$cordovaGeolocation
.getCurrentPosition()
.then(function (position) {
console.log(position);
q.resolve(position)
}, function (err) {
q.reject();
});
return q.promise;
}

}
Expand Down
2 changes: 1 addition & 1 deletion www/templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

<div class="divider padding" align="center">
<p><img ng-src="img/inzhoop.png" id="headerSetting"></p>
<p>LΞTH v.0.26.9
<p>LΞTH v.0.26.10
<a ng-if="isIOS()" href="itms-services://?action=download-manifest&url=
https://www.inzhoop.com/download/ios/manifest.plist">(update)</a>
</p>
Expand Down

0 comments on commit 0c17778

Please sign in to comment.