-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Revise payment tutorials, add/remove screenshots #3091
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5bb552d
Revise payment tutorials, add/remove screenshots
DennisDawson b598a60
Updates based on feedback
DennisDawson 1ae3992
Merge branch 'master' into refactor_payment_modular_tuts
DennisDawson dba9871
minor changes, mostly to try and kick a new build
DennisDawson e570110
change to kick off a build
DennisDawson c7a11da
Fix bad image link
DennisDawson ec1f33d
Merge branch 'master' into refactor_payment_modular_tuts
DennisDawson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
// ****************************************************** | ||
// ************* Get the Preferred Network ************** | ||
// ****************************************************** | ||
|
||
function getNet() { | ||
let net | ||
if (document.getElementById("tn").checked) net = "wss://s.altnet.rippletest.net:51233/" | ||
if (document.getElementById("dn").checked) net = "wss://s.devnet.rippletest.net:51233/" | ||
return net | ||
} // End of getNet() | ||
|
||
// ******************************************************* | ||
// ************* Get Account ***************************** | ||
// ******************************************************* | ||
|
||
async function getAccount() { | ||
let net = getNet() | ||
const client = new xrpl.Client(net) | ||
await client.connect() | ||
resultField.value = `===Getting Account===\n\nConnected to ${net}.` | ||
try { | ||
let faucetHost = null | ||
const my_wallet = (await client.fundWallet(null, { faucetHost})).wallet | ||
const newAccount = [my_wallet.address, my_wallet.seed] | ||
return (newAccount) | ||
} | ||
catch (error) { | ||
console.error('===Error getting account:', error); | ||
results += `\nError: ${error.message}\n` | ||
resultField.value = results | ||
throw error; // Re-throw the error to be handled by the caller | ||
} | ||
finally { | ||
// Disconnect from the client | ||
await client.disconnect(); | ||
} | ||
} // End of getAccount() | ||
|
||
async function getNewAccount1() { | ||
account1address.value = "=== Getting new account. ===\n\n" | ||
account1seed.value = "" | ||
const accountInfo= await getAccount() | ||
account1address.value = accountInfo[0] | ||
account1seed.value = accountInfo[1] | ||
} | ||
|
||
async function getNewAccount2() { | ||
account2address.value = "=== Getting new account. ===\n\n" | ||
account2seed.value = "" | ||
const accountInfo= await getAccount() | ||
account2address.value = accountInfo[0] | ||
account2seed.value = accountInfo[1] | ||
} | ||
|
||
// ***************************************************** | ||
// ********** Get Account from Seed ******************** | ||
// ***************************************************** | ||
|
||
async function getAccountFromSeed(my_seed) { | ||
const net = getNet() | ||
const client = new xrpl.Client(net) | ||
await client.connect() | ||
let results = '===Finding wallet.===\n\n' | ||
resultField.value = results | ||
try { | ||
const wallet = xrpl.Wallet.fromSeed(my_seed) | ||
const address = wallet.address | ||
results += "===Wallet found.===\n\n" | ||
results += "Account address: " + address + "\n\n" | ||
resultField.value = results | ||
return (address) | ||
} | ||
catch (error) { | ||
console.error('===Error getting account from seed:', error); | ||
results += `\nError: ${error.message}\n` | ||
resultField.value = results | ||
throw error; // Re-throw the error to be handled by the caller | ||
} | ||
finally { | ||
// Disconnect from the client | ||
await client.disconnect(); | ||
} | ||
} // End of getAccountFromSeed() | ||
|
||
// ***************************************************** | ||
// ********** Get Account from Seed1 ******************* | ||
// ***************************************************** | ||
|
||
async function getAccountFromSeed1() { | ||
account1address.value = await getAccountFromSeed(account1seed.value) | ||
} | ||
|
||
// ***************************************************** | ||
// ********** Get Account from Seed2 ******************* | ||
// ***************************************************** | ||
|
||
async function getAccountFromSeed2() { | ||
account2address.value = await getAccountFromSeed(account2seed.value) | ||
} | ||
|
||
// ***************************************************** | ||
// ************ Gather Account Info ******************** | ||
// ***************************************************** | ||
|
||
function gatherAccountInfo() { | ||
let accountData = account1name.value + "\n" + account1address.value + "\n" + account1seed.value + "\n" | ||
accountData += account2name.value + "\n" + account2address.value + "\n" + account2seed.value | ||
resultField.value = accountData | ||
} | ||
|
||
// ***************************************************** | ||
// ********** Distribute Account Info ****************** | ||
// ***************************************************** | ||
|
||
function distributeAccountInfo() { | ||
let accountInfo = resultField.value.split("\n") | ||
account1name.value = accountInfo[0] | ||
account1address.value = accountInfo[1] | ||
account1seed.value = accountInfo[2] | ||
account2name.value = accountInfo[3] | ||
account2address.value = accountInfo[4] | ||
account2seed.value = accountInfo[5] | ||
} | ||
|
||
// ***************************************************** | ||
// ************ Populate Active Form 1 ***************** | ||
// ***************************************************** | ||
|
||
function populate1() { | ||
accountNameField.value = account1name.value | ||
accountAddressField.value = account1address.value | ||
accountSeedField.value = account1seed.value | ||
getXrpBalance() | ||
} | ||
|
||
// ***************************************************** | ||
// ************ Populate Active Form 2 ***************** | ||
// ***************************************************** | ||
|
||
function populate2() { | ||
accountNameField.value = account2name.value | ||
accountAddressField.value = account2address.value | ||
accountSeedField.value = account2seed.value | ||
getXrpBalance() | ||
} | ||
|
||
// ******************************************************* | ||
// **************** Get XRP Balance ********************* | ||
// ******************************************************* | ||
|
||
async function getXrpBalance() { | ||
const net = getNet() | ||
const client = new xrpl.Client(net) | ||
await client.connect() | ||
let results = `\n===Getting XRP balance...===\n\n` | ||
resultField.value = results | ||
try { | ||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value) | ||
const balance = await client.getXrpBalance(wallet.address) | ||
results += accountNameField.value + " current XRP balance: " + balance + "\n\n" | ||
xrpBalanceField.value = await client.getXrpBalance(accountAddressField.value) | ||
resultField.value = results | ||
} | ||
catch (error) { | ||
console.error('Error getting XRP balance:', error); | ||
results += `\nError: ${error.message}\n` | ||
resultField.value = results | ||
throw error; // Re-throw the error to be handled by the caller | ||
} | ||
finally { | ||
// Disconnect from the client | ||
await client.disconnect(); | ||
} | ||
} // End of getXrpBalance() | ||
|
||
// ******************************************************* | ||
// ************** Get Token Balance ********************* | ||
// ******************************************************* | ||
|
||
async function getTokenBalance() { | ||
let net = getNet() | ||
const client = new xrpl.Client(net) | ||
await client.connect() | ||
let results = `===Connected to ${net}.===\n===Getting account token balance...===\n\n` | ||
resultField.value += results | ||
try { | ||
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value) | ||
const balance = await client.request({ | ||
command: "gateway_balances", | ||
account: wallet.address, | ||
ledger_index: "validated", | ||
}) | ||
results = accountNameField.value + "\'s token balance(s): " + JSON.stringify(balance.result, null, 2) + "\n" | ||
resultField.value += results | ||
xrpBalanceField.value = (await client.getXrpBalance(wallet.address)) | ||
} | ||
catch (error) { | ||
console.error('Error getting token balance:', error); | ||
results = `\nError: ${error.message}\n` | ||
resultField.value += results | ||
throw error; // Re-throw the error to be handled by the caller | ||
} | ||
finally { | ||
// Disconnect from the client | ||
await client.disconnect(); | ||
} | ||
} // End of getTokenBalance() | ||
|
||
DennisDawson marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.