Skip to content

Commit

Permalink
add debug code
Browse files Browse the repository at this point in the history
  • Loading branch information
djeck1432 committed Sep 26, 2024
1 parent 2a3ce6a commit b5b190f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
5 changes: 3 additions & 2 deletions web_app/api/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ async def get_transaction_data(
:param transaction_data: Pydantic model for the query parameters
:return: List of dicts containing the transaction data
"""
print("transaction_data", transaction_data)
wallet_id = request.session.get("wallet_id")
if not wallet_id:
return RedirectResponse(url="/login", status_code=302)
Expand All @@ -108,5 +109,5 @@ async def get_transaction_data(
response = TransactionDataResponse(
approve_data=approve_data, loop_liquidity_data=loop_liquidity_data
)

return [response]
print("response", response.dict())
return [response.dict()]
3 changes: 0 additions & 3 deletions web_app/static/js/form.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
console.log("JavaScript is loaded");
alert("JavaScript is working!");

// Update max balance based on the selected token
function updateMaxBalance() {
const selectedToken = document.getElementById('token').value;
Expand Down
37 changes: 30 additions & 7 deletions web_app/static/js/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ async function logout() {

async function sendTransaction(transactionData) {
try {
console.log("Transaction Data:", transactionData);

const starknet = window.starknet;
if (!starknet) {
alert("Please connect to the Argent X wallet.");
Expand All @@ -52,21 +54,42 @@ async function sendTransaction(transactionData) {
const approveData = transactionData[0].approve_data;
const loopLiquidityData = transactionData[0].loop_liquidity_data;

// Log the extracted data for debugging
console.log("Approve Data:", approveData.to_address);
console.log("Loop Liquidity Data:", loopLiquidityData["pool_key"]);

// Construct transaction details based on approve data
const transactionDetails = {
const approveTransaction = {
contractAddress: approveData.to_address,
entrypoint: "approve",
calldata: [
approveData.spender,
approveData.amount,
approveData.spender, // spender address
approveData.amount // approval amount
],
};

// Send the "approve" transaction
const approveResponse = await starknet.provider.invokeFunction(approveTransaction);
console.log("Approve transaction response:", approveResponse);

// Construct the second transaction for liquidity deposit
const depositTransaction = {
contractAddress: loopLiquidityData.pool_key.token0,
entrypoint: "deposit",
calldata: [
loopLiquidityData.pool_key.token0, // token0 address
loopLiquidityData.pool_key.token1, // token1 address
loopLiquidityData.deposit_data.amount, // deposit amount
loopLiquidityData.deposit_data.multiplier // multiplier
],
};

// Send the transaction via the Starknet provider
const response = await starknet.provider.invokeFunction(transactionDetails);
console.log("Transaction response:", response);
// Send the "deposit" transaction
const depositResponse = await starknet.provider.invokeFunction(depositTransaction);
console.log("Deposit transaction response:", depositResponse);

alert(`Transaction sent. Hash: ${response.transaction_hash}`);
// Alert the user with the transaction hash
alert(`Transactions sent. Approve Hash: ${approveResponse.transaction_hash}, Deposit Hash: ${depositResponse.transaction_hash}`);
} catch (error) {
console.error("Error sending transaction:", error);
alert("An error occurred while sending the transaction.");
Expand Down

0 comments on commit b5b190f

Please sign in to comment.