Compare commits
8 Commits
feat/fix-m
...
fix/v2-upd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32445dbebf | ||
|
|
1a1d4901aa | ||
|
|
8b646c56dc | ||
|
|
ac38bbc72c | ||
|
|
c2eb57211f | ||
|
|
0e97df3c8e | ||
|
|
5dd0dfdc18 | ||
|
|
ef48bac8f6 |
@@ -304,6 +304,18 @@ const Accounts: FC<AccountProps> = (props) => {
|
|||||||
if (accountToUpdate) {
|
if (accountToUpdate) {
|
||||||
accountToUpdate.xrp = balance;
|
accountToUpdate.xrp = balance;
|
||||||
accountToUpdate.sequence = sequence;
|
accountToUpdate.sequence = sequence;
|
||||||
|
accountToUpdate.error = null;
|
||||||
|
} else {
|
||||||
|
const oldAccount = state.accounts.find(
|
||||||
|
(acc) => acc.address === res?.account
|
||||||
|
);
|
||||||
|
if (oldAccount) {
|
||||||
|
oldAccount.xrp = "0";
|
||||||
|
oldAccount.error = {
|
||||||
|
code: res?.error,
|
||||||
|
message: res?.error_message,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const objectRequests = snap.accounts.map((acc) => {
|
const objectRequests = snap.accounts.map((acc) => {
|
||||||
@@ -343,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"
|
||||||
@@ -431,18 +443,23 @@ const Accounts: FC<AccountProps> = (props) => {
|
|||||||
wordBreak: "break-word",
|
wordBreak: "break-word",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{account.address} (
|
{account.address}{" "}
|
||||||
{Dinero({
|
{!account?.error ? (
|
||||||
amount: Number(account?.xrp || "0"),
|
`(${Dinero({
|
||||||
precision: 6,
|
amount: Number(account?.xrp || "0"),
|
||||||
})
|
precision: 6,
|
||||||
.toUnit()
|
})
|
||||||
.toLocaleString(undefined, {
|
.toUnit()
|
||||||
style: "currency",
|
.toLocaleString(undefined, {
|
||||||
currency: "XRP",
|
style: "currency",
|
||||||
currencyDisplay: "name",
|
currency: "XRP",
|
||||||
})}
|
currencyDisplay: "name",
|
||||||
)
|
})})`
|
||||||
|
) : (
|
||||||
|
<Box css={{ color: "$red11" }}>
|
||||||
|
(Account not found, request funds to activate account)
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
</Text>
|
</Text>
|
||||||
</Box>
|
</Box>
|
||||||
{!props.hideDeployBtn && (
|
{!props.hideDeployBtn && (
|
||||||
|
|||||||
@@ -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",
|
||||||
@@ -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) {
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ export interface IAccount {
|
|||||||
hooks: string[];
|
hooks: string[];
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
version?: string;
|
version?: string;
|
||||||
|
error?: {
|
||||||
|
message: string;
|
||||||
|
code: string;
|
||||||
|
} | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ILog {
|
export interface ILog {
|
||||||
@@ -109,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