Compare commits
5 Commits
fix/split-
...
feat/creat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f1b877db0 | ||
|
|
53afb1d3d1 | ||
|
|
31ff7c0e28 | ||
|
|
dfa35df465 | ||
|
|
f163b052e1 |
@@ -31,6 +31,7 @@ import transactionsData from "../content/transactions.json";
|
|||||||
import { SetHookDialog } from "./SetHookDialog";
|
import { SetHookDialog } from "./SetHookDialog";
|
||||||
import { addFunds } from "../state/actions/addFaucetAccount";
|
import { addFunds } from "../state/actions/addFaucetAccount";
|
||||||
import { deleteHook } from "../state/actions/deployHook";
|
import { deleteHook } from "../state/actions/deployHook";
|
||||||
|
import { capitalize } from "../utils/helpers";
|
||||||
|
|
||||||
export const AccountDialog = ({
|
export const AccountDialog = ({
|
||||||
activeAccountAddress,
|
activeAccountAddress,
|
||||||
@@ -42,12 +43,12 @@ export const AccountDialog = ({
|
|||||||
const snap = useSnapshot(state);
|
const snap = useSnapshot(state);
|
||||||
const [showSecret, setShowSecret] = useState(false);
|
const [showSecret, setShowSecret] = useState(false);
|
||||||
const activeAccount = snap.accounts.find(
|
const activeAccount = snap.accounts.find(
|
||||||
(account) => account.address === activeAccountAddress
|
account => account.address === activeAccountAddress
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
open={Boolean(activeAccountAddress)}
|
open={Boolean(activeAccountAddress)}
|
||||||
onOpenChange={(open) => {
|
onOpenChange={open => {
|
||||||
setShowSecret(false);
|
setShowSecret(false);
|
||||||
!open && setActiveAccountAddress(null);
|
!open && setActiveAccountAddress(null);
|
||||||
}}
|
}}
|
||||||
@@ -99,7 +100,7 @@ export const AccountDialog = ({
|
|||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const index = state.accounts.findIndex(
|
const index = state.accounts.findIndex(
|
||||||
(acc) => acc.address === activeAccount?.address
|
acc => acc.address === activeAccount?.address
|
||||||
);
|
);
|
||||||
state.accounts.splice(index, 1);
|
state.accounts.splice(index, 1);
|
||||||
}}
|
}}
|
||||||
@@ -165,7 +166,7 @@ export const AccountDialog = ({
|
|||||||
}}
|
}}
|
||||||
ghost
|
ghost
|
||||||
size="xs"
|
size="xs"
|
||||||
onClick={() => setShowSecret((curr) => !curr)}
|
onClick={() => setShowSecret(curr => !curr)}
|
||||||
>
|
>
|
||||||
{showSecret ? "Hide" : "Show"}
|
{showSecret ? "Hide" : "Show"}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -252,7 +253,7 @@ export const AccountDialog = ({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{activeAccount && activeAccount.hooks.length > 0
|
{activeAccount && activeAccount.hooks.length > 0
|
||||||
? activeAccount.hooks.map((i) => {
|
? activeAccount.hooks.map(i => {
|
||||||
return (
|
return (
|
||||||
<a
|
<a
|
||||||
key={i}
|
key={i}
|
||||||
@@ -301,7 +302,7 @@ interface AccountProps {
|
|||||||
showHookStats?: boolean;
|
showHookStats?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Accounts: FC<AccountProps> = (props) => {
|
const Accounts: FC<AccountProps> = props => {
|
||||||
const snap = useSnapshot(state);
|
const snap = useSnapshot(state);
|
||||||
const [activeAccountAddress, setActiveAccountAddress] = useState<
|
const [activeAccountAddress, setActiveAccountAddress] = useState<
|
||||||
string | null
|
string | null
|
||||||
@@ -309,7 +310,7 @@ const Accounts: FC<AccountProps> = (props) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchAccInfo = async () => {
|
const fetchAccInfo = async () => {
|
||||||
if (snap.clientStatus === "online") {
|
if (snap.clientStatus === "online") {
|
||||||
const requests = snap.accounts.map((acc) =>
|
const requests = snap.accounts.map(acc =>
|
||||||
snap.client?.send({
|
snap.client?.send({
|
||||||
id: `hooks-builder-req-info-${acc.address}`,
|
id: `hooks-builder-req-info-${acc.address}`,
|
||||||
command: "account_info",
|
command: "account_info",
|
||||||
@@ -322,7 +323,7 @@ const Accounts: FC<AccountProps> = (props) => {
|
|||||||
const balance = res?.account_data?.Balance as string;
|
const balance = res?.account_data?.Balance as string;
|
||||||
const sequence = res?.account_data?.Sequence as number;
|
const sequence = res?.account_data?.Sequence as number;
|
||||||
const accountToUpdate = state.accounts.find(
|
const accountToUpdate = state.accounts.find(
|
||||||
(acc) => acc.address === address
|
acc => acc.address === address
|
||||||
);
|
);
|
||||||
if (accountToUpdate) {
|
if (accountToUpdate) {
|
||||||
accountToUpdate.xrp = balance;
|
accountToUpdate.xrp = balance;
|
||||||
@@ -330,7 +331,7 @@ const Accounts: FC<AccountProps> = (props) => {
|
|||||||
accountToUpdate.error = null;
|
accountToUpdate.error = null;
|
||||||
} else {
|
} else {
|
||||||
const oldAccount = state.accounts.find(
|
const oldAccount = state.accounts.find(
|
||||||
(acc) => acc.address === res?.account
|
acc => acc.address === res?.account
|
||||||
);
|
);
|
||||||
if (oldAccount) {
|
if (oldAccount) {
|
||||||
oldAccount.xrp = "0";
|
oldAccount.xrp = "0";
|
||||||
@@ -341,7 +342,7 @@ const Accounts: FC<AccountProps> = (props) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const objectRequests = snap.accounts.map((acc) => {
|
const objectRequests = snap.accounts.map(acc => {
|
||||||
return snap.client?.send({
|
return snap.client?.send({
|
||||||
id: `hooks-builder-req-objects-${acc.address}`,
|
id: `hooks-builder-req-objects-${acc.address}`,
|
||||||
command: "account_objects",
|
command: "account_objects",
|
||||||
@@ -352,7 +353,7 @@ const Accounts: FC<AccountProps> = (props) => {
|
|||||||
objectResponses.forEach((res: any) => {
|
objectResponses.forEach((res: any) => {
|
||||||
const address = res?.account as string;
|
const address = res?.account as string;
|
||||||
const accountToUpdate = state.accounts.find(
|
const accountToUpdate = state.accounts.find(
|
||||||
(acc) => acc.address === address
|
acc => acc.address === address
|
||||||
);
|
);
|
||||||
if (accountToUpdate) {
|
if (accountToUpdate) {
|
||||||
accountToUpdate.hooks =
|
accountToUpdate.hooks =
|
||||||
@@ -416,9 +417,7 @@ const Accounts: FC<AccountProps> = (props) => {
|
|||||||
<Wallet size="15px" /> <Text css={{ lineHeight: 1 }}>Accounts</Text>
|
<Wallet size="15px" /> <Text css={{ lineHeight: 1 }}>Accounts</Text>
|
||||||
</Heading>
|
</Heading>
|
||||||
<Flex css={{ ml: "auto", gap: "$3", marginRight: "$3" }}>
|
<Flex css={{ ml: "auto", gap: "$3", marginRight: "$3" }}>
|
||||||
<Button ghost size="sm" onClick={() => addFaucetAccount(true)}>
|
<ImportAccountDialog type="create" />
|
||||||
Create
|
|
||||||
</Button>
|
|
||||||
<ImportAccountDialog />
|
<ImportAccountDialog />
|
||||||
</Flex>
|
</Flex>
|
||||||
</Flex>
|
</Flex>
|
||||||
@@ -435,7 +434,7 @@ const Accounts: FC<AccountProps> = (props) => {
|
|||||||
overflowY: "auto",
|
overflowY: "auto",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{snap.accounts.map((account) => (
|
{snap.accounts.map(account => (
|
||||||
<Flex
|
<Flex
|
||||||
column
|
column
|
||||||
key={account.address + account.name}
|
key={account.address + account.name}
|
||||||
@@ -488,7 +487,7 @@ const Accounts: FC<AccountProps> = (props) => {
|
|||||||
{!props.hideDeployBtn && (
|
{!props.hideDeployBtn && (
|
||||||
<div
|
<div
|
||||||
className="hook-deploy-button"
|
className="hook-deploy-button"
|
||||||
onClick={(e) => {
|
onClick={e => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -514,32 +513,71 @@ const Accounts: FC<AccountProps> = (props) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const transactionsOptions = transactionsData.map((tx) => ({
|
export const transactionsOptions = transactionsData.map(tx => ({
|
||||||
value: tx.TransactionType,
|
value: tx.TransactionType,
|
||||||
label: tx.TransactionType,
|
label: tx.TransactionType,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const ImportAccountDialog = () => {
|
const ImportAccountDialog = ({
|
||||||
const [value, setValue] = useState("");
|
type = "import",
|
||||||
|
}: {
|
||||||
|
type?: "import" | "create";
|
||||||
|
}) => {
|
||||||
|
const [secret, setSecret] = useState("");
|
||||||
|
const [name, setName] = useState("");
|
||||||
|
|
||||||
|
const btnText = type === "import" ? "Import" : "Create";
|
||||||
|
const title = type === "import" ? "Import Account" : "Create Account";
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
if (type === "create") {
|
||||||
|
const value = capitalize(name);
|
||||||
|
await addFaucetAccount(value, true);
|
||||||
|
setName("");
|
||||||
|
setSecret("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
importAccount(secret, name);
|
||||||
|
setName("");
|
||||||
|
setSecret("");
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<Dialog>
|
<Dialog>
|
||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
<Button ghost size="sm">
|
<Button ghost size="sm">
|
||||||
Import
|
{btnText}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
<DialogContent>
|
<DialogContent aria-describedby={undefined}>
|
||||||
<DialogTitle>Import account</DialogTitle>
|
<DialogTitle css={{ mb: "$4" }}>{title}</DialogTitle>
|
||||||
<DialogDescription>
|
<Flex column>
|
||||||
<Label>Add account secret</Label>
|
<Box css={{ mb: "$2" }}>
|
||||||
<Input
|
<Label>
|
||||||
name="secret"
|
Account name <Text muted>(optional)</Text>
|
||||||
type="password"
|
</Label>
|
||||||
autoComplete="new-password"
|
<Input
|
||||||
value={value}
|
name="name"
|
||||||
onChange={(e) => setValue(e.target.value)}
|
type="text"
|
||||||
/>
|
autoComplete="off"
|
||||||
</DialogDescription>
|
autoCapitalize="on"
|
||||||
|
value={name}
|
||||||
|
onChange={e => setName(e.target.value)}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
{type === "import" && (
|
||||||
|
<Box>
|
||||||
|
<Label>Account secret</Label>
|
||||||
|
<Input
|
||||||
|
required
|
||||||
|
name="secret"
|
||||||
|
type="password"
|
||||||
|
autoComplete="new-password"
|
||||||
|
value={secret}
|
||||||
|
onChange={e => setSecret(e.target.value)}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
</Flex>
|
||||||
|
|
||||||
<Flex
|
<Flex
|
||||||
css={{
|
css={{
|
||||||
@@ -552,14 +590,8 @@ const ImportAccountDialog = () => {
|
|||||||
<Button outline>Cancel</Button>
|
<Button outline>Cancel</Button>
|
||||||
</DialogClose>
|
</DialogClose>
|
||||||
<DialogClose asChild>
|
<DialogClose asChild>
|
||||||
<Button
|
<Button type="submit" variant="primary" onClick={handleSubmit}>
|
||||||
variant="primary"
|
{title}
|
||||||
onClick={() => {
|
|
||||||
importAccount(value);
|
|
||||||
setValue("");
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Import account
|
|
||||||
</Button>
|
</Button>
|
||||||
</DialogClose>
|
</DialogClose>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export const names = [
|
|||||||
* new account with 10 000 XRP. Hooks Testnet /newcreds endpoint
|
* new account with 10 000 XRP. Hooks Testnet /newcreds endpoint
|
||||||
* is protected with CORS so that's why we did our own endpoint
|
* is protected with CORS so that's why we did our own endpoint
|
||||||
*/
|
*/
|
||||||
export const addFaucetAccount = async (showToast: boolean = false) => {
|
export const addFaucetAccount = async (name?: string, showToast: boolean = false) => {
|
||||||
// Lets limit the number of faucet accounts to 5 for now
|
// Lets limit the number of faucet accounts to 5 for now
|
||||||
if (state.accounts.length > 5) {
|
if (state.accounts.length > 5) {
|
||||||
return toast.error("You can only have maximum 6 accounts");
|
return toast.error("You can only have maximum 6 accounts");
|
||||||
@@ -52,7 +52,7 @@ export const addFaucetAccount = async (showToast: boolean = false) => {
|
|||||||
}
|
}
|
||||||
const currNames = state.accounts.map(acc => acc.name);
|
const currNames = state.accounts.map(acc => acc.name);
|
||||||
state.accounts.push({
|
state.accounts.push({
|
||||||
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,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import state from '../index';
|
|||||||
import { names } from './addFaucetAccount';
|
import { names } from './addFaucetAccount';
|
||||||
|
|
||||||
// Adds test account to global state with secret key
|
// Adds test account to global state with secret key
|
||||||
export const importAccount = (secret: string) => {
|
export const importAccount = (secret: string, name?: string) => {
|
||||||
if (!secret) {
|
if (!secret) {
|
||||||
return toast.error("You need to add secret!");
|
return toast.error("You need to add secret!");
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ export const importAccount = (secret: string) => {
|
|||||||
return toast.error(`Couldn't create account!`);
|
return toast.error(`Couldn't create account!`);
|
||||||
}
|
}
|
||||||
state.accounts.push({
|
state.accounts.push({
|
||||||
name: names[state.accounts.length],
|
name: name || names[state.accounts.length],
|
||||||
address: account.address || "",
|
address: account.address || "",
|
||||||
secret: account.secret.familySeed || "",
|
secret: account.secret.familySeed || "",
|
||||||
xrp: "0",
|
xrp: "0",
|
||||||
|
|||||||
@@ -6,4 +6,10 @@ export const guessZipFileName = (files: File[]) => {
|
|||||||
let parts = (files.filter(f => f.name.endsWith('.c'))[0]?.name || 'hook').split('.')
|
let parts = (files.filter(f => f.name.endsWith('.c'))[0]?.name || 'hook').split('.')
|
||||||
parts = parts.length > 1 ? parts.slice(0, -1) : parts
|
parts = parts.length > 1 ? parts.slice(0, -1) : parts
|
||||||
return parts.join('')
|
return parts.join('')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const capitalize = (value?: string) => {
|
||||||
|
if (!value) return '';
|
||||||
|
|
||||||
|
return value[0].toLocaleUpperCase() + value.slice(1);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user