Compare commits

..

10 Commits

Author SHA1 Message Date
muzam1l
704ebe4b92 Show tx hash instead of server ledger index in deploy log. 2022-05-26 14:55:24 +05:30
Valtteri Karesto
d0dde56c67 Merge pull request #192 from XRPLF/fix/fix-sequence-number
Fix/fix sequence number
2022-05-24 18:20:31 +03:00
Valtteri Karesto
45c6927e72 Take next sequence number from response 2022-05-24 18:16:56 +03:00
Valtteri Karesto
6014b6e79f Update sequence after successful request 2022-05-24 18:14:01 +03:00
Valtteri Karesto
04a99227df Merge pull request #191 from XRPLF/fix/v2-updates
Fix/v2 updates
2022-05-24 15:44:00 +03:00
Valtteri Karesto
0965a1e898 Merge pull request #190 from XRPLF/feat/update-descriptions
Update meta tags
2022-05-24 15:43:47 +03:00
Valtteri Karesto
32445dbebf Mutate tx with fee estimation 2022-05-24 15:27:20 +03:00
Valtteri Karesto
1a1d4901aa Add estimate fee function 2022-05-24 15:26:38 +03:00
Valtteri Karesto
8b646c56dc Fix recursion 2022-05-24 15:26:03 +03:00
Valtteri Karesto
ac38bbc72c Turn the cleaner on by default 2022-05-24 15:25:33 +03:00
5 changed files with 52 additions and 15 deletions

View File

@@ -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"

View File

@@ -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) {

View File

@@ -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({

View File

@@ -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
View 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