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