Skip to content

Commit

Permalink
Custom Price GUI done
Browse files Browse the repository at this point in the history
  • Loading branch information
stanacton committed Oct 13, 2017
1 parent 3ec9cd6 commit 59e2f7f
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 891 deletions.
36 changes: 36 additions & 0 deletions src/dapp/app/controllers/CoinAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,26 @@ app.controller("CoinAdminCtrl", ['$scope', 'web3', 'ico', '$rootScope', function
});
};

$scope.setPriceForCustomer = function (userAddress, price) {
if (!userAddress) {
return alert( "User Address is required.");
}

if (!price) {
return alert( "price is required.");
}


ico.setPriceForCustomer(userAddress, price, function (err, response) {
if (err) {
alert(err);
return;
}

alert("The transaction has been submitted. Please wait till the next blocks are mined and check if the custom price setting was successful.");
});
};

$scope.takeOwnership = function () {
console.log("taking ownership");
ico.takeOwnership(function (err) {
Expand Down Expand Up @@ -275,6 +295,22 @@ app.controller("CoinAdminCtrl", ['$scope', 'web3', 'ico', '$rootScope', function
});
};

$scope.checkPriceForCustomer = function (address) {

$scope.showPriceCheckResult = false;
$scope.priceCheckAddress = address;
ico.checkPriceForCustomer(address, function (err, response) {
if (err) {
alert(err);
return;
}

$scope.customPrice = response;
$scope.showPriceCheckResult = true;
$scope.$apply();
});
};

$rootScope.$on("new-block", function (event) {
updateDetails();
});
Expand Down
16 changes: 14 additions & 2 deletions src/dapp/app/controllers/WalletCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ app.controller("WalletCtrl", ["$scope", "web3","ico","$rootScope", function ($sc
}

$scope.currentPrice = price;

ico.checkPriceForCustomer(web3.eth.accounts[0], function (err, result) {
if (result > 0) {
$scope.currentPrice = result;
$scope.$apply();
}
});

$scope.$apply();
});

Expand All @@ -29,7 +37,12 @@ app.controller("WalletCtrl", ["$scope", "web3","ico","$rootScope", function ($sc
updateBalance();
});

updateBalance();
updateData();

function updateData() {
updateBalance();
// updatePrice();
}

$scope.updatePrice = function(ethAmount) {
$scope.tokenAmount = ethAmount / $scope.currentPrice;
Expand All @@ -48,7 +61,6 @@ app.controller("WalletCtrl", ["$scope", "web3","ico","$rootScope", function ($sc
$scope.displayConfirmData = true;
$scope.contractAddress = details.contractAddress;
$scope.buyTokenData = details.tranData;
console.log(ico.contractAddress);
});
}
};
Expand Down
23 changes: 23 additions & 0 deletions src/dapp/app/partials/coin-admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,27 @@ <h3>Whitelist
<button class="btn btn-primary" ng-click="addToWhitelist(whitelistAddress)">Add To Whitelist</button>
<button class="btn btn-danger" ng-click="removeFromWhitelist(whitelistAddress)">Remove From Whitelist</button>
</div>

<div class="row admin-action">
<h3>Custom Price</h3>
<p>A custom price can be set for each user. If price is set to 0, then the default price is used.</p>
<div class="row">
<div class="form-group col-lg-9">
<label for="customerPriceAddress">User Address</label>
<input class="form-control" type="text" id="customerPriceAddress" ng-model="customerPriceAddress" placeholder="User Address e.g. 0xac89b7s..."
ng-change="checkPriceForCustomer(customerPriceAddress)"
/>
</div>
<div class="form-group col-lg-9">
<label for="newCustomerPrice">Custom Price</label>
<input class="form-control" type="number" id="newCustomerPrice" ng-model="newCustomerPrice" placeholder="Price in ETH"/>
</div>
</div>
<p>
<span class="label label-success whitelist-label" ng-show="showPriceCheckResult === true">Custom Price is {{ customPrice }} ETH/Token</span>
</p>

<button class="btn btn-default" ng-click="checkPriceForCustomer(customerPriceAddress)">Check Current Price</button>
<button class="btn btn-primary" ng-click="setPriceForCustomer(customerPriceAddress, newCustomerPrice)">Set Custom Price</button>
</div>
</div>
23 changes: 23 additions & 0 deletions src/dapp/app/services/ico.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@
});
}

function setPriceForCustomer(customerAddress, price, next) {
var wei = web3.toWei(price, "ether");
ico.setPriceForCustomer.sendTransaction(customerAddress, wei, function (err, result) {
next(err, result);
});
}

function enableWhitelist(next) {
ico.enableWhitelist.sendTransaction(next);
}
Expand Down Expand Up @@ -222,6 +229,20 @@
});
}

function checkPriceForCustomer(address, next) {
getICO().then(function (ico) {
ico.customerPrice(address, function (err, result) {
if (err) {
return next(err);
}

next(null, web3.fromWei(result));
});
}, function (err) {
console.error(err);
});
}

