diff --git a/src/pages/addresses/AddressButtonRow.tsx b/src/pages/addresses/AddressButtonRow.tsx
index 638914e..b97744b 100644
--- a/src/pages/addresses/AddressButtonRow.tsx
+++ b/src/pages/addresses/AddressButtonRow.tsx
@@ -1,73 +1,161 @@
// Copyright (c) 2020-2021 Drew Lemmy
// This file is part of KristWeb 2 under AGPL-3.0.
// Full details: https://github.com/tmpim/KristWeb2/blob/master/LICENSE.txt
-import { Button, Tooltip } from "antd";
+import { useEffect } from "react";
+import { Button, Tooltip, Menu } from "antd";
import { SendOutlined, SwapOutlined, UserAddOutlined, EditOutlined } from "@ant-design/icons";
-import { useTranslation } from "react-i18next";
+import { useTFns } from "@utils/i18n";
import { isV1Address } from "@utils/currency";
-import { KristAddressWithNames } from "@api/lookup";
import { Wallet } from "@wallets";
import { Contact } from "@contacts";
-import { WalletEditButton } from "../wallets/WalletEditButton";
-import { ContactEditButton } from "../contacts/ContactEditButton";
-import { SendTransactionModalLink } from "@comp/transactions/SendTransactionModalLink";
+
+import { useTopMenuOptions } from "@layout/nav/TopMenu";
+import { useAuth } from "@comp/auth";
+import { OpenEditWalletFn } from "@pages/wallets/WalletEditButton";
+import { OpenEditContactFn } from "@pages/contacts/ContactEditButton";
+import { OpenSendTxFn } from "@comp/transactions/SendTransactionModalLink";
interface Props {
- address: KristAddressWithNames;
+ address: string;
myWallet?: Wallet;
myContact?: Contact;
+
+ openEditWallet: OpenEditWalletFn;
+ openEditContact: OpenEditContactFn;
+ openSendTx: OpenSendTxFn;
}
export function AddressButtonRow({
address,
myWallet,
- myContact
-}: Props): JSX.Element {
- const { t } = useTranslation();
+ myContact,
- const isV1 = address && isV1Address(address.address);
+ openEditWallet,
+ openEditContact,
+ openSendTx
+}: Props): JSX.Element {
+ const { t, tStr, tKey } = useTFns("address.");
+
+ const isV1 = isV1Address(address);
+
+ const promptAuth = useAuth();
+
+ const [usingTopMenu, set, unset] = useTopMenuOptions();
+ useEffect(() => {
+ set(<>
+ {/* Send/transfer Krist */}
+
: }
+ disabled={isV1}
+ onClick={() => promptAuth(false, () =>
+ openSendTx(undefined, address))}
+ >
+ {t(
+ tKey(myWallet ? "buttonTransferKrist" : "buttonSendKrist"),
+ { address }
+ )}
+
+
+ {/* Add contact/edit wallet */}
+ {myWallet
+ ? (
+ }
+ onClick={() => promptAuth(true, () => openEditWallet(myWallet))}
+ >
+ {tStr("buttonEditWallet")}
+
+ )
+ : (
+ : }
+ onClick={() => openEditContact(address, myContact)}
+ >
+ {tStr(myContact ? "buttonEditContact" : "buttonAddContact")}
+
+ )
+ }
+ >);
+ return unset;
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [
+ t, tStr, tKey, set, unset, address, openSendTx, openEditWallet,
+ openEditContact, isV1, promptAuth, myContact?.id, myWallet?.id
+ ]);
+
+ return <>
+ {/* Only display the buttons on desktop */}
+ {!usingTopMenu && }
+ >;
+}
+
+function Buttons({
+ address,
+ myWallet,
+ myContact,
+ isV1,
+
+ openEditWallet,
+ openEditContact,
+ openSendTx
+}: Props & { isV1: boolean }): JSX.Element {
+ const { t, tStr, tKey } = useTFns("address.");
+
+ const promptAuth = useAuth();
const sendButton = : }
disabled={isV1}
+ onClick={() => promptAuth(false, () =>
+ openSendTx(undefined, address))}
>
- {t(myWallet ? "address.buttonTransferKrist" : "address.buttonSendKrist",
- { address: address.address })}
+ {t(
+ tKey(myWallet ? "buttonTransferKrist" : "buttonSendKrist"),
+ { address }
+ )}
;
return <>
{/* Send/transfer Krist button */}
{isV1
? ( // Disable the button and show a tooltip for V1 addresses
-
+
{sendButton}
)
- : ( // Otherwise, enable the button
-
- {sendButton}
-
- )}
+ : sendButton // Otherwise, enable the button
+ }
{/* Add contact/edit wallet button */}
{myWallet
? (
-
- }>{t("address.buttonEditWallet")}
-
+ }
+ onClick={() => promptAuth(true, () => openEditWallet(myWallet))}
+ >
+ {tStr("buttonEditWallet")}
+
)
: (
-
- : }>
- {t(myContact
- ? "address.buttonEditContact"
- : "address.buttonAddContact")}
-
-
+ : }
+ onClick={() => openEditContact(address, myContact)}
+ >
+ {tStr(myContact ? "buttonEditContact" : "buttonAddContact")}
+
)}
>;
}
diff --git a/src/pages/addresses/AddressPage.tsx b/src/pages/addresses/AddressPage.tsx
index b08e932..ea2f716 100644
--- a/src/pages/addresses/AddressPage.tsx
+++ b/src/pages/addresses/AddressPage.tsx
@@ -27,6 +27,10 @@
import { getVerified, VerifiedDescription } from "@comp/addresses/VerifiedAddress";
+import { useEditWalletModal } from "@pages/wallets/WalletEditButton";
+import { useEditContactModal } from "@pages/contacts/ContactEditButton";
+import { useSendTransactionModal } from "@comp/transactions/SendTransactionModalLink";
+
import "./AddressPage.less";
const { Text } = Typography;
@@ -54,6 +58,10 @@
const showVerifiedDesc = verified?.description || verified?.website ||
verified?.isActive === false;
+ const [openEditWallet, editWalletModal] = useEditWalletModal();
+ const [openEditContact, editContactModal] = useEditContactModal();
+ const [openSendTx, sendTxModal] = useSendTransactionModal();
+
return <>
{/* Address and buttons */}
@@ -64,9 +72,13 @@
{/* Buttons (e.g. Send Krist, Add contact) */}
@@ -150,6 +162,10 @@
+
+ {sendTxModal}
+ {editWalletModal}
+ {editContactModal}
>;
}
diff --git a/src/pages/contacts/AddContactModal.tsx b/src/pages/contacts/AddContactModal.tsx
index 6786816..090389a 100644
--- a/src/pages/contacts/AddContactModal.tsx
+++ b/src/pages/contacts/AddContactModal.tsx
@@ -1,7 +1,7 @@
// Copyright (c) 2020-2021 Drew Lemmy
// This file is part of KristWeb 2 under AGPL-3.0.
// Full details: https://github.com/tmpim/KristWeb2/blob/master/LICENSE.txt
-import { useState } from "react";
+import { useState, useEffect, useMemo } from "react";
import { Modal, Form, Input, message, notification } from "antd";
import { useTFns } from "@utils/i18n";
@@ -104,6 +104,20 @@
setAddress(values.address || "");
}
+ const initialValues = useMemo(() => ({
+ label: editing?.label ?? undefined,
+ address: editing?.address ?? initialAddress
+ }), [
+ initialAddress, editing?.label, editing?.address
+ ]);
+
+ // Refresh the form if the initial values have changed
+ useEffect(() => {
+ if (!form || (!initialAddress && !editing?.address)) return;
+ form.setFieldsValue(initialValues);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [form, initialAddress, editing?.label, editing?.address]);
+
return promptAuth(true, () => openEditContact(contact))}
+ onClick={() => promptAuth(true, () => openEditContact(undefined, contact))}
trigger={["click"]}
overlay={() => (