diff --git a/djed-sdk/dist/esm/index.js b/djed-sdk/dist/esm/index.js index f030428..0baac43 100644 --- a/djed-sdk/dist/esm/index.js +++ b/djed-sdk/dist/esm/index.js @@ -156,7 +156,7 @@ const CONFIRMATION_WAIT_PERIOD = REFRESH_PERIOD + 1000; const scalingFactor = decimalUnscaling("1", SCALING_DECIMALS); const FEE_UI_UNSCALED = decimalUnscaling( (FEE_UI / 100).toString(), - SCALING_DECIMALS + SCALING_DECIMALS, ); const tradeDataPriceCore = (djed, method, decimals, amountScaled) => { const amountUnscaled = decimalUnscaling(amountScaled, decimals); @@ -166,7 +166,7 @@ const tradeDataPriceCore = (djed, method, decimals, amountScaled) => { const totalUnscaled = convertToBC( amountUnscaled, priceUnscaled, - decimals + decimals, ).toString(); const totalScaled = decimalScaling(totalUnscaled, BC_DECIMALS); @@ -179,7 +179,7 @@ const tradeDataPriceCore = (djed, method, decimals, amountScaled) => { priceUnscaled, priceScaled, }; - } + }, ); }; @@ -259,14 +259,33 @@ const isTxLimitReached = (amountUSD, totalSCSupply, thresholdSCSupply) => amountUSD > TRANSACTION_USD_LIMIT && BigInt(totalSCSupply) >= BigInt(thresholdSCSupply); -const promiseTx = (isWalletConnected, tx, signer) => { +const promiseTx = (isWalletConnected, tx, web3) => { if (!isWalletConnected) { return Promise.reject(new Error("Metamask not connected!")); } - if (!signer) { - return Promise.reject(new Error("Couldn't get Signer")); + + if (!web3 || !web3.eth) { + return Promise.reject(new Error("Web3 instance not provided")); + } + + if (!tx?.from) { + return Promise.reject(new Error("Transaction 'from' address is required")); } - return signer.sendTransaction(tx); + + const selectedGas = tx.gas ?? tx.gasLimit ?? 500000; + + return new Promise((resolve, reject) => { + web3.eth + .sendTransaction({ + from: tx.from, + to: tx.to, + value: tx.value, + data: tx.data, + gas: selectedGas, + }) + .on("receipt", resolve) + .on("error", reject); + }); }; const verifyTx = (web3, hash) => { diff --git a/djed-sdk/dist/umd/index.js b/djed-sdk/dist/umd/index.js index 24bf322..caa765c 100644 --- a/djed-sdk/dist/umd/index.js +++ b/djed-sdk/dist/umd/index.js @@ -160,7 +160,7 @@ const scalingFactor = decimalUnscaling("1", SCALING_DECIMALS); const FEE_UI_UNSCALED = decimalUnscaling( (FEE_UI / 100).toString(), - SCALING_DECIMALS + SCALING_DECIMALS, ); const tradeDataPriceCore = (djed, method, decimals, amountScaled) => { const amountUnscaled = decimalUnscaling(amountScaled, decimals); @@ -170,7 +170,7 @@ const totalUnscaled = convertToBC( amountUnscaled, priceUnscaled, - decimals + decimals, ).toString(); const totalScaled = decimalScaling(totalUnscaled, BC_DECIMALS); @@ -183,7 +183,7 @@ priceUnscaled, priceScaled, }; - } + }, ); }; @@ -263,14 +263,33 @@ amountUSD > TRANSACTION_USD_LIMIT && BigInt(totalSCSupply) >= BigInt(thresholdSCSupply); - const promiseTx = (isWalletConnected, tx, signer) => { + const promiseTx = (isWalletConnected, tx, web3) => { if (!isWalletConnected) { return Promise.reject(new Error("Metamask not connected!")); } - if (!signer) { - return Promise.reject(new Error("Couldn't get Signer")); + + if (!web3 || !web3.eth) { + return Promise.reject(new Error("Web3 instance not provided")); + } + + if (!tx?.from) { + return Promise.reject(new Error("Transaction 'from' address is required")); } - return signer.sendTransaction(tx); + + const selectedGas = tx.gas ?? tx.gasLimit ?? 500000; + + return new Promise((resolve, reject) => { + web3.eth + .sendTransaction({ + from: tx.from, + to: tx.to, + value: tx.value, + data: tx.data, + gas: selectedGas, + }) + .on("receipt", resolve) + .on("error", reject); + }); }; const verifyTx = (web3, hash) => { diff --git a/djed-sdk/src/djed/tradeUtils.js b/djed-sdk/src/djed/tradeUtils.js index 456f1f1..b439e8b 100644 --- a/djed-sdk/src/djed/tradeUtils.js +++ b/djed-sdk/src/djed/tradeUtils.js @@ -15,7 +15,7 @@ import { export const scalingFactor = decimalUnscaling("1", SCALING_DECIMALS); export const FEE_UI_UNSCALED = decimalUnscaling( (FEE_UI / 100).toString(), - SCALING_DECIMALS + SCALING_DECIMALS, ); export const tradeDataPriceCore = (djed, method, decimals, amountScaled) => { const amountUnscaled = decimalUnscaling(amountScaled, decimals); @@ -25,7 +25,7 @@ export const tradeDataPriceCore = (djed, method, decimals, amountScaled) => { const totalUnscaled = convertToBC( amountUnscaled, priceUnscaled, - decimals + decimals, ).toString(); const totalScaled = decimalScaling(totalUnscaled, BC_DECIMALS); @@ -38,7 +38,7 @@ export const tradeDataPriceCore = (djed, method, decimals, amountScaled) => { priceUnscaled, priceScaled, }; - } + }, ); }; @@ -118,14 +118,33 @@ export const isTxLimitReached = (amountUSD, totalSCSupply, thresholdSCSupply) => amountUSD > TRANSACTION_USD_LIMIT && BigInt(totalSCSupply) >= BigInt(thresholdSCSupply); -export const promiseTx = (isWalletConnected, tx, signer) => { +export const promiseTx = (isWalletConnected, tx, web3) => { if (!isWalletConnected) { return Promise.reject(new Error("Metamask not connected!")); } - if (!signer) { - return Promise.reject(new Error("Couldn't get Signer")); + + if (!web3 || !web3.eth) { + return Promise.reject(new Error("Web3 instance not provided")); + } + + if (!tx?.from) { + return Promise.reject(new Error("Transaction 'from' address is required")); } - return signer.sendTransaction(tx); + + const selectedGas = tx.gas ?? tx.gasLimit ?? 500000; + + return new Promise((resolve, reject) => { + web3.eth + .sendTransaction({ + from: tx.from, + to: tx.to, + value: tx.value, + data: tx.data, + gas: selectedGas, + }) + .on("receipt", resolve) + .on("error", reject); + }); }; export const verifyTx = (web3, hash) => {