diff --git a/public/locales/en.json b/public/locales/en.json index 34396f2..7132156 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -181,7 +181,9 @@ "errorMissingWalletTitle": "Wallet not found", "errorMissingWalletDescription": "The wallet you are trying to edit no longer exists.", "errorDecryptTitle": "Incorrect master password", - "errorDecryptDescription": "Failed to decrypt the wallet password. Is the master password correct?" + "errorDecryptDescription": "Failed to decrypt the wallet password. Is the master password correct?", + "errorWalletLimitTitle": "Wallet limit reached", + "errorWalletLimitDescription": "You currently cannot add any more wallets." }, "credits": { diff --git a/src/krist/wallets/Wallet.ts b/src/krist/wallets/Wallet.ts index e41a581..231fcd4 100644 --- a/src/krist/wallets/Wallet.ts +++ b/src/krist/wallets/Wallet.ts @@ -55,6 +55,12 @@ export interface DecryptedWallet { password: string; privatekey: string } +/** The limit provided by the Krist server for a single address lookup. In the + * future I may implement batching for these, but for now, this seems like a + * reasonable compromise to limit wallet storage. It should also give us a fair + * upper bound for potential performance issues. */ +export const ADDRESS_LIST_LIMIT = 128; + /** Get the local storage key for a given wallet. */ export function getWalletKey(wallet: Wallet): string { return `wallet2-${wallet.id}`; diff --git a/src/pages/wallets/AddWalletModal.tsx b/src/pages/wallets/AddWalletModal.tsx index 0f3857d..7c86e43 100644 --- a/src/pages/wallets/AddWalletModal.tsx +++ b/src/pages/wallets/AddWalletModal.tsx @@ -15,7 +15,7 @@ import { WalletFormatName, applyWalletFormat, formatNeedsUsername } from "../../krist/wallets/formats/WalletFormat"; import { getSelectWalletFormat } from "../../components/wallets/SelectWalletFormat"; import { makeV2Address } from "../../krist/AddressAlgo"; -import { addWallet, decryptWallet, editWallet, Wallet } from "../../krist/wallets/Wallet"; +import { addWallet, decryptWallet, editWallet, Wallet, ADDRESS_LIST_LIMIT } from "../../krist/wallets/Wallet"; const { Text } = Typography; @@ -55,7 +55,7 @@ const [form] = Form.useForm(); const passwordInput = useRef(null); const [calculatedAddress, setCalculatedAddress] = useState(); - const [formatState, setFormatState] = useState(initialFormat); + const [formatState, setFormatState] = useState(editing?.format || initialFormat); async function onSubmit() { if (!masterPassword) return notification.error({ @@ -80,6 +80,14 @@ form.resetFields(); setVisible(false); } else { // Add/create wallet + // Check if we reached the wallet limit + if (Object.keys(wallets).length >= ADDRESS_LIST_LIMIT) { + return notification.error({ + message: t("addWallet.errorWalletLimitTitle"), + description: t("addWallet.errorWalletLimitDescription") + }); + } + // Check if the wallet already exists if (Object.values(wallets).find(w => w.address === calculatedAddress)) { return notification.error({