function whitelistEnabled(next) {
getICO().then(function (ico) {
ico.whitelistEnabled(function (err, result) {
Expand Down Expand Up @@ -376,6 +397,8 @@
disableWhitelist: disableWhitelist,
pauseICO: pauseICO,
takeOwnership: takeOwnership,
setPriceForCustomer: setPriceForCustomer,
checkPriceForCustomer: checkPriceForCustomer,
unpauseICO: unpauseICO
};
}]);
Expand Down
943 changes: 57 additions & 886 deletions src/dapp/public/PreICO.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/dapp/public/address.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"PreICO":{"address":"0xf5c8ec7b37641ce533e786308f14301323194099"}}
{"PreICO":{"address":"0xea6d0d8de0c41f84bf075cff0a2b2cff9ce04430"}}
23 changes: 23 additions & 0 deletions src/dapp/public/partials/coin-admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,27 @@ <h3>Whitelist
<button class="btn btn-primary" ng-click="addToWhitelist(whitelistAddress)">Add To Whitelist</button>
<button class="btn btn-danger" ng-click="removeFromWhitelist(whitelistAddress)">Remove From Whitelist</button>
</div>

<div class="row admin-action">
<h3>Custom Price</h3>
<p>A custom price can be set for each user. If price is set to 0, then the default price is used.</p>
<div class="row">
<div class="form-group col-lg-9">
<label for="customerPriceAddress">User Address</label>
<input class="form-control" type="text" id="customerPriceAddress" ng-model="customerPriceAddress" placeholder="User Address e.g. 0xac89b7s..."
ng-change="checkPriceForCustomer(customerPriceAddress)"
/>
</div>
<div class="form-group col-lg-9">
<label for="newCustomerPrice">Custom Price</label>
<input class="form-control" type="number" id="newCustomerPrice" ng-model="newCustomerPrice" placeholder="Price in ETH"/>
</div>
</div>
<p>
<span class="label label-success whitelist-label" ng-show="showPriceCheckResult === true">Custom Price is {{ customPrice }} ETH/Token</span>
</p>

<button class="btn btn-default" ng-click="checkPriceForCustomer(customerPriceAddress)">Check Current Price</button>
<button class="btn btn-primary" ng-click="setPriceForCustomer(customerPriceAddress, newCustomerPrice)">Set Custom Price</button>
</div>
</div>
75 changes: 73 additions & 2 deletions src/dapp/public/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,26 @@ app.controller("CoinAdminCtrl", ['$scope', 'web3', 'ico', '$rootScope', function
});
};

$scope.setPriceForCustomer = function (userAddress, price) {
if (!userAddress) {
return alert( "User Address is required.");
}

if (!price) {
return alert( "price is required.");
}


ico.setPriceForCustomer(userAddress, price, function (err, response) {
if (err) {
alert(err);
return;
}

alert("The transaction has been submitted. Please wait till the next blocks are mined and check if the custom price setting was successful.");
});
};

$scope.takeOwnership = function () {
console.log("taking ownership");
ico.takeOwnership(function (err) {
Expand Down Expand Up @@ -282,6 +302,22 @@ app.controller("CoinAdminCtrl", ['$scope', 'web3', 'ico', '$rootScope', function
});
};

$scope.checkPriceForCustomer = function (address) {

$scope.showPriceCheckResult = false;
$scope.priceCheckAddress = address;
ico.checkPriceForCustomer(address, function (err, response) {
if (err) {
alert(err);
return;
}

$scope.customPrice = response;
$scope.showPriceCheckResult = true;
$scope.$apply();
});
};

$rootScope.$on("new-block", function (event) {
updateDetails();
});
Expand Down Expand Up @@ -343,6 +379,14 @@ app.controller("WalletCtrl", ["$scope", "web3","ico","$rootScope", function ($sc
}

$scope.currentPrice = price;

ico.checkPriceForCustomer(web3.eth.accounts[0], function (err, result) {
if (result > 0) {
$scope.currentPrice = result;
$scope.$apply();
}
});

$scope.$apply();
});

Expand All @@ -361,7 +405,12 @@ app.controller("WalletCtrl", ["$scope", "web3","ico","$rootScope", function ($sc
updateBalance();
});

updateBalance();
updateData();

function updateData() {
updateBalance();
// updatePrice();
}

$scope.updatePrice = function(ethAmount) {
$scope.tokenAmount = ethAmount / $scope.currentPrice;
Expand All @@ -380,7 +429,6 @@ app.controller("WalletCtrl", ["$scope", "web3","ico","$rootScope", function ($sc
$scope.displayConfirmData = true;
$scope.contractAddress = details.contractAddress;
$scope.buyTokenData = details.tranData;
console.log(ico.contractAddress);
});
}
};
Expand Down Expand Up @@ -562,6 +610,13 @@ app.config(function ($routeProvider, $locationProvider) {
});
}

function setPriceForCustomer(customerAddress, price, next) {
var wei = web3.toWei(price, "ether");
ico.setPriceForCustomer.sendTransaction(customerAddress, wei, function (err, result) {
next(err, result);
});
}

function enableWhitelist(next) {
ico.enableWhitelist.sendTransaction(next);
}
Expand Down Expand Up @@ -646,6 +701,20 @@ app.config(function ($routeProvider, $locationProvider) {
});
}

function checkPriceForCustomer(address, next) {
getICO().then(function (ico) {
ico.customerPrice(address, function (err, result) {
if (err) {
return next(err);
}

next(null, web3.fromWei(result));
});
}, function (err) {
console.error(err);
});
}

function whitelistEnabled(next) {
getICO().then(function (ico) {
ico.whitelistEnabled(function (err, result) {
Expand Down Expand Up @@ -800,6 +869,8 @@ app.config(function ($routeProvider, $locationProvider) {
disableWhitelist: disableWhitelist,
pauseICO: pauseICO,
takeOwnership: takeOwnership,
setPriceForCustomer: setPriceForCustomer,
checkPriceForCustomer: checkPriceForCustomer,
unpauseICO: unpauseICO
};
}]);
Expand Down

0 comments on commit 59e2f7f

Please sign in to comment.