Skip to content
Permalink
Browse files

Merge pull request #12 from Daniel-Wang/daniel/fixAddCoin

Daniel/fix add coin
  • Loading branch information...
Daniel-Wang committed Nov 25, 2017
2 parents d0e990c + 3343caa commit dabfc8af311e2da6b282f397ba99b7c0c38e596f
@@ -31,28 +31,50 @@ var coinSet = {
'zec':"Zcash"
};

var noDataLoadedCoinList = [];

var DashboardPage = Backbone.View.extend({
openWebSocketConnection: function(){
connection.onopen = function (session) {
function tickerEvent (args,kwargs) {
let ticker = args[0];

if (ticker.substring(0, 5) === "USDT_") {
let symbol = ticker.substring(5).toLowerCase();
latestCoinPrices[symbol] = args[1];
display: function(){
function openWebSocketConnection() {
connection.onopen = function (session) {
function tickerEvent(args, kwargs) {
let ticker = args[0];

if (ticker.substring(0, 5) === "USDT_") {
let symbol = ticker.substring(5).toLowerCase();
latestCoinPrices[symbol] = args[1];

let indicesToRemove = [];
let counter = 0;
noDataLoadedCoinList.forEach(function (coin) {
if (symbol == coin.type) {
indicesToRemove.push(counter);
let priceUSD = latestCoinPrices[symbol];
addCoinToPortfolio(symbol, coin.amount.toString(), priceUSD.toString());
}
counter++;
});

indicesToRemove.forEach(function (index) {
noDataLoadedCoinList.remove(index);
});

updateTotalUSD();
updateCoinPercentage();
updatePortfolio();
}
}
}
session.subscribe('ticker', tickerEvent);
};

connection.onclose = function () {
console.log("Websocket connection closed");
};
session.subscribe('ticker', tickerEvent);
};

connection.open();
},
connection.onclose = function () {
console.log("Websocket connection closed");
alert("Websocket connection closed");
};

display: function(){
connection.open();
}

$('#signout-button').click(function(event) {
event.preventDefault();
@@ -105,7 +127,6 @@ var DashboardPage = Backbone.View.extend({
function updateCoinPercentage() {
if (portfolio.coins.length > 0) {
portfolio.coins.forEach(function (coin) {
console.log(getCoinMarketValue(coin.type, coin.amount));
coin['percentPortfolio'] = getCoinMarketValue(coin.type, coin.amount) / parseFloat(portfolio.totalUSD) * 100.0;
});
}
@@ -190,8 +211,6 @@ var DashboardPage = Backbone.View.extend({
});

$('#coin-list').click(function() {
console.log("options");
console.log(selectedManualType.toUpperCase());
document.getElementById('coin-symbol').textContent = selectedManualType.toUpperCase();
});

@@ -241,7 +260,7 @@ var DashboardPage = Backbone.View.extend({

document.getElementById('wallet-address').value = "";

wallets.forEach(function (wallet) {
portfolio.wallets.forEach(function (wallet) {
if (wallet.address === newAddress) {
alreadyExists = true;
}
@@ -250,6 +269,7 @@ var DashboardPage = Backbone.View.extend({
if (!alreadyExists) {
portfolio.wallets.push(newWallet);
fetchWalletInfo(selectedAddressType, newAddress);
fetchTransactions(selectedAddressType, newAddress);
closeDialog();
} else {
document.getElementById('already-exists-error').display = 'inline';
@@ -271,9 +291,17 @@ var DashboardPage = Backbone.View.extend({
data += chunk;
let p = JSON.parse(data);
amount = parseFloat(p)*Math.pow(10, -8);
let priceUSD = latestCoinPrices[type];
addCoinToPortfolio(type, amount.toString(), priceUSD.toString());
updatePortfolio();
if (typeof latestCoinPrices[type] != 'undefined') {
let priceUSD = latestCoinPrices[type];
addCoinToPortfolio(type, amount.toString(), priceUSD.toString());
updatePortfolio();
} else {
let coin = {
"type": type,
"amount": amount
};
noDataLoadedCoinList.push(coin);
}
});
});
break;
@@ -287,9 +315,18 @@ var DashboardPage = Backbone.View.extend({
data += chunk;
let p = JSON.parse(data);
amount = parseFloat(p.result)*Math.pow(10, -18);
let priceUSD = latestCoinPrices[type];
addCoinToPortfolio(type, amount.toString(), priceUSD.toString());
updatePortfolio();

if (typeof latestCoinPrices[type] != 'undefined') {
let priceUSD = latestCoinPrices[type];
addCoinToPortfolio(type, amount.toString(), priceUSD.toString());
updatePortfolio();
} else {
let coin = {
"type": type,
"amount": amount
};
noDataLoadedCoinList.push(coin);
}
});
});
break;
@@ -356,16 +393,15 @@ var DashboardPage = Backbone.View.extend({

portfolio.coins.forEach(function (coin) {

console.log(latestCoinPrices[coin.type]);
console.log(coin);

$(".portfolio-item-container").append(`<div class="portfolio-item"> <div class="CryptoCurrencyType">${coin.coinName}</div> <div class="Percent-of-Portfolio">${coin.percentPortfolio.toFixed(1)}%</div><div class="CryptoCurrencyVal">${coin.amount} ${coin.type}</div><div class="USD">${getCoinMarketValue(coin.type, coin.amount).toFixed(2)}</div></div>`);

if (isNaN(getCoinMarketValue(coin.type, coin.amount))) {
$(".portfolio-item-container").append(`<div class="portfolio-item"><img src='img/${coin.type.toUpperCase()}.svg' alt='${coin.coinName}' class="portfolio-icon"><div class="CryptoCurrencyType">${coin.coinName}</div> <div class="Percent-of-Portfolio">Loading</div><div class="CryptoCurrencyVal">${coin.amount} ${coin.type.toUpperCase()}</div><div class="USD">Loading</div></div>`);
$('.portfolio-total-balance').html(`Total balance: US$$`);
} else {
$(".portfolio-item-container").append(`<div class="portfolio-item"><img src='img/${coin.type.toUpperCase()}.svg' alt='${coin.coinName}' class="portfolio-icon"><div class="CryptoCurrencyType">${coin.coinName}</div> <div class="Percent-of-Portfolio">${coin.percentPortfolio.toFixed(1)}%</div><div class="CryptoCurrencyVal">${coin.amount.toFixed(5)} ${coin.type.toUpperCase()}</div><div class="USD">${getCoinMarketValue(coin.type, coin.amount).toFixed(2)}</div></div>`);
$('.portfolio-total-balance').html(`Total balance: US$${portfolio.totalUSD.toFixed(2)}`);
blockstack.putFile(STORAGE_FILE, JSON.stringify(portfolio));
}
});


$('.portfolio-total-balance').html(`Total balance: US$${portfolio.totalUSD.toFixed(2)}`);
blockstack.putFile(STORAGE_FILE, JSON.stringify(portfolio));
}

function showTransactions() {
@@ -374,7 +410,7 @@ var DashboardPage = Backbone.View.extend({
let transVal = "";
let transType;

wallets.forEach(function(wallet) {
portfolio.wallets.forEach(function(wallet) {
if (wallet.address === data.from) {
transText = "Sent ";
transVal = "-";
@@ -407,6 +443,8 @@ var DashboardPage = Backbone.View.extend({
});
}

openWebSocketConnection();

blockstack.getFile(STORAGE_FILE).then((portfolioJson) => {
portfolio = JSON.parse(portfolioJson);

@@ -424,6 +462,5 @@ var DashboardPage = Backbone.View.extend({

$(function() {
var dashboardPage = new DashboardPage();
dashboardPage.openWebSocketConnection();
dashboardPage.display();
});
@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="227" height="227" viewBox="0 0 227 227"><path d="M113.666 43.5c-5.767-.01-11.629.7-17.475 2.191v-.003c-37.41 9.551-59.99 47.587-50.431 84.957 9.56 37.37 47.637 59.925 85.049 50.375 37.412-9.548 59.99-47.584 50.432-84.954-8.067-31.53-36.434-52.514-67.575-52.566zM0 43.82V183.5h64.531c-22-15.421-36.383-40.953-36.383-69.84 0-28.886 14.382-54.418 36.383-69.84H0zm162.469 0c22 15.422 36.383 40.954 36.383 69.84 0 28.887-14.382 54.419-36.383 69.84H227V43.82h-64.531zm-50.832 23.037l3.465 13.545c6.33-1.205 11.273-1.202 16.087.754 6.224 2.526 7.666 9.308 7.96 10.938.291 1.63.377 4.894-.521 7.24-.896 2.35-3.824 5.219-3.824 5.219s4.279-.179 7.683 1.24c3.397 1.42 6.479 4.664 7.778 10.236 1.303 5.569 1.574 11.361-2.564 16.159-4.039 4.679-9.113 6.699-11.498 7.649l-.179.07c-1.136.455-3.108 1.133-5.237 1.81l3.469 13.565-8.359 2.135-3.415-13.346-6.367 1.625 3.414 13.346-8.359 2.135-3.414-13.348-16.447 4.197-.846-10.469 5-1.275c1.68-.431 2.342-.764 2.875-1.605.533-.844.43-1.899.22-2.721l-8.837-34.553c-.554-2.165-.88-2.705-2.16-3.563-1.282-.859-3.663-.409-4.983-.069l-4.832 1.231-2.219-8.672 16.448-4.197-3.427-13.383 8.36-2.133 3.423 13.385 6.367-1.625-3.424-13.385 8.363-2.135zm3.666 24.047c-2.965-.012-5.03.447-7.33.998-2.627.63-5.225 1.543-5.225 1.543l4.121 16.116s3.938-.881 6.955-1.776c3.018-.896 6.082-2.422 8.094-4.308 2.015-1.887 2.824-4.256 1.969-7.28-.86-3.024-3.547-5.08-7.254-5.258a31.112 31.112 0 0 0-1.33-.035zm8.926 24.002a32.93 32.93 0 0 0-5.777.555c-4.213.784-9.456 2.412-9.456 2.412l4.582 17.91s5.579-1.296 9.219-2.518c3.641-1.22 7.229-3.133 8.875-4.676 1.643-1.542 3.529-3.771 2.481-7.867-1.048-4.098-4.221-5.116-5.983-5.498-.881-.191-2.258-.328-3.941-.318z"/></svg>
<svg fill="#FFB119" xmlns="http://www.w3.org/2000/svg" width="227" height="227" viewBox="0 0 227 227"><path d="M113.666 43.5c-5.767-.01-11.629.7-17.475 2.191v-.003c-37.41 9.551-59.99 47.587-50.431 84.957 9.56 37.37 47.637 59.925 85.049 50.375 37.412-9.548 59.99-47.584 50.432-84.954-8.067-31.53-36.434-52.514-67.575-52.566zM0 43.82V183.5h64.531c-22-15.421-36.383-40.953-36.383-69.84 0-28.886 14.382-54.418 36.383-69.84H0zm162.469 0c22 15.422 36.383 40.954 36.383 69.84 0 28.887-14.382 54.419-36.383 69.84H227V43.82h-64.531zm-50.832 23.037l3.465 13.545c6.33-1.205 11.273-1.202 16.087.754 6.224 2.526 7.666 9.308 7.96 10.938.291 1.63.377 4.894-.521 7.24-.896 2.35-3.824 5.219-3.824 5.219s4.279-.179 7.683 1.24c3.397 1.42 6.479 4.664 7.778 10.236 1.303 5.569 1.574 11.361-2.564 16.159-4.039 4.679-9.113 6.699-11.498 7.649l-.179.07c-1.136.455-3.108 1.133-5.237 1.81l3.469 13.565-8.359 2.135-3.415-13.346-6.367 1.625 3.414 13.346-8.359 2.135-3.414-13.348-16.447 4.197-.846-10.469 5-1.275c1.68-.431 2.342-.764 2.875-1.605.533-.844.43-1.899.22-2.721l-8.837-34.553c-.554-2.165-.88-2.705-2.16-3.563-1.282-.859-3.663-.409-4.983-.069l-4.832 1.231-2.219-8.672 16.448-4.197-3.427-13.383 8.36-2.133 3.423 13.385 6.367-1.625-3.424-13.385 8.363-2.135zm3.666 24.047c-2.965-.012-5.03.447-7.33.998-2.627.63-5.225 1.543-5.225 1.543l4.121 16.116s3.938-.881 6.955-1.776c3.018-.896 6.082-2.422 8.094-4.308 2.015-1.887 2.824-4.256 1.969-7.28-.86-3.024-3.547-5.08-7.254-5.258a31.112 31.112 0 0 0-1.33-.035zm8.926 24.002a32.93 32.93 0 0 0-5.777.555c-4.213.784-9.456 2.412-9.456 2.412l4.582 17.91s5.579-1.296 9.219-2.518c3.641-1.22 7.229-3.133 8.875-4.676 1.643-1.542 3.529-3.771 2.481-7.867-1.048-4.098-4.221-5.116-5.983-5.498-.881-.191-2.258-.328-3.941-.318z"/></svg>

This file was deleted.

@@ -0,0 +1 @@
<svg fill="#0076b8" xmlns="http://www.w3.org/2000/svg" width="226.777" height="226.777" viewBox="0 0 226.777 226.777"><path d="M92.683 97.738H10.195L.65 128.765h82.488z"/><path d="M223.896 57.882c-4.539-8.829-13.874-12.097-20.937-12.097H48.831l-10.426 33.79h138.119l-20.803 67.626H16.501l-10.427 33.79h148.032c14.464 0 18.33-2.531 28.673-8.586s18.414-16.649 22.789-29.262c4.376-12.613 15.05-48.181 18.328-60.037 3.281-11.855 4.541-16.395 0-25.224z"/></svg>
@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 226.8 226.8"><path d="M47.1 101.6L114 73.4l64.8 28.9L113.9 0 47.1 101.6zm.2 31.3l66.7 38.7 68.1-38.7-67.5 93.9-67.3-93.9z"/><path d="M114.3 87.2l-69.6 29.3 69.6 38.7 67.7-37.8-67.7-30.2z"/></svg>
<svg fill="#648e74" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 226.8 226.8"><path d="M47.1 101.6L114 73.4l64.8 28.9L113.9 0 47.1 101.6zm.2 31.3l66.7 38.7 68.1-38.7-67.5 93.9-67.3-93.9z"/><path d="M114.3 87.2l-69.6 29.3 69.6 38.7 67.7-37.8-67.7-30.2z"/></svg>
@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="226.777" height="226.777" viewBox="0 0 226.777 226.777"><path d="M113.441 0C50.789 0 0 50.79 0 113.443c0 62.654 50.789 113.441 113.441 113.441 62.654 0 113.443-50.787 113.443-113.441C226.885 50.79 176.096 0 113.441 0zm44.036 168.762H68.839l7.45-35.566-14.486 9.933 3.519-19.463 15.151-10.43 14.862-70.939h27.671l-10.232 48.71L148.8 66.213l-4.222 20.167-36.02 24.693-7.126 33.93H162.4l-4.923 23.759z"/></svg>
<svg fill="#979797" xmlns="http://www.w3.org/2000/svg" width="226.777" height="226.777" viewBox="0 0 226.777 226.777"><path d="M113.441 0C50.789 0 0 50.79 0 113.443c0 62.654 50.789 113.441 113.441 113.441 62.654 0 113.443-50.787 113.443-113.441C226.885 50.79 176.096 0 113.441 0zm44.036 168.762H68.839l7.45-35.566-14.486 9.933 3.519-19.463 15.151-10.43 14.862-70.939h27.671l-10.232 48.71L148.8 66.213l-4.222 20.167-36.02 24.693-7.126 33.93H162.4l-4.923 23.759z"/></svg>
@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="226.777" height="226.777" viewBox="0 0 226.777 226.777"><path d="M39.722 149.021v-95.15l73.741 73.741 73.669-73.669v95.079h33.936a113.219 113.219 0 0 0 5.709-35.59c0-62.6-50.746-113.347-113.347-113.347C50.83.085.083 50.832.083 113.432c0 12.435 2.008 24.396 5.709 35.59h33.93z"/><path d="M162.54 172.077v-60.152l-49.495 49.495-49.148-49.148v59.806h-47.48c19.864 32.786 55.879 54.7 97.013 54.7 41.135 0 77.149-21.914 97.013-54.7H162.54z"/></svg>
<svg fill="#f66631" xmlns="http://www.w3.org/2000/svg" width="226.777" height="226.777" viewBox="0 0 226.777 226.777"><path d="M39.722 149.021v-95.15l73.741 73.741 73.669-73.669v95.079h33.936a113.219 113.219 0 0 0 5.709-35.59c0-62.6-50.746-113.347-113.347-113.347C50.83.085.083 50.832.083 113.432c0 12.435 2.008 24.396 5.709 35.59h33.93z"/><path d="M162.54 172.077v-60.152l-49.495 49.495-49.148-49.148v59.806h-47.48c19.864 32.786 55.879 54.7 97.013 54.7 41.135 0 77.149-21.914 97.013-54.7H162.54z"/></svg>
@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="226.777" height="226.777" viewBox="0 0 226.777 226.777"><path d="M113.48.183C50.908.183.183 50.908.183 113.48c0 62.572 50.725 113.297 113.297 113.297 62.572 0 113.297-50.726 113.297-113.297C226.777 50.908 176.052.183 113.48.183zm47.419 163.777c-7.365 12.656-23.905 17.119-36.941 9.97-13.037-7.149-17.635-23.205-10.268-35.862 3.068-5.272 1.153-11.96-4.28-14.941-5.356-2.937-12.132-1.166-15.261 3.941h-.002v-.021c-.044.078-.083.155-.128.232-7.365 12.656-23.904 17.12-36.94 9.97-13.038-7.149-17.636-23.207-10.271-35.86 7.367-12.657 23.905-17.12 36.944-9.969 4.357 2.39 7.765 5.779 10.107 9.7v-.014l.002-.002c3.248 5.032 10.055 6.654 15.341 3.603 5.362-3.095 7.125-9.824 3.936-15.03-7.651-12.494-3.42-28.645 9.451-36.072 12.869-7.428 29.506-3.321 37.159 9.172 7.651 12.495 3.422 28.645-9.451 36.073a27.612 27.612 0 0 1-13.697 3.694l.012.005v.002c-6.175.207-11.081 5.161-11.007 11.191.073 6.11 5.239 11.008 11.533 10.936l-.039.021a27.627 27.627 0 0 1 13.533 3.401c13.034 7.151 17.632 23.206 10.267 35.86z"/></svg>
<svg fill="#008abe" xmlns="http://www.w3.org/2000/svg" width="226.777" height="226.777" viewBox="0 0 226.777 226.777"><path d="M113.48.183C50.908.183.183 50.908.183 113.48c0 62.572 50.725 113.297 113.297 113.297 62.572 0 113.297-50.726 113.297-113.297C226.777 50.908 176.052.183 113.48.183zm47.419 163.777c-7.365 12.656-23.905 17.119-36.941 9.97-13.037-7.149-17.635-23.205-10.268-35.862 3.068-5.272 1.153-11.96-4.28-14.941-5.356-2.937-12.132-1.166-15.261 3.941h-.002v-.021c-.044.078-.083.155-.128.232-7.365 12.656-23.904 17.12-36.94 9.97-13.038-7.149-17.636-23.207-10.271-35.86 7.367-12.657 23.905-17.12 36.944-9.969 4.357 2.39 7.765 5.779 10.107 9.7v-.014l.002-.002c3.248 5.032 10.055 6.654 15.341 3.603 5.362-3.095 7.125-9.824 3.936-15.03-7.651-12.494-3.42-28.645 9.451-36.072 12.869-7.428 29.506-3.321 37.159 9.172 7.651 12.495 3.422 28.645-9.451 36.073a27.612 27.612 0 0 1-13.697 3.694l.012.005v.002c-6.175.207-11.081 5.161-11.007 11.191.073 6.11 5.239 11.008 11.533 10.936l-.039.021a27.627 27.627 0 0 1 13.533 3.401c13.034 7.151 17.632 23.206 10.267 35.86z"/></svg>
@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="595.279" height="595.28" viewBox="0 123.305 595.279 595.28"><path d="M297.606 718.517C133.506 718.517 0 585.015 0 420.914 0 256.81 133.506 123.305 297.606 123.305c164.098 0 297.605 133.505 297.605 297.609 0 164.101-133.508 297.603-297.605 297.603zm0-566.181c-148.092 0-268.573 120.482-268.573 268.577 0 148.092 120.481 268.575 268.573 268.575 148.091 0 268.569-120.482 268.569-268.575 0-148.095-120.478-268.577-268.569-268.577z"/><path d="M278.497 500.175h138.006v69.357h-84.927c1.416 19.818 2.12 38.221 3.539 58.036h-71.482v-57.325h-84.927c0-22.651-2.829-45.294 1.415-66.525 2.125-11.326 14.862-21.238 22.649-31.143 26.89-31.849 53.788-62.987 81.388-94.833 10.614-12.03 21.232-23.353 33.262-36.803H185.077v-69.356h78.556v-58.032h68.648v56.617h85.637c0 23.353 2.83 46.002-1.415 67.234-2.122 11.323-14.862 21.229-23.356 31.14-26.89 31.849-53.785 62.984-81.388 94.835-10.616 12.738-21.23 24.061-33.262 36.798z"/></svg>
<svg fill="#eeb354" xmlns="http://www.w3.org/2000/svg" width="595.279" height="595.28" viewBox="0 123.305 595.279 595.28"><path d="M297.606 718.517C133.506 718.517 0 585.015 0 420.914 0 256.81 133.506 123.305 297.606 123.305c164.098 0 297.605 133.505 297.605 297.609 0 164.101-133.508 297.603-297.605 297.603zm0-566.181c-148.092 0-268.573 120.482-268.573 268.577 0 148.092 120.481 268.575 268.573 268.575 148.091 0 268.569-120.482 268.569-268.575 0-148.095-120.478-268.577-268.569-268.577z"/><path d="M278.497 500.175h138.006v69.357h-84.927c1.416 19.818 2.12 38.221 3.539 58.036h-71.482v-57.325h-84.927c0-22.651-2.829-45.294 1.415-66.525 2.125-11.326 14.862-21.238 22.649-31.143 26.89-31.849 53.788-62.987 81.388-94.833 10.614-12.03 21.232-23.353 33.262-36.803H185.077v-69.356h78.556v-58.032h68.648v56.617h85.637c0 23.353 2.83 46.002-1.415 67.234-2.122 11.323-14.862 21.229-23.356 31.14-26.89 31.849-53.785 62.984-81.388 94.835-10.616 12.738-21.23 24.061-33.262 36.798z"/></svg>
@@ -150,7 +150,7 @@ h2 {
overflow:visible;
pointer-events:none;
background:none !important;
margin-left:-50px;
margin-left:-70px;
margin-top: 26px;
color: #a6b1ba;
}
@@ -92,3 +92,10 @@
align-items: center;
justify-content: space-evenly;
}

.portfolio-icon {
height: 24px;
width: 24px;
padding-right: 10px;
margin-top: -5px;
}

0 comments on commit dabfc8a

Please sign in to comment.
You can’t perform that action at this time.