diff --git a/utils/estimateFee.ts b/utils/estimateFee.ts index 8d66646..7e3796a 100644 --- a/utils/estimateFee.ts +++ b/utils/estimateFee.ts @@ -1,19 +1,24 @@ -import { sign, XRPL_Account } from "xrpl-accountlib" -import state from "../state" +import { derive, sign } from "xrpl-accountlib" +import state, { IAccount } from "../state" -// Mutate tx object with network estimated fee value -const estimateFee = async (tx: Record, keypair: XRPL_Account): Promise => { +const estimateFee = async (tx: Record, account: IAccount): Promise => { const copyTx = JSON.parse(JSON.stringify(tx)) + console.log(tx) delete copyTx['SigningPubKey'] + if (!copyTx.Fee) { + copyTx.Fee = '1000' + } + const keypair = derive.familySeed(account.secret) 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 res.drops; } return null } catch (err) { - throw Error('Cannot estimate fee') + throw Error('Cannot estimate fee'); + return null } }