Fix delete hook and some refactor.

This commit is contained in:
muzam1l
2023-02-10 14:43:51 +05:30
parent 6bb407cb0f
commit 43c83d0de6
2 changed files with 133 additions and 139 deletions

View File

@@ -85,13 +85,13 @@ export const prepareDeployHookTx = async (
// }
// }
// });
if (typeof window === 'undefined') return;
if (typeof window === 'undefined') return
const tx = {
Account: account.address,
TransactionType: 'SetHook',
Sequence: account.sequence,
Fee: data.Fee,
NetworkID: process.env.NEXT_PUBLIC_NETWORK_ID || state.client.getState().server.networkId,
NetworkID: process.env.NEXT_PUBLIC_NETWORK_ID,
Hooks: [
{
Hook: {
@@ -111,29 +111,28 @@ export const prepareDeployHookTx = async (
return tx
}
/* deployHook function turns the wasm binary into
* hex string, signs the transaction and deploys it to
* Hooks testnet.
/*
* Turns the wasm binary into hex string, signs the transaction and deploys it to Hooks testnet.
*/
export const deployHook = async (account: IAccount & { name?: string }, data: SetHookData) => {
if (typeof window !== 'undefined') {
const activeFile = state.files[state.active]?.compiledContent
? state.files[state.active]
: state.files.filter(file => file.compiledContent)[0]
state.deployValues[activeFile.name] = data
const tx = await prepareDeployHookTx(account, data)
if (!tx) {
return
}
const keypair = derive.familySeed(account.secret)
const { signedTransaction } = sign(tx, keypair)
const currentAccount = state.accounts.find(acc => acc.address === account.address)
if (currentAccount) {
currentAccount.isLoading = true
}
let submitRes
let submitRes
try {
submitRes = await xrplSend({
command: 'submit',
@@ -180,7 +179,7 @@ export const deployHook = async (account: IAccount & { name?: string }, data: Se
})
}
} catch (err) {
console.log(err)
console.error(err)
state.deployLogs.push({
type: 'error',
message: 'Error occurred while deploying'
@@ -190,7 +189,6 @@ export const deployHook = async (account: IAccount & { name?: string }, data: Se
currentAccount.isLoading = false
}
return submitRes
}
}
export const deleteHook = async (account: IAccount & { name?: string }) => {
@@ -198,12 +196,12 @@ export const deleteHook = async (account: IAccount & { name?: string }) => {
if (currentAccount?.isLoading || !currentAccount?.hooks.length) {
return
}
if (typeof window !== 'undefined') {
const tx = {
Account: account.address,
TransactionType: 'SetHook',
Sequence: account.sequence,
Fee: '100000',
NetworkID: process.env.NEXT_PUBLIC_NETWORK_ID,
Hooks: [
{
Hook: {
@@ -213,18 +211,15 @@ export const deleteHook = async (account: IAccount & { name?: string }) => {
}
]
}
const keypair = derive.familySeed(account.secret)
try {
// Update tx Fee value with network estimation
const res = await estimateFee(tx, account)
tx['Fee'] = res?.base_fee ? res?.base_fee : '1000'
tx['Fee'] = res?.base_fee || '1000'
} catch (err) {
// use default value what you defined earlier
console.log(err)
console.error(err)
}
const { signedTransaction } = sign(tx, keypair)
if (currentAccount) {
currentAccount.isLoading = true
}
@@ -270,5 +265,4 @@ export const deleteHook = async (account: IAccount & { name?: string }) => {
currentAccount.isLoading = false
}
return submitRes
}
}

View File

@@ -27,7 +27,7 @@ export const sendTransaction = async (
Account: account.address,
Sequence: account.sequence,
Fee,
NetworkID: process.env.NEXT_PUBLIC_NETWORK_ID || state.client.getState().server.networkId,
NetworkID: process.env.NEXT_PUBLIC_NETWORK_ID,
...opts
}
const { logPrefix = '' } = options || {}