Skip to content
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

Coinsta Wallet #72

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
24 changes: 12 additions & 12 deletions js/ui-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

var uiBlock = function () {

var MAIN_NET_ATP_CONTRACT_ADDR = "n1zUNqeBPvsyrw5zxp9mKcDdLTjuaEL7s39";
var TEST_NET_ATP_CONTRACT_ADDR = "n1nkoSJVLQnaKnDKH56mtKtdjbgLKoHZhtD";
var MAIN_NET_ATP_CONTRACT_ADDR = "c1zUNqeBPvsyrw5zxp9mKcDdLTjuaEL7s39";
var TEST_NET_ATP_CONTRACT_ADDR = "c1nkoSJVLQnaKnDKH56mtKtdjbgLKoHZhtD";

var MAIN_NET_NAT_CONTRACT_ADDR = "n1mpgNi6KKdSzr7i5Ma7JsG5yPY9knf9He7";
var TEST_NET_NAT_CONTRACT_ADDR = "n22PdtQepev7rcQgy3zqfdAkNPN2pSpywZ8";
var MAIN_NET_NAT_CONTRACT_ADDR = "c1mpgNi6KKdSzr7i5Ma7JsG5yPY9knf9He7";
var TEST_NET_NAT_CONTRACT_ADDR = "c22PdtQepev7rcQgy3zqfdAkNPN2pSpywZ8";

var MAIN_NET_NAX_CONTRACT_ADDR = 'n1etmdwczuAUCnMMvpGasfi8kwUbb2ddvRJ';
var TEST_NET_NAX_CONTRACT_ADDR = 'n1osWtAu3V4Ho1ztq6BcMmCuoWDoLTFnPbw';
var MAIN_NET_NAX_CONTRACT_ADDR = 'c1etmdwczuAUCnMMvpGasfi8kwUbb2ddvRJ';
var TEST_NET_NAX_CONTRACT_ADDR = 'c1osWtAu3V4Ho1ztq6BcMmCuoWDoLTFnPbw';

var old$fnModal = $.fn.modal;

Expand All @@ -22,7 +22,7 @@ var uiBlock = function () {
numberAddComma: numberAddComma,
toSi: toSi,
validate: validate,
currency: "NAS",
currency: "CNTA",
_currencyChangedListeners: [],
addCurrencyChangedListener: addCurrencyChangedListener,
getContractAddr: getContractAddr,
Expand Down Expand Up @@ -79,7 +79,7 @@ var uiBlock = function () {
function isNRC20ContractAddr(addr) {
var currencies = getCurrencies();
for (var c in currencies) {
if (c != "NAS" && currencies[c] == addr) {
if (c != "CNTA" && currencies[c] == addr) {
return true;
}
}
Expand All @@ -89,7 +89,7 @@ var uiBlock = function () {
function getCurrencies() {
currencies = localSave.getItem("currencies");
if (!currencies) {
currencies = { "NAS": "", "NAX": MAIN_NET_NAX_CONTRACT_ADDR, "ATP": MAIN_NET_ATP_CONTRACT_ADDR, "NAT": MAIN_NET_NAT_CONTRACT_ADDR };
currencies = { "CNTA": "", "NAX": MAIN_NET_NAX_CONTRACT_ADDR, "ATP": MAIN_NET_ATP_CONTRACT_ADDR, "NAT": MAIN_NET_NAT_CONTRACT_ADDR };
} else {
currencies = JSON.parse(currencies);
}
Expand Down Expand Up @@ -201,9 +201,9 @@ var uiBlock = function () {
// apiPrefix

apiList = [
{ chainId: 1, name: "Mainnet", url: "https://mainnet.nebulas.io", currencies: { "NAS": "", "NAX": MAIN_NET_NAX_CONTRACT_ADDR, "ATP": MAIN_NET_ATP_CONTRACT_ADDR, "NAT": MAIN_NET_NAT_CONTRACT_ADDR } },
{ chainId: 1, name: "Mainnet", url: "https://mainnet.nebulas.io", currencies: { "CNTA": "", "NAX": MAIN_NET_NAX_CONTRACT_ADDR, "ATP": MAIN_NET_ATP_CONTRACT_ADDR, "NAT": MAIN_NET_NAT_CONTRACT_ADDR } },
{ chainId: 1001, name: "Testnet", url: "https://testnet.nebulas.io", currencies: { "NAS": "", "NAX": TEST_NET_NAX_CONTRACT_ADDR, "ATP": TEST_NET_ATP_CONTRACT_ADDR, "NAT": TEST_NET_NAT_CONTRACT_ADDR } },
{ chainId: 100, name: "Local Nodes", url: "http://127.0.0.1:8685", currencies: { "NAS": "" } }
{ chainId: 100, name: "Local Nodes", url: "http://127.0.0.1:8685", currencies: { "CNTA": "" } }
];
apiPrefix = (localSave.getItem("apiPrefix") || "").toLowerCase();
sApiButtons = "";
Expand Down Expand Up @@ -480,7 +480,7 @@ var uiBlock = function () {
for (i = 0; i < len && n >= 1000; ++i, n /= 1000);

if (i == len && unit == "Wei")
for (i = 0, len = si.length - 1, unit = "NAS"; i < len && n >= 1000; ++i, n /= 1000);
for (i = 0, len = si.length - 1, unit = "CNTA"; i < len && n >= 1000; ++i, n /= 1000);

n = n.toFixed();
return (i == len ? numberAddComma(n) : n) + " " + si[i] + unit;
Expand Down
12 changes: 6 additions & 6 deletions sendNas.html
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ <h5 class=modal-title id=exampleModalLabel data-i18n=send-nas/transfer_msg>trans
var currency = uiBlock.currency;
var contractAddr = uiBlock.getContractAddr(uiBlock.currency);
$("#balance").val("").trigger("input");
if (currency == "NAS") {
if (currency == "CNTA") {
neb.api.getAccountState(addr)
.then(function (resp) {
if (currency != uiBlock.currency) {
Expand All @@ -243,7 +243,7 @@ <h5 class=modal-title id=exampleModalLabel data-i18n=send-nas/transfer_msg>trans
if (resp.error) {
throw new Error(resp.error);
}
var nas = Unit.fromBasic(resp.balance, "nas").toString(10);
var nas = Unit.fromBasic(resp.balance, "cnta").toString(10);
$("#balance").val(nas).trigger("input"); // add comma & unit from value, needs trigger 'input' event if via set o.value
$("#nonce").val(parseInt(resp.nonce || 0) + 1);
})
Expand Down Expand Up @@ -277,7 +277,7 @@ <h5 class=modal-title id=exampleModalLabel data-i18n=send-nas/transfer_msg>trans
if(uiBlock.currency === "NAX") {
balance = Unit.fromBasic(b, "gwei").toString();
} else {
balance = Unit.fromBasic(b, "nas").toString(10);
balance = Unit.fromBasic(b, ).toString(10);
}

$("#balance").val(balance).trigger("input"); // add comma & unit from value, needs trigger 'input' event if via set o.value
Expand Down Expand Up @@ -327,7 +327,7 @@ <h5 class=modal-title id=exampleModalLabel data-i18n=send-nas/transfer_msg>trans
gLastGenerateInfo.gasprice != gasprice ||
gLastGenerateInfo.nonce != nonce) try { //TODO: 加括号
var tmp = Unit.fromBasic(Utils.toBigNumber(gaslimit)
.times(Utils.toBigNumber(gasprice)), "nas");
.times(Utils.toBigNumber(gasprice)), "cnta");

if (Utils.toBigNumber(balance).lt(Utils.toBigNumber(amount).plus(tmp))) //TODO: 加括号; tmp-->max gas used
if (Utils.toBigNumber(balance).lt(tmp))
Expand All @@ -337,7 +337,7 @@ <h5 class=modal-title id=exampleModalLabel data-i18n=send-nas/transfer_msg>trans

var a = amount.split(".");
var amountValid = a.length == 1 || a[1].length <= 18;
if (uiBlock.currency == "NAS") {
if (uiBlock.currency == "CNTA") {
if (!amountValid) throw new Error("Invalid value! The minimum unit is wei (1^-18nas) ");
gTx = new Transaction(parseInt(localSave.getItem("chainId")), gAccount, toAddress, Unit.nasToBasic(Utils.toBigNumber(amount)), parseInt(nonce), gasprice, gaslimit);
} else {
Expand Down Expand Up @@ -407,7 +407,7 @@ <h5 class=modal-title id=exampleModalLabel data-i18n=send-nas/transfer_msg>trans
neb.api.getAccountState($(".icon-address.from input").val())
.then(function (resp) {
// console.log("getAccountState resp: " + JSON.stringify(resp));
var balanceNas = Unit.fromBasic(resp.balance, "nas").toString(10);
var balanceNas = Unit.fromBasic(resp.balance, "cnta").toString(10);
$("#balance").val(balanceNas);
$("#nonce").val(resp.nonce);
}).catch(function (err) {
Expand Down
8 changes: 4 additions & 4 deletions sendOffline.html
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ <h4 class=modal-title>info</h4>
tx = Transaction.prototype.fromProto(val);
var to = tx.to.getAddressString();
var value = tx.value;
var currency = "NAS"
var currency = "CNTA"
if (tx.data.payload) {
var data = eval("var d = " + nebulas.CryptoUtils.toBuffer(tx.data.payload).toString() + "; d");
var args = eval("var args = " + data["Args"]+"; args");
Expand All @@ -277,7 +277,7 @@ <h4 class=modal-title>info</h4>
if(uiBlock.currency === "NAX") {
balance = unit.fromBasic(value, "gwei").toString();
} else {
balance = unit.fromBasic(value, "nas").toString(10);
balance = unit.fromBasic(value, "cnta").toString(10);
}

$("#value").val(balance).trigger("input");
Expand Down Expand Up @@ -305,7 +305,7 @@ <h4 class=modal-title>info</h4>
var contract = null;

toaccount = Account.fromAddress(toaddress);
if (uiBlock.currency != "NAS") {
if (uiBlock.currency != "CNTA") {

var transfer_amount;
if(uiBlock.currency === "NAX") {
Expand All @@ -325,7 +325,7 @@ <h4 class=modal-title>info</h4>
gLastGenerateInfo.contract != contract) try {
var a = amount.split(".");
var amountValid = a.length == 1 || a[1].length <= 18;
if (uiBlock.currency == "NAS") {
if (uiBlock.currency == "CNTA") {
if (!amountValid) throw new Error("Invalid value! The minimum unit is wei (1^-18nas) ");
tx = new Transaction(parseInt(localSave.getItem("chainId")), gAccount, toaccount.getAddressString(), unit.nasToBasic(amount), parseInt(nonce), gasprice, gaslimit);
} else {
Expand Down
2 changes: 1 addition & 1 deletion viewWalletInfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
var currency = uiBlock.currency;
var contractAddr = uiBlock.getContractAddr(uiBlock.currency);
$("#amount").val("").trigger("input");
if (currency == "NAS") {
if (currency == "CNTA") {
neb.api.getAccountState(addr)
.then(function (resp) {
if (currency != uiBlock.currency) {
Expand Down