Compare commits
10 Commits
feat/updat
...
feat/tx_ha
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
704ebe4b92 | ||
|
|
d0dde56c67 | ||
|
|
45c6927e72 | ||
|
|
6014b6e79f | ||
|
|
04a99227df | ||
|
|
0965a1e898 | ||
|
|
32445dbebf | ||
|
|
1a1d4901aa | ||
|
|
8b646c56dc | ||
|
|
ac38bbc72c |
@@ -355,7 +355,7 @@ const Accounts: FC<AccountProps> = (props) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [snap.accounts, snap.clientStatus]);
|
}, [snap.accounts.length, snap.clientStatus]);
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
as="div"
|
as="div"
|
||||||
|
|||||||
@@ -6,13 +6,14 @@ import calculateHookOn, { TTS } from "../../utils/hookOnCalculator";
|
|||||||
import { SetHookData } from "../../components/SetHookDialog";
|
import { SetHookData } from "../../components/SetHookDialog";
|
||||||
import { Link } from "../../components";
|
import { Link } from "../../components";
|
||||||
import { ref } from "valtio";
|
import { ref } from "valtio";
|
||||||
|
import estimateFee from "../../utils/estimateFee";
|
||||||
|
|
||||||
export const sha256 = async (string: string) => {
|
export const sha256 = async (string: string) => {
|
||||||
const utf8 = new TextEncoder().encode(string);
|
const utf8 = new TextEncoder().encode(string);
|
||||||
const hashBuffer = await crypto.subtle.digest("SHA-256", utf8);
|
const hashBuffer = await crypto.subtle.digest("SHA-256", utf8);
|
||||||
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||||||
const hashHex = hashArray
|
const hashHex = hashArray
|
||||||
.map(bytes => bytes.toString(16).padStart(2, "0"))
|
.map((bytes) => bytes.toString(16).padStart(2, "0"))
|
||||||
.join("");
|
.join("");
|
||||||
return hashHex;
|
return hashHex;
|
||||||
};
|
};
|
||||||
@@ -72,12 +73,12 @@ export const deployHook = async (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const HookNamespace = (await sha256(data.HookNamespace)).toUpperCase();
|
const HookNamespace = (await sha256(data.HookNamespace)).toUpperCase();
|
||||||
const hookOnValues: (keyof TTS)[] = data.Invoke.map(tt => tt.value);
|
const hookOnValues: (keyof TTS)[] = data.Invoke.map((tt) => tt.value);
|
||||||
const { HookParameters } = data;
|
const { HookParameters } = data;
|
||||||
const filteredHookParameters = HookParameters.filter(
|
const filteredHookParameters = HookParameters.filter(
|
||||||
hp =>
|
(hp) =>
|
||||||
hp.HookParameter.HookParameterName && hp.HookParameter.HookParameterValue
|
hp.HookParameter.HookParameterName && hp.HookParameter.HookParameterValue
|
||||||
)?.map(aa => ({
|
)?.map((aa) => ({
|
||||||
HookParameter: {
|
HookParameter: {
|
||||||
HookParameterName: toHex(aa.HookParameter.HookParameterName || ""),
|
HookParameterName: toHex(aa.HookParameter.HookParameterName || ""),
|
||||||
HookParameterValue: aa.HookParameter.HookParameterValue || "",
|
HookParameterValue: aa.HookParameter.HookParameterValue || "",
|
||||||
@@ -119,14 +120,22 @@ export const deployHook = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
const keypair = derive.familySeed(account.secret);
|
const keypair = derive.familySeed(account.secret);
|
||||||
|
try {
|
||||||
|
// Update tx Fee value with network estimation
|
||||||
|
await estimateFee(tx, keypair);
|
||||||
|
} catch (err) {
|
||||||
|
// use default value what you defined earlier
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
const { signedTransaction } = sign(tx, keypair);
|
const { signedTransaction } = sign(tx, keypair);
|
||||||
const currentAccount = state.accounts.find(
|
const currentAccount = state.accounts.find(
|
||||||
acc => acc.address === account.address
|
(acc) => acc.address === account.address
|
||||||
);
|
);
|
||||||
if (currentAccount) {
|
if (currentAccount) {
|
||||||
currentAccount.isLoading = true;
|
currentAccount.isLoading = true;
|
||||||
}
|
}
|
||||||
let submitRes;
|
let submitRes;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
submitRes = await state.client.send({
|
submitRes = await state.client.send({
|
||||||
command: "submit",
|
command: "submit",
|
||||||
@@ -143,14 +152,14 @@ export const deployHook = async (
|
|||||||
message: ref(
|
message: ref(
|
||||||
<>
|
<>
|
||||||
[{submitRes.engine_result}] {submitRes.engine_result_message}{" "}
|
[{submitRes.engine_result}] {submitRes.engine_result_message}{" "}
|
||||||
Validated ledger index:{" "}
|
Transaction hash:{" "}
|
||||||
<Link
|
<Link
|
||||||
as="a"
|
as="a"
|
||||||
href={`https://${process.env.NEXT_PUBLIC_EXPLORER_URL}/${submitRes.validated_ledger_index}`}
|
href={`https://${process.env.NEXT_PUBLIC_EXPLORER_URL}/${submitRes.tx_json?.hash}`}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
>
|
>
|
||||||
{submitRes.validated_ledger_index}
|
{submitRes.tx_json?.hash}
|
||||||
</Link>
|
</Link>
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
@@ -183,7 +192,7 @@ export const deleteHook = async (account: IAccount & { name?: string }) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const currentAccount = state.accounts.find(
|
const currentAccount = state.accounts.find(
|
||||||
acc => acc.address === account.address
|
(acc) => acc.address === account.address
|
||||||
);
|
);
|
||||||
if (currentAccount?.isLoading || !currentAccount?.hooks.length) {
|
if (currentAccount?.isLoading || !currentAccount?.hooks.length) {
|
||||||
return;
|
return;
|
||||||
@@ -205,6 +214,13 @@ export const deleteHook = async (account: IAccount & { name?: string }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const keypair = derive.familySeed(account.secret);
|
const keypair = derive.familySeed(account.secret);
|
||||||
|
try {
|
||||||
|
// Update tx Fee value with network estimation
|
||||||
|
await estimateFee(tx, keypair);
|
||||||
|
} catch (err) {
|
||||||
|
// use default value what you defined earlier
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
const { signedTransaction } = sign(tx, keypair);
|
const { signedTransaction } = sign(tx, keypair);
|
||||||
|
|
||||||
if (currentAccount) {
|
if (currentAccount) {
|
||||||
|
|||||||
@@ -24,10 +24,7 @@ export const sendTransaction = async (account: IAccount, txOptions: TransactionO
|
|||||||
Fee, // TODO auto-fillable
|
Fee, // TODO auto-fillable
|
||||||
...opts
|
...opts
|
||||||
};
|
};
|
||||||
const currAcc = state.accounts.find(acc => acc.address === account.address);
|
|
||||||
if (currAcc) {
|
|
||||||
currAcc.sequence = account.sequence + 1;
|
|
||||||
}
|
|
||||||
const { logPrefix = '' } = options || {}
|
const { logPrefix = '' } = options || {}
|
||||||
try {
|
try {
|
||||||
const signedAccount = derive.familySeed(account.secret);
|
const signedAccount = derive.familySeed(account.secret);
|
||||||
@@ -47,6 +44,10 @@ export const sendTransaction = async (account: IAccount, txOptions: TransactionO
|
|||||||
message: `${logPrefix}[${response.error || response.engine_result}] ${response.error_exception || response.engine_result_message}`,
|
message: `${logPrefix}[${response.error || response.engine_result}] ${response.error_exception || response.engine_result_message}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
const currAcc = state.accounts.find(acc => acc.address === account.address);
|
||||||
|
if (currAcc && response.account_sequence_next) {
|
||||||
|
currAcc.sequence = response.account_sequence_next;
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
state.transactionLogs.push({
|
state.transactionLogs.push({
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ let initialState: IState = {
|
|||||||
accounts: [],
|
accounts: [],
|
||||||
compileOptions: {
|
compileOptions: {
|
||||||
optimizationLevel: '-O0',
|
optimizationLevel: '-O0',
|
||||||
strip: false
|
strip: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
20
utils/estimateFee.ts
Normal file
20
utils/estimateFee.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { sign, XRPL_Account } from "xrpl-accountlib"
|
||||||
|
import state from "../state"
|
||||||
|
|
||||||
|
// Mutate tx object with network estimated fee value
|
||||||
|
const estimateFee = async (tx: Record<string, unknown>, keypair: XRPL_Account): Promise<null | { base_fee: string, median_fee: string; minimum_fee: string; open_ledger_fee: string; }> => {
|
||||||
|
const copyTx = JSON.parse(JSON.stringify(tx))
|
||||||
|
delete copyTx['SigningPubKey']
|
||||||
|
const { signedTransaction } = sign(copyTx, keypair);
|
||||||
|
try {
|
||||||
|
const res = await state.client?.send({ command: 'fee', tx_blob: signedTransaction })
|
||||||
|
if (res && res.drops) {
|
||||||
|
return tx['Fee'] = res.drops.base_fee;
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
} catch (err) {
|
||||||
|
throw Error('Cannot estimate fee')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default estimateFee
|
||||||
Reference in New Issue
Block a user