Compare commits
5 Commits
feat/bundl
...
fix/params
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
423ee18e6a | ||
|
|
3bb26d0c9b | ||
|
|
43c83d0de6 | ||
|
|
6bb407cb0f | ||
|
|
d7b29ba809 |
@@ -15,7 +15,7 @@ const contentShow = keyframes({
|
|||||||
'100%': { opacity: 1 }
|
'100%': { opacity: 1 }
|
||||||
})
|
})
|
||||||
const StyledOverlay = styled(DialogPrimitive.Overlay, {
|
const StyledOverlay = styled(DialogPrimitive.Overlay, {
|
||||||
zIndex: 10000,
|
zIndex: 3000,
|
||||||
backgroundColor: blackA.blackA9,
|
backgroundColor: blackA.blackA9,
|
||||||
position: 'fixed',
|
position: 'fixed',
|
||||||
inset: 0,
|
inset: 0,
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ const generateHtmlTemplate = async (code: string, data?: Record<string, any>) =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
processString = JSON.stringify(process)
|
processString = JSON.stringify(process)
|
||||||
|
|
||||||
const libs = (await import("xrpl-accountlib/dist/browser.hook-bundle.js")).default;
|
const libs = (await import("xrpl-accountlib/dist/browser.hook-bundle.js")).default;
|
||||||
return `
|
return `
|
||||||
<html>
|
<html>
|
||||||
@@ -135,14 +135,28 @@ const RunScript: React.FC<{ file: IFile }> = ({ file: { content, name } }) => {
|
|||||||
const runScript = useCallback(async () => {
|
const runScript = useCallback(async () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
|
// Show loading toast only after 1 second, otherwise skip it.
|
||||||
|
let loaded = false
|
||||||
|
let toastId: string | undefined;
|
||||||
|
setTimeout(() => {
|
||||||
|
if (!loaded) {
|
||||||
|
toastId = toast.loading('Loading packages, may take a few seconds...', {
|
||||||
|
position: 'bottom-center',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, 1000)
|
||||||
|
|
||||||
let data: any = {}
|
let data: any = {}
|
||||||
Object.keys(fields).forEach(key => {
|
Object.keys(fields).forEach(key => {
|
||||||
data[key] = fields[key].value
|
data[key] = fields[key].value
|
||||||
})
|
})
|
||||||
const template = await generateHtmlTemplate(content, data)
|
const template = await generateHtmlTemplate(content, data)
|
||||||
|
|
||||||
setIframeCode(template)
|
setIframeCode(template)
|
||||||
|
|
||||||
|
loaded = true
|
||||||
|
if (toastId) {
|
||||||
|
toast.dismiss(toastId)
|
||||||
|
}
|
||||||
state.scriptLogs = [{ type: 'success', message: 'Started running...' }]
|
state.scriptLogs = [{ type: 'success', message: 'Started running...' }]
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
state.scriptLogs = [
|
state.scriptLogs = [
|
||||||
@@ -181,11 +195,11 @@ const RunScript: React.FC<{ file: IFile }> = ({ file: { content, name } }) => {
|
|||||||
|
|
||||||
const isDisabled = Object.values(fields).some(field => field.required && !field.value)
|
const isDisabled = Object.values(fields).some(field => field.required && !field.value)
|
||||||
|
|
||||||
const handleRun = useCallback(() => {
|
const handleRun = useCallback(async () => {
|
||||||
if (isDisabled) return toast.error('Please fill in all the required fields.')
|
if (isDisabled) return toast.error('Please fill in all the required fields.')
|
||||||
|
|
||||||
state.scriptLogs = []
|
state.scriptLogs = []
|
||||||
runScript()
|
await runScript();
|
||||||
setIsDialogOpen(false)
|
setIsDialogOpen(false)
|
||||||
}, [isDisabled, runScript])
|
}, [isDisabled, runScript])
|
||||||
|
|
||||||
|
|||||||
@@ -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,86 +111,84 @@ 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)
|
|
||||||
if (!tx) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const keypair = derive.familySeed(account.secret)
|
|
||||||
|
|
||||||
const { signedTransaction } = sign(tx, keypair)
|
const tx = await prepareDeployHookTx(account, data)
|
||||||
const currentAccount = state.accounts.find(acc => acc.address === account.address)
|
if (!tx) {
|
||||||
if (currentAccount) {
|
return
|
||||||
currentAccount.isLoading = true
|
}
|
||||||
}
|
const keypair = derive.familySeed(account.secret)
|
||||||
let submitRes
|
const { signedTransaction } = sign(tx, keypair)
|
||||||
|
|
||||||
try {
|
const currentAccount = state.accounts.find(acc => acc.address === account.address)
|
||||||
submitRes = await xrplSend({
|
if (currentAccount) {
|
||||||
command: 'submit',
|
currentAccount.isLoading = true
|
||||||
tx_blob: signedTransaction
|
}
|
||||||
|
|
||||||
|
let submitRes
|
||||||
|
try {
|
||||||
|
submitRes = await xrplSend({
|
||||||
|
command: 'submit',
|
||||||
|
tx_blob: signedTransaction
|
||||||
|
})
|
||||||
|
|
||||||
|
const txHash = submitRes.tx_json?.hash
|
||||||
|
const resultMsg = ref(
|
||||||
|
<>
|
||||||
|
[<ResultLink result={submitRes.engine_result} />] {submitRes.engine_result_message}{' '}
|
||||||
|
{txHash && (
|
||||||
|
<>
|
||||||
|
Transaction hash:{' '}
|
||||||
|
<Link
|
||||||
|
as="a"
|
||||||
|
href={`https://${process.env.NEXT_PUBLIC_EXPLORER_URL}/${txHash}`}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
{txHash}
|
||||||
|
</Link>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
if (submitRes.engine_result === 'tesSUCCESS') {
|
||||||
|
state.deployLogs.push({
|
||||||
|
type: 'success',
|
||||||
|
message: 'Hook deployed successfully ✅'
|
||||||
})
|
})
|
||||||
|
state.deployLogs.push({
|
||||||
const txHash = submitRes.tx_json?.hash
|
type: 'success',
|
||||||
const resultMsg = ref(
|
message: resultMsg
|
||||||
<>
|
})
|
||||||
[<ResultLink result={submitRes.engine_result} />] {submitRes.engine_result_message}{' '}
|
} else if (submitRes.engine_result) {
|
||||||
{txHash && (
|
|
||||||
<>
|
|
||||||
Transaction hash:{' '}
|
|
||||||
<Link
|
|
||||||
as="a"
|
|
||||||
href={`https://${process.env.NEXT_PUBLIC_EXPLORER_URL}/${txHash}`}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
{txHash}
|
|
||||||
</Link>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
if (submitRes.engine_result === 'tesSUCCESS') {
|
|
||||||
state.deployLogs.push({
|
|
||||||
type: 'success',
|
|
||||||
message: 'Hook deployed successfully ✅'
|
|
||||||
})
|
|
||||||
state.deployLogs.push({
|
|
||||||
type: 'success',
|
|
||||||
message: resultMsg
|
|
||||||
})
|
|
||||||
} else if (submitRes.engine_result) {
|
|
||||||
state.deployLogs.push({
|
|
||||||
type: 'error',
|
|
||||||
message: resultMsg
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
state.deployLogs.push({
|
|
||||||
type: 'error',
|
|
||||||
message: `[${submitRes.error}] ${submitRes.error_exception}`
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err)
|
|
||||||
state.deployLogs.push({
|
state.deployLogs.push({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: 'Error occurred while deploying'
|
message: resultMsg
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
state.deployLogs.push({
|
||||||
|
type: 'error',
|
||||||
|
message: `[${submitRes.error}] ${submitRes.error_exception}`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (currentAccount) {
|
} catch (err) {
|
||||||
currentAccount.isLoading = false
|
console.error(err)
|
||||||
}
|
state.deployLogs.push({
|
||||||
return submitRes
|
type: 'error',
|
||||||
|
message: 'Error occurred while deploying'
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
if (currentAccount) {
|
||||||
|
currentAccount.isLoading = false
|
||||||
|
}
|
||||||
|
return submitRes
|
||||||
}
|
}
|
||||||
|
|
||||||
export const deleteHook = async (account: IAccount & { name?: string }) => {
|
export const deleteHook = async (account: IAccount & { name?: string }) => {
|
||||||
@@ -198,77 +196,73 @@ export const deleteHook = async (account: IAccount & { name?: string }) => {
|
|||||||
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: {
|
||||||
CreateCode: '',
|
CreateCode: '',
|
||||||
Flags: 1
|
Flags: 1
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
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'
|
|
||||||
} catch (err) {
|
|
||||||
// use default value what you defined earlier
|
|
||||||
console.log(err)
|
|
||||||
}
|
|
||||||
const { signedTransaction } = sign(tx, keypair)
|
|
||||||
|
|
||||||
if (currentAccount) {
|
|
||||||
currentAccount.isLoading = true
|
|
||||||
}
|
|
||||||
let submitRes
|
|
||||||
const toastId = toast.loading('Deleting hook...')
|
|
||||||
try {
|
|
||||||
submitRes = await xrplSend({
|
|
||||||
command: 'submit',
|
|
||||||
tx_blob: signedTransaction
|
|
||||||
})
|
|
||||||
|
|
||||||
if (submitRes.engine_result === 'tesSUCCESS') {
|
|
||||||
toast.success('Hook deleted successfully ✅', { id: toastId })
|
|
||||||
state.deployLogs.push({
|
|
||||||
type: 'success',
|
|
||||||
message: 'Hook deleted successfully ✅'
|
|
||||||
})
|
|
||||||
state.deployLogs.push({
|
|
||||||
type: 'success',
|
|
||||||
message: `[${submitRes.engine_result}] ${submitRes.engine_result_message} Validated ledger index: ${submitRes.validated_ledger_index}`
|
|
||||||
})
|
|
||||||
currentAccount.hooks = []
|
|
||||||
} else {
|
|
||||||
toast.error(`${submitRes.engine_result_message || submitRes.error_exception}`, {
|
|
||||||
id: toastId
|
|
||||||
})
|
|
||||||
state.deployLogs.push({
|
|
||||||
type: 'error',
|
|
||||||
message: `[${submitRes.engine_result || submitRes.error}] ${
|
|
||||||
submitRes.engine_result_message || submitRes.error_exception
|
|
||||||
}`
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
]
|
||||||
console.log(err)
|
}
|
||||||
toast.error('Error occurred while deleting hook', { id: toastId })
|
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 || '1000'
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
}
|
||||||
|
const { signedTransaction } = sign(tx, keypair)
|
||||||
|
if (currentAccount) {
|
||||||
|
currentAccount.isLoading = true
|
||||||
|
}
|
||||||
|
let submitRes
|
||||||
|
const toastId = toast.loading('Deleting hook...')
|
||||||
|
try {
|
||||||
|
submitRes = await xrplSend({
|
||||||
|
command: 'submit',
|
||||||
|
tx_blob: signedTransaction
|
||||||
|
})
|
||||||
|
|
||||||
|
if (submitRes.engine_result === 'tesSUCCESS') {
|
||||||
|
toast.success('Hook deleted successfully ✅', { id: toastId })
|
||||||
|
state.deployLogs.push({
|
||||||
|
type: 'success',
|
||||||
|
message: 'Hook deleted successfully ✅'
|
||||||
|
})
|
||||||
|
state.deployLogs.push({
|
||||||
|
type: 'success',
|
||||||
|
message: `[${submitRes.engine_result}] ${submitRes.engine_result_message} Validated ledger index: ${submitRes.validated_ledger_index}`
|
||||||
|
})
|
||||||
|
currentAccount.hooks = []
|
||||||
|
} else {
|
||||||
|
toast.error(`${submitRes.engine_result_message || submitRes.error_exception}`, {
|
||||||
|
id: toastId
|
||||||
|
})
|
||||||
state.deployLogs.push({
|
state.deployLogs.push({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: 'Error occurred while deleting hook'
|
message: `[${submitRes.engine_result || submitRes.error}] ${
|
||||||
|
submitRes.engine_result_message || submitRes.error_exception
|
||||||
|
}`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (currentAccount) {
|
} catch (err) {
|
||||||
currentAccount.isLoading = false
|
console.log(err)
|
||||||
}
|
toast.error('Error occurred while deleting hook', { id: toastId })
|
||||||
return submitRes
|
state.deployLogs.push({
|
||||||
|
type: 'error',
|
||||||
|
message: 'Error occurred while deleting hook'
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
if (currentAccount) {
|
||||||
|
currentAccount.isLoading = false
|
||||||
|
}
|
||||||
|
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 || {}
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ export const tts = {
|
|||||||
ttNFTOKEN_BURN: 26,
|
ttNFTOKEN_BURN: 26,
|
||||||
ttNFTOKEN_CREATE_OFFER: 27,
|
ttNFTOKEN_CREATE_OFFER: 27,
|
||||||
ttNFTOKEN_CANCEL_OFFER: 28,
|
ttNFTOKEN_CANCEL_OFFER: 28,
|
||||||
ttNFTOKEN_ACCEPT_OFFER: 29
|
ttNFTOKEN_ACCEPT_OFFER: 29,
|
||||||
|
ttINVOKE: 99,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TTS = typeof tts
|
export type TTS = typeof tts
|
||||||
|
|||||||
Reference in New Issue
Block a user