From 0f92626ebc64fc9109f30a8da13c940d39768905 Mon Sep 17 00:00:00 2001 From: jonathanlei Date: Sun, 6 Nov 2022 17:44:15 -0800 Subject: [PATCH] fix memos format --- assets/js/test-net.js | 153 +++++++++++++++++++++++++----------------- 1 file changed, 93 insertions(+), 60 deletions(-) diff --git a/assets/js/test-net.js b/assets/js/test-net.js index ce1f76f39a..1bd0c77dca 100644 --- a/assets/js/test-net.js +++ b/assets/js/test-net.js @@ -1,48 +1,48 @@ async function wait_for_seq(network_url, address) { - const api = new xrpl.Client(network_url) - await api.connect() + const api = new xrpl.Client(network_url); + await api.connect(); let response; while (true) { try { response = await api.request({ command: "account_info", account: address, - ledger_index: "validated" - }) - break - } catch(e) { - await new Promise(resolve => setTimeout(resolve, 1000)) + ledger_index: "validated", + }); + break; + } catch (e) { + await new Promise((resolve) => setTimeout(resolve, 1000)); } } - console.log(response) - $("#sequence").html('

Sequence Number

'+response.result.account_data.Sequence) + console.log(response); + $("#sequence").html( + "

Sequence Number

" + response.result.account_data.Sequence + ); $("#balance").html( "

Balance

" + (Number(response.result.account_data.Balance) * 0.000001).toLocaleString( "en" ) + " XRP" - ) - api.disconnect() + ); + api.disconnect(); } - function rippleTestNetCredentials(url, altnet_name) { - - const credentials = $('#your-credentials') - const address = $('#address') - const secret = $('#secret') - const balance = $('#balance') - const sequence = $('#sequence') - const loader = $('#loader') + const credentials = $("#your-credentials"); + const address = $("#address"); + const secret = $("#secret"); + const balance = $("#balance"); + const sequence = $("#sequence"); + const loader = $("#loader"); //reset the fields initially and for re-generation - credentials.hide() - address.html('') - secret.html('') - balance.html('') - sequence.html('') - loader.css('display', 'inline') + credentials.hide(); + address.html(""); + secret.html(""); + balance.html(""); + sequence.html(""); + loader.css("display", "inline"); // generate the test wallet const test_wallet = xrpl.Wallet.generate(); @@ -50,61 +50,94 @@ function rippleTestNetCredentials(url, altnet_name) { //call the alt-net and get key generations $.ajax({ url: url, - type: 'POST', + type: "POST", contentType: "application/json; charset=utf-8", data: JSON.stringify({ destination: test_wallet.address, memos: [ { - Memo: { - MemoData: xrpl.convertStringToHex("xrpl.org-faucet"), - }, + data: xrpl.convertStringToHex("xrpl.org-faucet"), }, ], }), - success: function(data) { + success: function (data) { //hide the loader and show results loader.hide(); - credentials.hide().html('

Your '+altnet_name+' Credentials

').fadeIn('fast') - address.hide().html('

Address

' + - test_wallet.address).fadeIn('fast') - secret.hide().html('

Secret

' + - test_wallet.seed).fadeIn('fast') - // TODO: currently the faucet api doesn't return balance unless the account is generated server side, need to make upates when faucet repo is updated. - balance.hide().html('

Balance

' + - Number(data.amount).toLocaleString('en') + ' XRP').fadeIn('fast') - sequence.html('

Sequence

Waiting...').fadeIn('fast') - if (altnet_name=="Testnet") { - wait_for_seq("wss://s.altnet.rippletest.net:51233", test_wallet.address) - } else if (altnet_name=="NFT-Devnet") { - wait_for_seq("wss://xls20-sandbox.rippletest.net:51233", test_wallet.address) + credentials + .hide() + .html("

Your " + altnet_name + " Credentials

") + .fadeIn("fast"); + address + .hide() + .html("

Address

" + test_wallet.address) + .fadeIn("fast"); + secret + .hide() + .html("

Secret

" + test_wallet.seed) + .fadeIn("fast"); + // TODO: currently the faucet api doesn't return balance unless the account is generated server side, need to make upates when faucet repo is updated. + balance + .hide() + .html( + "

Balance

" + + Number(data.amount).toLocaleString("en") + + " XRP" + ) + .fadeIn("fast"); + sequence + .html( + '

Sequence

Waiting...' + ) + .fadeIn("fast"); + if (altnet_name == "Testnet") { + wait_for_seq( + "wss://s.altnet.rippletest.net:51233", + test_wallet.address + ); + } else if (altnet_name == "NFT-Devnet") { + wait_for_seq( + "wss://xls20-sandbox.rippletest.net:51233", + test_wallet.address + ); } else { - wait_for_seq("wss://s.devnet.rippletest.net:51233", test_wallet.address) + wait_for_seq( + "wss://s.devnet.rippletest.net:51233", + test_wallet.address + ); } - }, - error: function() { + error: function () { loader.hide(); - alert("There was an error with the "+altnet_name+" faucet. Please try again."); - } - }) + alert( + "There was an error with the " + + altnet_name + + " faucet. Please try again." + ); + }, + }); } -$(document).ready(function() { +$(document).ready(function () { function testnet_click(evt) { - rippleTestNetCredentials("https://faucet.altnet.rippletest.net/accounts", - "Testnet") + rippleTestNetCredentials( + "https://faucet.altnet.rippletest.net/accounts", + "Testnet" + ); } function devnet_click(evt) { - rippleTestNetCredentials("https://faucet.devnet.rippletest.net/accounts", - "Devnet") + rippleTestNetCredentials( + "https://faucet.devnet.rippletest.net/accounts", + "Devnet" + ); } function nftnet_click(evt) { - rippleTestNetCredentials("https://faucet-nft.ripple.com/accounts", - "NFT-Devnet") + rippleTestNetCredentials( + "https://faucet-nft.ripple.com/accounts", + "NFT-Devnet" + ); } - $('#testnet-creds-button').click(testnet_click) - $('#devnet-creds-button').click(devnet_click) - $('#nftnet-creds-button').click(nftnet_click) -}) + $("#testnet-creds-button").click(testnet_click); + $("#devnet-creds-button").click(devnet_click); + $("#nftnet-creds-button").click(nftnet_click); +});