Fixed minor bugs in client scripts

- Added floGlobals and link for floBlockchainAPI
This commit is contained in:
sairajzero 2021-09-24 03:35:53 +05:30
parent 7362d0d4b7
commit c675ce3366
2 changed files with 47 additions and 14 deletions

View File

@ -289,11 +289,9 @@ function depositFLO(quantity, userID, privKey, proxySecret) {
return new Promise((resolve, reject) => {
if (typeof quantity !== "number" || quantity <= floGlobals.fee)
return reject(`Invalid quantity (${quantity})`);
floBlockchainAPI.sendTx(userID, floGlobals.adminID, quantity, privKey, 'Deposit FLO in market').then(result => {
if (!result.txid || !result.txid.result || result.txid.error)
return reject(result);
floBlockchainAPI.sendTx(userID, floGlobals.adminID, quantity, privKey, 'Deposit FLO in market').then(txid => {
let request = {
txid: result.txid.result,
txid: txid,
timestamp: Date.now()
};
request.sign = signRequest({
@ -345,13 +343,11 @@ function withdrawFLO(quantity, proxySecret) {
function depositRupee(quantity, userID, privKey, proxySecret) {
return new Promise((resolve, reject) => {
if (!floGlobals.verifyPrivKey(privKey, userID))
if (!floCrypto.verifyPrivKey(privKey, userID))
return reject("Invalid Private Key");
tokenAPI.sendToken(privKey, quantity, 'Deposit Rupee in market').then(result => {
if (!result.txid || !result.txid.result || result.txid.error)
return reject(result);
tokenAPI.sendToken(privKey, quantity, 'Deposit Rupee in market').then(txid => {
let request = {
txid: result.txid.result,
txid: txid,
timestamp: Date.now()
};
request.sign = signRequest({

View File

@ -7,7 +7,30 @@
border: 1px solid black;
}
</style>
<script>
</script>
<script id="floGlobals">
/* Constants for FLO blockchain operations !!Make sure to add this at begining!! */
const floGlobals = {
//Required for all
blockchain: "FLO",
//Required for blockchain API operators
apiURL: {
FLO: ['https://livenet.flocha.in/', 'https://flosight.duckdns.org/'],
FLO_TEST: ['https://testnet-flosight.duckdns.org/', 'https://testnet.flocha.in/']
},
tokenURL: "https://ranchimallflo.duckdns.org/",
token: "rupee",
adminID: "FKAEdnPfjXLHSYwrXQu377ugN4tXU7VGdf",
sendAmt: 0.001,
fee: 0.0005,
}
</script>
<script src="https://sairajzero.github.io/Standard_Operations/cdn/floCrypto.js"></script>
<script src="https://github.com/sairajzero/Standard_Operations/releases/download/test/floBlockchainAPI.js"></script>
<script src="fn.js"></script>
</head>
@ -18,7 +41,8 @@
<input type="password" name="priv-key" placeholder="Enter Private Key" />
<input type="text" name="sid" style="display: none;" />
<input type="button" name="login" value="login" onclick="UI_evt.login();" /><br />
<input type="checkbox" name="remember-me" checked />RememberMe
<input type="checkbox" name="remember-me" checked />RememberMe <br />
<button type="button" onclick="UI_evt.signup();">Not registered? click here!</button>
</fieldset>
</form>
<div id="user-container">
@ -312,9 +336,22 @@
const UI_evt = {};
UI_evt.signup = function() {
let sid = document.forms['login-form']['sid'].value;
let privKey = prompt("Enter Private Key of floID to register: ");
signUp(privKey, sid).then(result => {
console.info(result);
alert("Account registered!")
}).catch(error => {
console.error(error)
alert(error);
});
};
UI_evt.logout = function() {
logout().then(result => {
console.warn(result);
localStorage.removeItem("proxy_secret");
location.reload();
}).catch(error => console.error(error));
};
@ -369,7 +406,7 @@
UI_evt.depositFLO = function() {
let formInputs = document.forms['deposit-withdraw-form'];
let privKey = prompt("Enter private key");
depositFLO(formInputs["quantity"].value, user_id, privKey, proxy_secret)
depositFLO(parseFloat(formInputs["quantity"].value), user_id, privKey, proxy_secret)
.then(result => console.log(result))
.catch(error => console.error(error))
.finally(_ => formInputs.reset());
@ -378,7 +415,7 @@
UI_evt.depositRupee = function() {
let formInputs = document.forms['deposit-withdraw-form'];
let privKey = prompt("Enter private key");
depositRupee(formInputs["quantity"].value, user_id, privKey, proxy_secret)
depositRupee(parseFloat(formInputs["quantity"].value), user_id, privKey, proxy_secret)
.then(result => console.log(result))
.catch(error => console.error(error))
.finally(_ => formInputs.reset());
@ -386,7 +423,7 @@
UI_evt.withdrawFLO = function() {
let formInputs = document.forms['deposit-withdraw-form'];
withdrawFLO(formInputs["quantity"].value, proxy_secret)
withdrawFLO(parseFloat(formInputs["quantity"].value), proxy_secret)
.then(result => console.log(result))
.catch(error => console.error(error))
.finally(_ => formInputs.reset());
@ -394,7 +431,7 @@
UI_evt.withdrawRupee = function() {
let formInputs = document.forms['deposit-withdraw-form'];
withdrawRupee(formInputs["quantity"].value, proxy_secret)
withdrawRupee(parseFloat(formInputs["quantity"].value), proxy_secret)
.then(result => console.log(result))
.catch(error => console.error(error))
.finally(_ => formInputs.reset());