Fixes issue #101

This commit is contained in:
Valtteri Karesto
2022-03-09 12:29:20 +02:00
parent b90bf67c20
commit 8f004ee4da

View File

@@ -36,11 +36,13 @@ 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(account => account.address === activeAccountAddress); const activeAccount = snap.accounts.find(
(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);
}} }}
@@ -135,7 +137,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>
@@ -221,13 +223,15 @@ 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<string | null>(null); const [activeAccountAddress, setActiveAccountAddress] = useState<
string | null
>(null);
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: acc.address, id: acc.address,
command: "account_info", command: "account_info",
@@ -239,13 +243,15 @@ const Accounts: FC<AccountProps> = props => {
const address = res?.account_data?.Account as string; const address = res?.account_data?.Account as string;
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(acc => acc.address === address); const accountToUpdate = state.accounts.find(
(acc) => acc.address === address
);
if (accountToUpdate) { if (accountToUpdate) {
accountToUpdate.xrp = balance; accountToUpdate.xrp = balance;
accountToUpdate.sequence = sequence; accountToUpdate.sequence = sequence;
} }
}); });
const objectRequests = snap.accounts.map(acc => { const objectRequests = snap.accounts.map((acc) => {
return snap.client?.send({ return snap.client?.send({
id: `${acc.address}-hooks`, id: `${acc.address}-hooks`,
command: "account_objects", command: "account_objects",
@@ -255,7 +261,9 @@ const Accounts: FC<AccountProps> = props => {
const objectResponses = await Promise.all(objectRequests); const objectResponses = await Promise.all(objectRequests);
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(acc => acc.address === address); const accountToUpdate = state.accounts.find(
(acc) => acc.address === address
);
if (accountToUpdate) { if (accountToUpdate) {
accountToUpdate.hooks = res.account_objects accountToUpdate.hooks = res.account_objects
.filter((ac: any) => ac?.LedgerEntryType === "Hook") .filter((ac: any) => ac?.LedgerEntryType === "Hook")
@@ -337,7 +345,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}
@@ -383,28 +391,37 @@ const Accounts: FC<AccountProps> = props => {
</Text> </Text>
</Box> </Box>
{!props.hideDeployBtn && ( {!props.hideDeployBtn && (
<Button <div
css={{ ml: "auto" }} onClick={(e) => {
size="xs" e.preventDefault();
uppercase
isLoading={account.isLoading}
disabled={
account.isLoading ||
!snap.files.filter(file => file.compiledWatContent).length
}
variant="secondary"
onClick={e => {
e.stopPropagation(); e.stopPropagation();
deployHook(account);
}} }}
> >
Deploy <Button
</Button> css={{ ml: "auto" }}
size="xs"
uppercase
isLoading={account.isLoading}
disabled={
account.isLoading ||
!snap.files.filter((file) => file.compiledWatContent)
.length
}
variant="secondary"
onClick={(e) => {
e.stopPropagation();
deployHook(account);
}}
>
Deploy
</Button>
</div>
)} )}
</Flex> </Flex>
{props.showHookStats && ( {props.showHookStats && (
<Text muted small css={{ mt: "$2" }}> <Text muted small css={{ mt: "$2" }}>
{account.hooks.length} hook{account.hooks.length === 1 ? "" : "s"} installed {account.hooks.length} hook
{account.hooks.length === 1 ? "" : "s"} installed
</Text> </Text>
)} )}
</Flex> </Flex>
@@ -436,7 +453,7 @@ const ImportAccountDialog = () => {
name="secret" name="secret"
type="password" type="password"
value={value} value={value}
onChange={e => setValue(e.target.value)} onChange={(e) => setValue(e.target.value)}
/> />
</DialogDescription> </DialogDescription>