Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions djed-sdk/src/djed/tradeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -38,7 +38,7 @@ export const tradeDataPriceCore = (djed, method, decimals, amountScaled) => {
priceUnscaled,
priceScaled,
};
}
},
);
};

Expand Down Expand Up @@ -118,14 +118,22 @@ 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"));
}
return signer.sendTransaction(tx);

return web3.eth.sendTransaction({
from: tx.from,
to: tx.to,
value: tx.value,
data: tx.data,
gas: tx.gasLimit || 500000,
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
};

export const verifyTx = (web3, hash) => {
Expand Down