Update with transfer nfts.

This commit is contained in:
Dennis Dawson
2025-05-23 14:17:56 -07:00
parent 08f2fde9e4
commit cc10aa0f94
5 changed files with 709 additions and 1101 deletions

View File

@@ -38,8 +38,6 @@ async function createSellOffer() {
transactionJson.Destination = destination; transactionJson.Destination = destination;
} }
console.log("Creating Sell Offer Transaction:", JSON.stringify(transactionJson, null, 2));
const tx = await client.submitAndWait(transactionJson, { wallet }); const tx = await client.submitAndWait(transactionJson, { wallet });
results += `\nSell offer created successfully!\nTransaction Hash: ${tx.result.hash}\nEngine Result: ${tx.result.engine_result}`; results += `\nSell offer created successfully!\nTransaction Hash: ${tx.result.hash}\nEngine Result: ${tx.result.engine_result}`;
resultField.value = results; resultField.value = results;
@@ -69,7 +67,6 @@ async function createBuyOffer() {
try { try {
// Use the external configureAmount() function // Use the external configureAmount() function
let amount = configureAmount(); let amount = configureAmount();
console.log("Amount:", amount);
// Use the external configureExpiration() function // Use the external configureExpiration() function
let expiration = configureExpiration(); // This will return a number or an empty string from the original logic let expiration = configureExpiration(); // This will return a number or an empty string from the original logic
@@ -100,8 +97,6 @@ console.log("Amount:", amount);
transactionJson.Expiration = expiration; transactionJson.Expiration = expiration;
} }
console.log("Buy Offer Transaction JSON:\n" + JSON.stringify(transactionJson, null, 2));
const tx = await client.submitAndWait(transactionJson, { wallet: wallet }); const tx = await client.submitAndWait(transactionJson, { wallet: wallet });
results += "\n\n=== Sell Offers ===\n"; results += "\n\n=== Sell Offers ===\n";
@@ -166,7 +161,7 @@ async function cancelOffer() {
// Submit transaction -------------------------------------------------------- // Submit transaction --------------------------------------------------------
const tx = await client.submitAndWait(transactionJson, { wallet }) const tx = await client.submitAndWait(transactionJson, { wallet })
results += "\n\n=== Sell Offers===\n" results = "\n\n=== Sell Offers===\n"
let nftSellOffers let nftSellOffers
try { try {
nftSellOffers = await client.request({ nftSellOffers = await client.request({
@@ -174,7 +169,7 @@ async function cancelOffer() {
nft_id: nftIdField.value nft_id: nftIdField.value
}) })
} catch (err) { } catch (err) {
nftSellOffers = "=== No sell offers. ===" nftSellOffers = '=== No sell offers. ===\n'
} }
results += JSON.stringify(nftSellOffers, null, 2) results += JSON.stringify(nftSellOffers, null, 2)
results += "\n\n=== Buy Offers ===\n" results += "\n\n=== Buy Offers ===\n"
@@ -184,18 +179,20 @@ async function cancelOffer() {
method: "nft_buy_offers", method: "nft_buy_offers",
nft_id: nftIdField.value nft_id: nftIdField.value
}) })
results += JSON.stringify(nftBuyOffers, null, 2)
} catch (err) { } catch (err) {
nftBuyOffers = '=== No buy offers. ===' nftBuyOffers = '=== No buy offers. ==='
} }
results += JSON.stringify(nftBuyOffers, null, 2)
resultField.value += results
// Check transaction results ------------------------------------------------- // Check transaction results -------------------------------------------------
results += "\n=== Transaction result:\n" + results = "\n=== Transaction result:\n" +
JSON.stringify(tx.result.meta.TransactionResult, null, 2) JSON.stringify(tx.result.meta.TransactionResult, null, 2)
results += "\n=== Balance changes:\n" + results += "\n\n=== Balance changes:\n" +
JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2) JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
resultField.value = results resultField.value += results
client.disconnect() // End of cancelOffer() client.disconnect() // End of cancelOffer()
} }
@@ -228,7 +225,7 @@ async function getOffers() {
resultField.value = results resultField.value = results
// --- Buy Offers --- // --- Buy Offers ---
results += '\n\n=== Buy Offers ===\n' results = '\n\n=== Buy Offers ===\n'
let nftBuyOffers let nftBuyOffers
try { try {
nftBuyOffers = await client.request({ nftBuyOffers = await client.request({
@@ -240,7 +237,7 @@ async function getOffers() {
nftBuyOffers = 'No buy offers found for this NFT ID.' // More descriptive nftBuyOffers = 'No buy offers found for this NFT ID.' // More descriptive
} }
results += JSON.stringify(nftBuyOffers, null, 2) // Append the JSON string results += JSON.stringify(nftBuyOffers, null, 2) // Append the JSON string
resultField.value = results // Update the display with buy offers resultField.value += results // Update the display with buy offers
client.disconnect() client.disconnect()
}// End of getOffers() }// End of getOffers()
@@ -253,6 +250,7 @@ async function acceptSellOffer() {
const wallet = xrpl.Wallet.fromSeed(accountSeedField.value) const wallet = xrpl.Wallet.fromSeed(accountSeedField.value)
let net = getNet() let net = getNet()
const client = new xrpl.Client(net) const client = new xrpl.Client(net)
try {
await client.connect() await client.connect()
let results = '\n=== Connected. Accepting sell offer. ===\n\n' let results = '\n=== Connected. Accepting sell offer. ===\n\n'
resultField.value = results resultField.value = results
@@ -281,8 +279,12 @@ async function acceptSellOffer() {
results += JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2) results += JSON.stringify(xrpl.getBalanceChanges(tx.result.meta), null, 2)
results += JSON.stringify(nfts, null, 2) results += JSON.stringify(nfts, null, 2)
resultField.value = results resultField.value = results
} catch (error) {
console.error('Error accepting sell offer:', error)
resultField.value = `Error: ${error.message || error}`
} finally {
client.disconnect() client.disconnect()
}
}// End of acceptSellOffer() }// End of acceptSellOffer()
// ******************************************************* // *******************************************************

Binary file not shown.

After

Width:  |  Height:  |  Size: 371 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 KiB

File diff suppressed because it is too large Load Diff