Bug fix And UI for asset/token selection
- Fixed bugs in deposit and withdrawal - Added UI select option for token selection on deposit and withdrawal - Added UI style to buy/sell asset selection
This commit is contained in:
parent
a06c5b4c7b
commit
cab65161ba
@ -102,7 +102,7 @@
|
|||||||
<strip-option value="sell">Sell</strip-option>
|
<strip-option value="sell">Sell</strip-option>
|
||||||
</strip-select>
|
</strip-select>
|
||||||
</div>
|
</div>
|
||||||
<select id="get_asset"></select>
|
<sm-select id="get_asset"></sm-select>
|
||||||
<sm-input id="get_price" variant="outlined" placeholder="Max price (₹)" type="number" step="0.01"
|
<sm-input id="get_price" variant="outlined" placeholder="Max price (₹)" type="number" step="0.01"
|
||||||
required hiderequired animate>
|
required hiderequired animate>
|
||||||
</sm-input>
|
</sm-input>
|
||||||
@ -197,8 +197,6 @@
|
|||||||
<div id="wallet_actions">
|
<div id="wallet_actions">
|
||||||
<p class="label">Select asset</p>
|
<p class="label">Select asset</p>
|
||||||
<sm-select id="wallet_asset_selector">
|
<sm-select id="wallet_asset_selector">
|
||||||
<sm-option value="FLO">FLO</sm-option>
|
|
||||||
<sm-option value="Rupee">Rupee</sm-option>
|
|
||||||
</sm-select>
|
</sm-select>
|
||||||
<div class="flex wallet_actions__wrapper">
|
<div class="flex wallet_actions__wrapper">
|
||||||
<button class="button" value="deposit">
|
<button class="button" value="deposit">
|
||||||
@ -1049,14 +1047,15 @@
|
|||||||
})
|
})
|
||||||
async function tradeFlo() {
|
async function tradeFlo() {
|
||||||
const asset = getRef('get_asset').value;
|
const asset = getRef('get_asset').value;
|
||||||
|
return console.debug(asset);
|
||||||
const quantity = parseFloat(getRef('get_quantity').value)
|
const quantity = parseFloat(getRef('get_quantity').value)
|
||||||
const price = parseFloat(getRef('get_price').value)
|
const price = parseFloat(getRef('get_price').value)
|
||||||
showProcess('trade_button_wrapper')
|
showProcess('trade_button_wrapper')
|
||||||
try {
|
try {
|
||||||
if (tradeType === 'buy') {
|
if (tradeType === 'buy') {
|
||||||
await buy(asset, quantity, price, proxy.userID, await proxy.secret) //TODO: asset_name
|
await buy(asset, quantity, price, proxy.userID, await proxy.secret)
|
||||||
} else {
|
} else {
|
||||||
await sell(asset, quantity, price, proxy.userID, await proxy.secret) //TODO: asset_name
|
await sell(asset, quantity, price, proxy.userID, await proxy.secret)
|
||||||
}
|
}
|
||||||
getRef('trade_button_wrapper').append(getRef('success_template').content.cloneNode(true))
|
getRef('trade_button_wrapper').append(getRef('success_template').content.cloneNode(true))
|
||||||
notify(`Placed ${tradeType} order`, 'success')
|
notify(`Placed ${tradeType} order`, 'success')
|
||||||
@ -1199,14 +1198,14 @@
|
|||||||
if (asset === 'FLO') {
|
if (asset === 'FLO') {
|
||||||
await depositFLO(quantity, proxy.userID, proxy.sinkID, privKey, proxySecret)
|
await depositFLO(quantity, proxy.userID, proxy.sinkID, privKey, proxySecret)
|
||||||
} else {
|
} else {
|
||||||
await depositToken(quantity, proxy.userID, proxy.sinkID, privKey, proxySecret) //TODO: token_name
|
await depositToken(asset, quantity, proxy.userID, proxy.sinkID, privKey, proxySecret)
|
||||||
}
|
}
|
||||||
showWalletResult('success', `Sent ${asset} deposit request`, 'This may take upto 30 mins to reflect in your wallet.')
|
showWalletResult('success', `Sent ${asset} deposit request`, 'This may take upto 30 mins to reflect in your wallet.')
|
||||||
} else {
|
} else {
|
||||||
if (asset === 'FLO') {
|
if (asset === 'FLO') {
|
||||||
await withdrawFLO(quantity, proxy.userID, proxySecret)
|
await withdrawFLO(quantity, proxy.userID, proxySecret)
|
||||||
} else {
|
} else {
|
||||||
await withdrawToken(quantity, proxy.userID, proxySecret) //TODO: token_name
|
await withdrawToken(asset, quantity, proxy.userID, proxySecret)
|
||||||
}
|
}
|
||||||
showWalletResult('success', `Sent ${asset} withdraw request`, 'This may take upto 30 mins to reflect in your wallet.')
|
showWalletResult('success', `Sent ${asset} withdraw request`, 'This may take upto 30 mins to reflect in your wallet.')
|
||||||
}
|
}
|
||||||
@ -1640,10 +1639,17 @@
|
|||||||
console.debug(rates);
|
console.debug(rates);
|
||||||
if(init){
|
if(init){
|
||||||
let assetList = getRef('get_asset');
|
let assetList = getRef('get_asset');
|
||||||
|
let walletList = getRef('wallet_asset_selector');
|
||||||
|
let c = document.createElement('sm-option');
|
||||||
|
c.setAttribute('value', floGlobals.currency);
|
||||||
|
c.innerText = floGlobals.currency;
|
||||||
|
walletList.appendChild(c);
|
||||||
for(let asset in rates){
|
for(let asset in rates){
|
||||||
let e = document.createElement('option');
|
let e = document.createElement('sm-option');
|
||||||
|
e.setAttribute('value', asset);
|
||||||
e.innerText = asset;
|
e.innerText = asset;
|
||||||
assetList.appendChild(e);
|
assetList.appendChild(e);
|
||||||
|
walletList.appendChild(e.cloneNode(true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let flo_rate = rates["FLO"];
|
let flo_rate = rates["FLO"];
|
||||||
|
|||||||
@ -99,7 +99,7 @@ function addBuyOrder(floID, asset, quantity, max_price) {
|
|||||||
return reject(INVALID(`Invalid max_price (${max_price})`));
|
return reject(INVALID(`Invalid max_price (${max_price})`));
|
||||||
else if (!assetList.includes(asset))
|
else if (!assetList.includes(asset))
|
||||||
return reject(INVALID(`Invalid asset (${asset})`));
|
return reject(INVALID(`Invalid asset (${asset})`));
|
||||||
getAssetBalance.check(floID, asset, quantity).then(_ => {
|
getAssetBalance.check(floID, floGlobals.currency, quantity).then(_ => {
|
||||||
DB.query("INSERT INTO BuyOrder(floID, asset, quantity, maxPrice) VALUES (?, ?, ?, ?)", [floID, asset, quantity, max_price])
|
DB.query("INSERT INTO BuyOrder(floID, asset, quantity, maxPrice) VALUES (?, ?, ?, ?)", [floID, asset, quantity, max_price])
|
||||||
.then(result => resolve("Added BuyOrder to DB"))
|
.then(result => resolve("Added BuyOrder to DB"))
|
||||||
.catch(error => reject(error));
|
.catch(error => reject(error));
|
||||||
@ -243,7 +243,7 @@ function withdrawFLO(floID, amount) {
|
|||||||
consumeAsset(floID, "FLO", amount).then(txQueries => {
|
consumeAsset(floID, "FLO", amount).then(txQueries => {
|
||||||
DB.transaction(txQueries).then(result => {
|
DB.transaction(txQueries).then(result => {
|
||||||
//Send FLO to user via blockchain API
|
//Send FLO to user via blockchain API
|
||||||
floBlockchainAPI.sendTx(global.myFloID, floID, amount, global.myPrivKey, 'Withdraw FLO Coins from Market').then(txid => {
|
floBlockchainAPI.sendTx(global.sinkID, floID, amount, global.sinkPrivKey, 'Withdraw FLO Coins from Market').then(txid => {
|
||||||
if (!txid)
|
if (!txid)
|
||||||
throw Error("Transaction not successful");
|
throw Error("Transaction not successful");
|
||||||
//Transaction was successful, Add in DB
|
//Transaction was successful, Add in DB
|
||||||
@ -265,7 +265,7 @@ function withdrawFLO(floID, amount) {
|
|||||||
function retryWithdrawalFLO() {
|
function retryWithdrawalFLO() {
|
||||||
DB.query("SELECT id, floID, amount FROM OutputFLO WHERE status=?", ["PENDING"]).then(results => {
|
DB.query("SELECT id, floID, amount FROM OutputFLO WHERE status=?", ["PENDING"]).then(results => {
|
||||||
results.forEach(req => {
|
results.forEach(req => {
|
||||||
floBlockchainAPI.sendTx(global.myFloID, req.floID, req.amount, global.myPrivKey, 'Withdraw FLO Coins from Market').then(txid => {
|
floBlockchainAPI.sendTx(global.sinkID, req.floID, req.amount, global.sinkPrivKey, 'Withdraw FLO Coins from Market').then(txid => {
|
||||||
if (!txid)
|
if (!txid)
|
||||||
throw Error("Transaction not successful");
|
throw Error("Transaction not successful");
|
||||||
//Transaction was successful, Add in DB
|
//Transaction was successful, Add in DB
|
||||||
@ -353,7 +353,7 @@ confirmDepositToken.checkTx = function(sender, txid) {
|
|||||||
return reject([true, "Transaction transfer is not 'token'"]);
|
return reject([true, "Transaction transfer is not 'token'"]);
|
||||||
var token_name = tx.parsedFloData.tokenIdentification,
|
var token_name = tx.parsedFloData.tokenIdentification,
|
||||||
amount_token = tx.parsedFloData.tokenAmount;
|
amount_token = tx.parsedFloData.tokenAmount;
|
||||||
if (!assetList.includes(token_name) || token_name === "FLO")
|
if ((!assetList.includes(token_name) && token_name !== floGlobals.currency) || token_name === "FLO")
|
||||||
return reject([true, "Token not authorised"]);
|
return reject([true, "Token not authorised"]);
|
||||||
let vin_sender = tx.transactionDetails.vin.filter(v => v.addr === sender)
|
let vin_sender = tx.transactionDetails.vin.filter(v => v.addr === sender)
|
||||||
if (!vin_sender.length)
|
if (!vin_sender.length)
|
||||||
@ -373,7 +373,7 @@ function withdrawToken(floID, token, amount) {
|
|||||||
return reject(INVALID("Invalid FLO ID"));
|
return reject(INVALID("Invalid FLO ID"));
|
||||||
else if (typeof amount !== "number" || amount <= 0)
|
else if (typeof amount !== "number" || amount <= 0)
|
||||||
return reject(INVALID(`Invalid amount (${amount})`));
|
return reject(INVALID(`Invalid amount (${amount})`));
|
||||||
else if (!assetList.includes(token) || token === "FLO")
|
else if ((!assetList.includes(token) && token !== floGlobals.currency) || token === "FLO")
|
||||||
return reject(INVALID("Invalid Token"));
|
return reject(INVALID("Invalid Token"));
|
||||||
//Check for FLO balance (transaction fee)
|
//Check for FLO balance (transaction fee)
|
||||||
const required_flo = floGlobals.sendAmt + floGlobals.fee;
|
const required_flo = floGlobals.sendAmt + floGlobals.fee;
|
||||||
@ -383,7 +383,7 @@ function withdrawToken(floID, token, amount) {
|
|||||||
consumeAsset(floID, token, amount, txQueries).then(txQueries => {
|
consumeAsset(floID, token, amount, txQueries).then(txQueries => {
|
||||||
DB.transaction(txQueries).then(result => {
|
DB.transaction(txQueries).then(result => {
|
||||||
//Send FLO to user via blockchain API
|
//Send FLO to user via blockchain API
|
||||||
tokenAPI.sendToken(global.myPrivKey, amount, floID, '(withdrawal from market)', token).then(txid => {
|
tokenAPI.sendToken(global.sinkPrivKey, amount, floID, '(withdrawal from market)', token).then(txid => {
|
||||||
if (!txid) throw Error("Transaction not successful");
|
if (!txid) throw Error("Transaction not successful");
|
||||||
//Transaction was successful, Add in DB
|
//Transaction was successful, Add in DB
|
||||||
DB.query("INSERT INTO OutputToken (floID, token, amount, txid, status) VALUES (?, ?, ?, ?, ?)", [floID, token, amount, txid, "WAITING_CONFIRMATION"])
|
DB.query("INSERT INTO OutputToken (floID, token, amount, txid, status) VALUES (?, ?, ?, ?, ?)", [floID, token, amount, txid, "WAITING_CONFIRMATION"])
|
||||||
@ -406,7 +406,7 @@ function withdrawToken(floID, token, amount) {
|
|||||||
function retryWithdrawalToken() {
|
function retryWithdrawalToken() {
|
||||||
DB.query("SELECT id, floID, token, amount FROM OutputToken WHERE status=?", ["PENDING"]).then(results => {
|
DB.query("SELECT id, floID, token, amount FROM OutputToken WHERE status=?", ["PENDING"]).then(results => {
|
||||||
results.forEach(req => {
|
results.forEach(req => {
|
||||||
tokenAPI.sendToken(global.myPrivKey, req.amount, req.floID, '(withdrawal from market)', req.token).then(txid => {
|
tokenAPI.sendToken(global.sinkPrivKey, req.amount, req.floID, '(withdrawal from market)', req.token).then(txid => {
|
||||||
if (!txid)
|
if (!txid)
|
||||||
throw Error("Transaction not successful");
|
throw Error("Transaction not successful");
|
||||||
//Transaction was successful, Add in DB
|
//Transaction was successful, Add in DB
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user