Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
33 changes: 26 additions & 7 deletions djed-sdk/dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -166,7 +166,7 @@ const tradeDataPriceCore = (djed, method, decimals, amountScaled) => {
const totalUnscaled = convertToBC(
amountUnscaled,
priceUnscaled,
decimals
decimals,
).toString();

const totalScaled = decimalScaling(totalUnscaled, BC_DECIMALS);
Expand All @@ -179,7 +179,7 @@ const tradeDataPriceCore = (djed, method, decimals, amountScaled) => {
priceUnscaled,
priceScaled,
};
}
},
);
};

Expand Down Expand Up @@ -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) => {
Expand Down
33 changes: 26 additions & 7 deletions djed-sdk/dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -170,7 +170,7 @@
const totalUnscaled = convertToBC(
amountUnscaled,
priceUnscaled,
decimals
decimals,
).toString();

const totalScaled = decimalScaling(totalUnscaled, BC_DECIMALS);
Expand All @@ -183,7 +183,7 @@
priceUnscaled,
priceScaled,
};
}
},
);
};

Expand Down Expand Up @@ -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) => {
Expand Down
33 changes: 26 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,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) => {
Expand Down