Compare commits
14 Commits
feat/tx-pa
...
fix/nft-cr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3340857575 | ||
|
|
e1f34c4beb | ||
|
|
54a89c969e | ||
|
|
ded867d997 | ||
|
|
0fce9af77c | ||
|
|
55c68c580a | ||
|
|
832a7997d1 | ||
|
|
4528e5a16e | ||
|
|
38f064c6d8 | ||
|
|
fbf4565dbc | ||
|
|
9001c64fed | ||
|
|
03b768db4e | ||
|
|
825af0db89 | ||
|
|
31043f33ab |
71
components/Sequence.tsx
Normal file
71
components/Sequence.tsx
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import { FC, useCallback, useState } from 'react'
|
||||||
|
import state from '../state'
|
||||||
|
import { Flex, Input, Button } from '.'
|
||||||
|
import fetchAccountInfo from '../utils/accountInfo'
|
||||||
|
import { useSnapshot } from 'valtio'
|
||||||
|
|
||||||
|
interface AccountSequenceProps {
|
||||||
|
address?: string
|
||||||
|
}
|
||||||
|
const AccountSequence: FC<AccountSequenceProps> = ({ address }) => {
|
||||||
|
const { accounts } = useSnapshot(state)
|
||||||
|
const account = accounts.find(acc => acc.address === address)
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
const setSequence = useCallback(
|
||||||
|
(sequence: number) => {
|
||||||
|
const acc = state.accounts.find(acc => acc.address == address)
|
||||||
|
if (!acc) return
|
||||||
|
acc.sequence = sequence
|
||||||
|
},
|
||||||
|
[address]
|
||||||
|
)
|
||||||
|
const handleUpdateSequence = useCallback(
|
||||||
|
async (silent?: boolean) => {
|
||||||
|
if (!account) return
|
||||||
|
setIsLoading(true)
|
||||||
|
|
||||||
|
const info = await fetchAccountInfo(account.address, { silent })
|
||||||
|
if (info) {
|
||||||
|
setSequence(info.Sequence)
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsLoading(false)
|
||||||
|
},
|
||||||
|
[account, setSequence]
|
||||||
|
)
|
||||||
|
const disabled = !account
|
||||||
|
return (
|
||||||
|
<Flex row align="center" fluid>
|
||||||
|
<Input
|
||||||
|
placeholder="Account sequence"
|
||||||
|
value={account?.sequence || ""}
|
||||||
|
disabled={!account}
|
||||||
|
type="number"
|
||||||
|
readOnly={true}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
size="xs"
|
||||||
|
variant="primary"
|
||||||
|
type="button"
|
||||||
|
outline
|
||||||
|
disabled={disabled}
|
||||||
|
isDisabled={disabled}
|
||||||
|
isLoading={isLoading}
|
||||||
|
css={{
|
||||||
|
background: '$backgroundAlt',
|
||||||
|
position: 'absolute',
|
||||||
|
right: '$2',
|
||||||
|
fontSize: '$xs',
|
||||||
|
cursor: 'pointer',
|
||||||
|
alignContent: 'center',
|
||||||
|
display: 'flex'
|
||||||
|
}}
|
||||||
|
onClick={() => handleUpdateSequence()}
|
||||||
|
>
|
||||||
|
Update
|
||||||
|
</Button>
|
||||||
|
</Flex>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AccountSequence
|
||||||
@@ -21,6 +21,7 @@ import { prepareDeployHookTx, sha256 } from '../state/actions/deployHook'
|
|||||||
import estimateFee from '../utils/estimateFee'
|
import estimateFee from '../utils/estimateFee'
|
||||||
import { getParameters, getInvokeOptions, transactionOptions, SetHookData } from '../utils/setHook'
|
import { getParameters, getInvokeOptions, transactionOptions, SetHookData } from '../utils/setHook'
|
||||||
import { capitalize } from '../utils/helpers'
|
import { capitalize } from '../utils/helpers'
|
||||||
|
import AccountSequence from './Sequence'
|
||||||
|
|
||||||
export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
||||||
({ accountAddress }) => {
|
({ accountAddress }) => {
|
||||||
@@ -190,6 +191,10 @@ export const SetHookDialog: React.FC<{ accountAddress: string }> = React.memo(
|
|||||||
onChange={(acc: any) => setSelectedAccount(acc)}
|
onChange={(acc: any) => setSelectedAccount(acc)}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
|
<Box css={{ width: '100%', position: 'relative' }}>
|
||||||
|
<Label>Sequence</Label>
|
||||||
|
<AccountSequence address={selectedAccount?.value} />
|
||||||
|
</Box>
|
||||||
<Box css={{ width: '100%' }}>
|
<Box css={{ width: '100%' }}>
|
||||||
<Label>Invoke on transactions</Label>
|
<Label>Invoke on transactions</Label>
|
||||||
<Controller
|
<Controller
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ const Transaction: FC<TransactionProps> = ({ header, state: txState, ...props })
|
|||||||
selectedAccount,
|
selectedAccount,
|
||||||
txFields,
|
txFields,
|
||||||
selectedFlags,
|
selectedFlags,
|
||||||
hookParameters
|
hookParameters,
|
||||||
|
memos
|
||||||
} = state
|
} = state
|
||||||
|
|
||||||
const TransactionType = selectedTransaction?.value || null
|
const TransactionType = selectedTransaction?.value || null
|
||||||
@@ -61,6 +62,13 @@ const Transaction: FC<TransactionProps> = ({ header, state: txState, ...props })
|
|||||||
HookParameter: { HookParameterName: toHex(label), HookParameterValue: toHex(value) }
|
HookParameter: { HookParameterName: toHex(label), HookParameterValue: toHex(value) }
|
||||||
})
|
})
|
||||||
}, [])
|
}, [])
|
||||||
|
const Memos = memos
|
||||||
|
? Object.entries(memos).reduce<SetHookData['Memos']>((acc, [_, { format, data, type }]) => {
|
||||||
|
return acc?.concat({
|
||||||
|
Memo: { MemoData: toHex(data), MemoFormat: toHex(format), MemoType: toHex(type) }
|
||||||
|
})
|
||||||
|
}, [])
|
||||||
|
: undefined
|
||||||
|
|
||||||
return prepareTransaction({
|
return prepareTransaction({
|
||||||
...txFields,
|
...txFields,
|
||||||
@@ -68,7 +76,8 @@ const Transaction: FC<TransactionProps> = ({ header, state: txState, ...props })
|
|||||||
Flags,
|
Flags,
|
||||||
TransactionType,
|
TransactionType,
|
||||||
Destination,
|
Destination,
|
||||||
Account
|
Account,
|
||||||
|
Memos
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
[txState]
|
[txState]
|
||||||
@@ -84,15 +93,29 @@ const Transaction: FC<TransactionProps> = ({ header, state: txState, ...props })
|
|||||||
}
|
}
|
||||||
}, [selectedAccount?.value, selectedTransaction?.value, setState, txIsLoading])
|
}, [selectedAccount?.value, selectedTransaction?.value, setState, txIsLoading])
|
||||||
|
|
||||||
|
const getJsonString = useCallback(
|
||||||
|
(state?: Partial<TransactionState>) =>
|
||||||
|
JSON.stringify(prepareOptions?.(state) || {}, null, editorSettings.tabSize),
|
||||||
|
[editorSettings.tabSize, prepareOptions]
|
||||||
|
)
|
||||||
|
|
||||||
|
const saveEditorState = useCallback(
|
||||||
|
(value: string = '', transactionType?: string) => {
|
||||||
|
const pTx = prepareState(value, transactionType)
|
||||||
|
if (pTx) {
|
||||||
|
pTx.editorValue = getJsonString(pTx)
|
||||||
|
return setState(pTx)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[getJsonString, setState]
|
||||||
|
)
|
||||||
|
|
||||||
const submitTest = useCallback(async () => {
|
const submitTest = useCallback(async () => {
|
||||||
let st: TransactionState | undefined
|
let st: TransactionState | undefined
|
||||||
const tt = txState.selectedTransaction?.value
|
const tt = txState.selectedTransaction?.value
|
||||||
if (viewType === 'json') {
|
if (viewType === 'json') {
|
||||||
// save the editor state first
|
st = saveEditorState(editorValue, tt)
|
||||||
const pst = prepareState(editorValue || '', tt)
|
if (!st) return
|
||||||
if (!pst) return
|
|
||||||
|
|
||||||
st = setState(pst)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const account = accounts.find(acc => acc.address === selectedAccount?.value)
|
const account = accounts.find(acc => acc.address === selectedAccount?.value)
|
||||||
@@ -123,23 +146,18 @@ const Transaction: FC<TransactionProps> = ({ header, state: txState, ...props })
|
|||||||
}
|
}
|
||||||
setState({ txIsLoading: false })
|
setState({ txIsLoading: false })
|
||||||
}, [
|
}, [
|
||||||
|
txState.selectedTransaction?.value,
|
||||||
viewType,
|
viewType,
|
||||||
accounts,
|
accounts,
|
||||||
txIsDisabled,
|
txIsDisabled,
|
||||||
setState,
|
setState,
|
||||||
header,
|
header,
|
||||||
|
saveEditorState,
|
||||||
editorValue,
|
editorValue,
|
||||||
txState,
|
|
||||||
selectedAccount?.value,
|
selectedAccount?.value,
|
||||||
prepareOptions
|
prepareOptions
|
||||||
])
|
])
|
||||||
|
|
||||||
const getJsonString = useCallback(
|
|
||||||
(state?: Partial<TransactionState>) =>
|
|
||||||
JSON.stringify(prepareOptions?.(state) || {}, null, editorSettings.tabSize),
|
|
||||||
[editorSettings.tabSize, prepareOptions]
|
|
||||||
)
|
|
||||||
|
|
||||||
const resetState = useCallback(
|
const resetState = useCallback(
|
||||||
(transactionType: SelectOption | undefined = defaultTransactionType) => {
|
(transactionType: SelectOption | undefined = defaultTransactionType) => {
|
||||||
const fields = getTxFields(transactionType?.value)
|
const fields = getTxFields(transactionType?.value)
|
||||||
@@ -192,11 +210,21 @@ const Transaction: FC<TransactionProps> = ({ header, state: txState, ...props })
|
|||||||
[accounts, prepareOptions, setState, txState]
|
[accounts, prepareOptions, setState, txState]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const switchToJson = useCallback(() => {
|
||||||
|
const editorValue = getJsonString()
|
||||||
|
setState({ viewType: 'json', editorValue })
|
||||||
|
}, [getJsonString, setState])
|
||||||
|
|
||||||
|
const switchToUI = useCallback(() => {
|
||||||
|
setState({ viewType: 'ui' })
|
||||||
|
}, [setState])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box css={{ position: 'relative', height: 'calc(100% - 28px)' }} {...props}>
|
<Box css={{ position: 'relative', height: 'calc(100% - 28px)' }} {...props}>
|
||||||
{viewType === 'json' ? (
|
{viewType === 'json' ? (
|
||||||
<TxJson
|
<TxJson
|
||||||
getJsonString={getJsonString}
|
getJsonString={getJsonString}
|
||||||
|
saveEditorState={saveEditorState}
|
||||||
header={header}
|
header={header}
|
||||||
state={txState}
|
state={txState}
|
||||||
setState={setState}
|
setState={setState}
|
||||||
@@ -204,6 +232,7 @@ const Transaction: FC<TransactionProps> = ({ header, state: txState, ...props })
|
|||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<TxUI
|
<TxUI
|
||||||
|
switchToJson={switchToJson}
|
||||||
state={txState}
|
state={txState}
|
||||||
resetState={resetState}
|
resetState={resetState}
|
||||||
setState={setState}
|
setState={setState}
|
||||||
@@ -224,8 +253,8 @@ const Transaction: FC<TransactionProps> = ({ header, state: txState, ...props })
|
|||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (viewType === 'ui') {
|
if (viewType === 'ui') {
|
||||||
setState({ viewType: 'json' })
|
switchToJson()
|
||||||
} else setState({ viewType: 'ui' })
|
} else switchToUI()
|
||||||
}}
|
}}
|
||||||
outline
|
outline
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { FC, useCallback, useEffect, useMemo, useState } from 'react'
|
import { FC, useCallback, useEffect, useState } from 'react'
|
||||||
import { useSnapshot } from 'valtio'
|
import { useSnapshot } from 'valtio'
|
||||||
import state, { prepareState, transactionsData, TransactionState } from '../../state'
|
import state, { transactionsData, TransactionState } from '../../state'
|
||||||
import Text from '../Text'
|
import Text from '../Text'
|
||||||
import { Flex, Link } from '..'
|
import { Flex, Link } from '..'
|
||||||
import { showAlert } from '../../state/actions/showAlert'
|
import { showAlert } from '../../state/actions/showAlert'
|
||||||
@@ -11,27 +11,27 @@ import Monaco from '../Monaco'
|
|||||||
import type monaco from 'monaco-editor'
|
import type monaco from 'monaco-editor'
|
||||||
|
|
||||||
interface JsonProps {
|
interface JsonProps {
|
||||||
getJsonString?: (state?: Partial<TransactionState>) => string
|
getJsonString: (st?: Partial<TransactionState>) => string
|
||||||
|
saveEditorState: (val?: string, tt?: string) => TransactionState | undefined
|
||||||
header?: string
|
header?: string
|
||||||
setState: (pTx?: Partial<TransactionState> | undefined) => void
|
setState: (pTx?: Partial<TransactionState> | undefined) => void
|
||||||
state: TransactionState
|
state: TransactionState
|
||||||
estimateFee?: () => Promise<string | undefined>
|
estimateFee?: () => Promise<string | undefined>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TxJson: FC<JsonProps> = ({ getJsonString, state: txState, header, setState }) => {
|
export const TxJson: FC<JsonProps> = ({
|
||||||
|
getJsonString,
|
||||||
|
state: txState,
|
||||||
|
header,
|
||||||
|
setState,
|
||||||
|
saveEditorState
|
||||||
|
}) => {
|
||||||
const { editorSettings, accounts } = useSnapshot(state)
|
const { editorSettings, accounts } = useSnapshot(state)
|
||||||
const { editorValue, estimatedFee } = txState
|
const { editorValue, estimatedFee, editorIsSaved } = txState
|
||||||
const [currTxType, setCurrTxType] = useState<string | undefined>(
|
const [currTxType, setCurrTxType] = useState<string | undefined>(
|
||||||
txState.selectedTransaction?.value
|
txState.selectedTransaction?.value
|
||||||
)
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setState({
|
|
||||||
editorValue: getJsonString?.()
|
|
||||||
})
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const parsed = parseJSON(editorValue)
|
const parsed = parseJSON(editorValue)
|
||||||
if (!parsed) return
|
if (!parsed) return
|
||||||
@@ -44,29 +44,19 @@ export const TxJson: FC<JsonProps> = ({ getJsonString, state: txState, header, s
|
|||||||
}
|
}
|
||||||
}, [editorValue])
|
}, [editorValue])
|
||||||
|
|
||||||
const saveState = (value: string, transactionType?: string) => {
|
|
||||||
const tx = prepareState(value, transactionType)
|
|
||||||
if (tx) {
|
|
||||||
setState(tx)
|
|
||||||
setState({
|
|
||||||
editorValue: getJsonString?.(tx)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const discardChanges = () => {
|
const discardChanges = () => {
|
||||||
showAlert('Confirm', {
|
showAlert('Confirm', {
|
||||||
body: 'Are you sure to discard these changes?',
|
body: 'Are you sure to discard these changes?',
|
||||||
confirmText: 'Yes',
|
confirmText: 'Yes',
|
||||||
onCancel: () => {},
|
onCancel: () => {},
|
||||||
onConfirm: () => setState({ editorValue: getJsonString?.() })
|
onConfirm: () => setState({ editorValue: getJsonString() })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const onExit = (value: string) => {
|
const onExit = (value: string) => {
|
||||||
const options = parseJSON(value)
|
const options = parseJSON(value)
|
||||||
if (options) {
|
if (options) {
|
||||||
saveState(value, currTxType)
|
saveEditorState(value, currTxType)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
showAlert('Error!', {
|
showAlert('Error!', {
|
||||||
@@ -163,8 +153,6 @@ export const TxJson: FC<JsonProps> = ({ getJsonString, state: txState, header, s
|
|||||||
})
|
})
|
||||||
}, [getSchemas, monacoInst])
|
}, [getSchemas, monacoInst])
|
||||||
|
|
||||||
const hasUnsaved = useMemo(() => editorValue !== getJsonString?.(), [editorValue, getJsonString])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Monaco
|
<Monaco
|
||||||
rootProps={{
|
rootProps={{
|
||||||
@@ -174,7 +162,7 @@ export const TxJson: FC<JsonProps> = ({ getJsonString, state: txState, header, s
|
|||||||
id={header}
|
id={header}
|
||||||
height="100%"
|
height="100%"
|
||||||
value={editorValue}
|
value={editorValue}
|
||||||
onChange={val => setState({ editorValue: val })}
|
onChange={val => setState({ editorValue: val, editorIsSaved: false })}
|
||||||
onMount={(editor, monaco) => {
|
onMount={(editor, monaco) => {
|
||||||
editor.updateOptions({
|
editor.updateOptions({
|
||||||
minimap: { enabled: false },
|
minimap: { enabled: false },
|
||||||
@@ -190,12 +178,12 @@ export const TxJson: FC<JsonProps> = ({ getJsonString, state: txState, header, s
|
|||||||
model?.onWillDispose(() => onExit(model.getValue()))
|
model?.onWillDispose(() => onExit(model.getValue()))
|
||||||
}}
|
}}
|
||||||
overlay={
|
overlay={
|
||||||
hasUnsaved ? (
|
!editorIsSaved ? (
|
||||||
<Flex row align="center" css={{ fontSize: '$xs', color: '$textMuted', ml: 'auto' }}>
|
<Flex row align="center" css={{ fontSize: '$xs', color: '$textMuted', ml: 'auto' }}>
|
||||||
<Text muted small>
|
<Text muted small>
|
||||||
This file has unsaved changes.
|
This file has unsaved changes.
|
||||||
</Text>
|
</Text>
|
||||||
<Link css={{ ml: '$1' }} onClick={() => saveState(editorValue || '', currTxType)}>
|
<Link css={{ ml: '$1' }} onClick={() => saveEditorState(editorValue, currTxType)}>
|
||||||
save
|
save
|
||||||
</Link>
|
</Link>
|
||||||
<Link css={{ ml: '$1' }} onClick={discardChanges}>
|
<Link css={{ ml: '$1' }} onClick={discardChanges}>
|
||||||
|
|||||||
@@ -19,15 +19,23 @@ import { Button } from '..'
|
|||||||
import Textarea from '../Textarea'
|
import Textarea from '../Textarea'
|
||||||
import { getFlags } from '../../state/constants/flags'
|
import { getFlags } from '../../state/constants/flags'
|
||||||
import { Plus, Trash } from 'phosphor-react'
|
import { Plus, Trash } from 'phosphor-react'
|
||||||
|
import AccountSequence from '../Sequence'
|
||||||
|
|
||||||
interface UIProps {
|
interface UIProps {
|
||||||
setState: (pTx?: Partial<TransactionState> | undefined) => TransactionState | undefined
|
setState: (pTx?: Partial<TransactionState> | undefined) => TransactionState | undefined
|
||||||
resetState: (tt?: SelectOption) => TransactionState | undefined
|
resetState: (tt?: SelectOption) => TransactionState | undefined
|
||||||
state: TransactionState
|
state: TransactionState
|
||||||
estimateFee?: (...arg: any) => Promise<string | undefined>
|
estimateFee?: (...arg: any) => Promise<string | undefined>
|
||||||
|
switchToJson: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TxUI: FC<UIProps> = ({ state: txState, setState, resetState, estimateFee }) => {
|
export const TxUI: FC<UIProps> = ({
|
||||||
|
state: txState,
|
||||||
|
setState,
|
||||||
|
resetState,
|
||||||
|
estimateFee,
|
||||||
|
switchToJson
|
||||||
|
}) => {
|
||||||
const { accounts } = useSnapshot(state)
|
const { accounts } = useSnapshot(state)
|
||||||
const {
|
const {
|
||||||
selectedAccount,
|
selectedAccount,
|
||||||
@@ -35,7 +43,8 @@ export const TxUI: FC<UIProps> = ({ state: txState, setState, resetState, estima
|
|||||||
selectedTransaction,
|
selectedTransaction,
|
||||||
txFields,
|
txFields,
|
||||||
selectedFlags,
|
selectedFlags,
|
||||||
hookParameters
|
hookParameters,
|
||||||
|
memos
|
||||||
} = txState
|
} = txState
|
||||||
|
|
||||||
const accountOptions: SelectOption[] = accounts.map(acc => ({
|
const accountOptions: SelectOption[] = accounts.map(acc => ({
|
||||||
@@ -101,8 +110,6 @@ export const TxUI: FC<UIProps> = ({ state: txState, setState, resetState, estima
|
|||||||
[handleEstimateFee, resetState, setState]
|
[handleEstimateFee, resetState, setState]
|
||||||
)
|
)
|
||||||
|
|
||||||
const switchToJson = () => setState({ viewType: 'json' })
|
|
||||||
|
|
||||||
// default tx
|
// default tx
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedTransaction?.value) return
|
if (selectedTransaction?.value) return
|
||||||
@@ -117,7 +124,7 @@ export const TxUI: FC<UIProps> = ({ state: txState, setState, resetState, estima
|
|||||||
[selectedTransaction?.value]
|
[selectedTransaction?.value]
|
||||||
)
|
)
|
||||||
|
|
||||||
const richFields = ['TransactionType', 'Account', 'HookParameters']
|
const richFields = ['TransactionType', 'Account', 'HookParameters', 'Memos']
|
||||||
if (fields.Destination !== undefined) {
|
if (fields.Destination !== undefined) {
|
||||||
richFields.push('Destination')
|
richFields.push('Destination')
|
||||||
}
|
}
|
||||||
@@ -155,6 +162,9 @@ export const TxUI: FC<UIProps> = ({ state: txState, setState, resetState, estima
|
|||||||
onChange={(acc: any) => handleSetAccount(acc)} // TODO make react-select have correct types for acc
|
onChange={(acc: any) => handleSetAccount(acc)} // TODO make react-select have correct types for acc
|
||||||
/>
|
/>
|
||||||
</TxField>
|
</TxField>
|
||||||
|
<TxField label="Sequence">
|
||||||
|
<AccountSequence address={selectedAccount?.value} />
|
||||||
|
</TxField>
|
||||||
{richFields.includes('Destination') && (
|
{richFields.includes('Destination') && (
|
||||||
<TxField label="Destination account">
|
<TxField label="Destination account">
|
||||||
<Select
|
<Select
|
||||||
@@ -333,6 +343,83 @@ export const TxUI: FC<UIProps> = ({ state: txState, setState, resetState, estima
|
|||||||
</Button>
|
</Button>
|
||||||
</Flex>
|
</Flex>
|
||||||
</TxField>
|
</TxField>
|
||||||
|
<TxField multiLine label="Memos">
|
||||||
|
<Flex column fluid>
|
||||||
|
{Object.entries(memos).map(([id, memo]) => (
|
||||||
|
<Flex column key={id} css={{ mb: '$2' }}>
|
||||||
|
<Flex
|
||||||
|
row
|
||||||
|
css={{
|
||||||
|
flexWrap: 'wrap',
|
||||||
|
width: '100%'
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Input
|
||||||
|
placeholder="Memo type"
|
||||||
|
value={memo.type}
|
||||||
|
onChange={e => {
|
||||||
|
setState({
|
||||||
|
memos: {
|
||||||
|
...memos,
|
||||||
|
[id]: { ...memo, type: e.target.value }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
placeholder="Data"
|
||||||
|
css={{ mx: '$2' }}
|
||||||
|
value={memo.data}
|
||||||
|
onChange={e => {
|
||||||
|
setState({
|
||||||
|
memos: {
|
||||||
|
...memos,
|
||||||
|
[id]: { ...memo, data: e.target.value }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
placeholder="Format"
|
||||||
|
value={memo.format}
|
||||||
|
onChange={e => {
|
||||||
|
setState({
|
||||||
|
memos: {
|
||||||
|
...memos,
|
||||||
|
[id]: { ...memo, format: e.target.value }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
css={{ ml: '$2' }}
|
||||||
|
onClick={() => {
|
||||||
|
const { [id]: _, ...rest } = memos
|
||||||
|
setState({ memos: rest })
|
||||||
|
}}
|
||||||
|
variant="destroy"
|
||||||
|
>
|
||||||
|
<Trash weight="regular" size="16px" />
|
||||||
|
</Button>
|
||||||
|
</Flex>
|
||||||
|
</Flex>
|
||||||
|
))}
|
||||||
|
<Button
|
||||||
|
outline
|
||||||
|
fullWidth
|
||||||
|
type="button"
|
||||||
|
onClick={() => {
|
||||||
|
const id = Object.keys(memos).length
|
||||||
|
setState({
|
||||||
|
memos: { ...memos, [id]: { data: '', format: '', type: '' } }
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Plus size="16px" />
|
||||||
|
Add Memo
|
||||||
|
</Button>
|
||||||
|
</Flex>
|
||||||
|
</TxField>
|
||||||
</Flex>
|
</Flex>
|
||||||
</Container>
|
</Container>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -124,7 +124,8 @@
|
|||||||
},
|
},
|
||||||
"Flags": "1",
|
"Flags": "1",
|
||||||
"Destination": "",
|
"Destination": "",
|
||||||
"Fee": "10"
|
"Fee": "10",
|
||||||
|
"Owner": ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"TransactionType": "OfferCancel",
|
"TransactionType": "OfferCancel",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import toast from 'react-hot-toast'
|
import toast from 'react-hot-toast'
|
||||||
import state, { FaucetAccountRes } from '../index'
|
import state, { FaucetAccountRes } from '../index'
|
||||||
|
import fetchAccountInfo from '../../utils/accountInfo';
|
||||||
|
|
||||||
export const names = [
|
export const names = [
|
||||||
'Alice',
|
'Alice',
|
||||||
@@ -35,26 +36,23 @@ export const addFaucetAccount = async (name?: string, showToast: boolean = false
|
|||||||
})
|
})
|
||||||
const json: FaucetAccountRes | { error: string } = await res.json()
|
const json: FaucetAccountRes | { error: string } = await res.json()
|
||||||
if ('error' in json) {
|
if ('error' in json) {
|
||||||
if (showToast) {
|
if (!showToast) return;
|
||||||
return toast.error(json.error, { id: toastId })
|
return toast.error(json.error, { id: toastId })
|
||||||
} else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (showToast) {
|
|
||||||
toast.success('New account created', { id: toastId })
|
|
||||||
}
|
}
|
||||||
const currNames = state.accounts.map(acc => acc.name)
|
const currNames = state.accounts.map(acc => acc.name)
|
||||||
|
const info = await fetchAccountInfo(json.address, { silent: true })
|
||||||
state.accounts.push({
|
state.accounts.push({
|
||||||
name: name || names.filter(name => !currNames.includes(name))[0],
|
name: name || names.filter(name => !currNames.includes(name))[0],
|
||||||
xrp: (json.xrp || 0 * 1000000).toString(),
|
xrp: (json.xrp || 0 * 1000000).toString(),
|
||||||
address: json.address,
|
address: json.address,
|
||||||
secret: json.secret,
|
secret: json.secret,
|
||||||
sequence: 1,
|
sequence: info?.Sequence || 1,
|
||||||
hooks: [],
|
hooks: [],
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
version: '2'
|
version: '2'
|
||||||
})
|
})
|
||||||
|
if (showToast) {
|
||||||
|
toast.success('New account created', { id: toastId })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,17 +16,27 @@ export type HookParameters = {
|
|||||||
[key: string]: SelectOption
|
[key: string]: SelectOption
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type Memos = {
|
||||||
|
[key: string]: {
|
||||||
|
type: string
|
||||||
|
format: string
|
||||||
|
data: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export interface TransactionState {
|
export interface TransactionState {
|
||||||
selectedTransaction: SelectOption | null
|
selectedTransaction: SelectOption | null
|
||||||
selectedAccount: SelectOption | null
|
selectedAccount: SelectOption | null
|
||||||
selectedDestAccount: SelectOption | null
|
selectedDestAccount: SelectOption | null
|
||||||
selectedFlags: SelectOption[] | null
|
selectedFlags: SelectOption[] | null
|
||||||
hookParameters: HookParameters
|
hookParameters: HookParameters
|
||||||
|
memos: Memos
|
||||||
txIsLoading: boolean
|
txIsLoading: boolean
|
||||||
txIsDisabled: boolean
|
txIsDisabled: boolean
|
||||||
txFields: TxFields
|
txFields: TxFields
|
||||||
viewType: 'json' | 'ui'
|
viewType: 'json' | 'ui'
|
||||||
editorValue?: string
|
editorValue?: string
|
||||||
|
editorIsSaved: boolean
|
||||||
estimatedFee?: string
|
estimatedFee?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,6 +53,8 @@ export const defaultTransaction: TransactionState = {
|
|||||||
selectedDestAccount: null,
|
selectedDestAccount: null,
|
||||||
selectedFlags: null,
|
selectedFlags: null,
|
||||||
hookParameters: {},
|
hookParameters: {},
|
||||||
|
memos: {},
|
||||||
|
editorIsSaved: true,
|
||||||
txIsLoading: false,
|
txIsLoading: false,
|
||||||
txIsDisabled: false,
|
txIsDisabled: false,
|
||||||
txFields: {},
|
txFields: {},
|
||||||
@@ -167,7 +179,7 @@ export const prepareState = (value: string, transactionType?: string) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const { Account, TransactionType, Destination, HookParameters, ...rest } = options
|
const { Account, TransactionType, Destination, HookParameters, Memos, ...rest } = options
|
||||||
let tx: Partial<TransactionState> = {}
|
let tx: Partial<TransactionState> = {}
|
||||||
const schema = getTxFields(transactionType)
|
const schema = getTxFields(transactionType)
|
||||||
|
|
||||||
@@ -205,6 +217,14 @@ export const prepareState = (value: string, transactionType?: string) => {
|
|||||||
}, {})
|
}, {})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Memos && Memos instanceof Array) {
|
||||||
|
tx.memos = Memos.reduce<TransactionState["memos"]>((acc, cur, idx) => {
|
||||||
|
const memo = { data: fromHex(cur.Memo?.MemoData || ""), type: fromHex(cur.Memo?.MemoType || ""), format: fromHex(cur.Memo?.MemoFormat || "") }
|
||||||
|
acc[idx] = memo;
|
||||||
|
return acc;
|
||||||
|
}, {})
|
||||||
|
}
|
||||||
|
|
||||||
if (schema.Destination !== undefined) {
|
if (schema.Destination !== undefined) {
|
||||||
const dest = state.accounts.find(acc => acc.address === Destination)
|
const dest = state.accounts.find(acc => acc.address === Destination)
|
||||||
if (dest) {
|
if (dest) {
|
||||||
@@ -253,6 +273,7 @@ export const prepareState = (value: string, transactionType?: string) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
tx.txFields = rest
|
tx.txFields = rest
|
||||||
|
tx.editorIsSaved = true;
|
||||||
|
|
||||||
return tx
|
return tx
|
||||||
}
|
}
|
||||||
|
|||||||
31
utils/accountInfo.ts
Normal file
31
utils/accountInfo.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import toast from 'react-hot-toast'
|
||||||
|
|
||||||
|
import { xrplSend } from '../state/actions/xrpl-client'
|
||||||
|
|
||||||
|
interface AccountInfo {
|
||||||
|
Account: string,
|
||||||
|
Sequence: number,
|
||||||
|
Flags: number,
|
||||||
|
Balance?: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchAccountInfo = async (
|
||||||
|
address: string,
|
||||||
|
opts: { silent?: boolean } = {}
|
||||||
|
): Promise<AccountInfo | undefined> => {
|
||||||
|
try {
|
||||||
|
const res = await xrplSend({
|
||||||
|
id: `hooks-builder-req-info-${address}`,
|
||||||
|
command: 'account_info',
|
||||||
|
account: address
|
||||||
|
})
|
||||||
|
return res.account_data;
|
||||||
|
} catch (err) {
|
||||||
|
if (!opts.silent) {
|
||||||
|
console.error(err)
|
||||||
|
toast.error('Could not fetch account info!')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default fetchAccountInfo
|
||||||
@@ -20,6 +20,13 @@ export type SetHookData = {
|
|||||||
}
|
}
|
||||||
$metaData?: any
|
$metaData?: any
|
||||||
}[]
|
}[]
|
||||||
|
Memos?: {
|
||||||
|
Memo: {
|
||||||
|
MemoType: string,
|
||||||
|
MemoData: string
|
||||||
|
MemoFormat: string
|
||||||
|
}
|
||||||
|
}[]
|
||||||
// HookGrants: {
|
// HookGrants: {
|
||||||
// HookGrant: {
|
// HookGrant: {
|
||||||
// Authorize: string;
|
// Authorize: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user