From 9edcd3464357a44b5730f4072e5de3567d052227 Mon Sep 17 00:00:00 2001 From: danidfra Date: Thu, 20 Feb 2025 21:07:02 -0300 Subject: [PATCH] Add relays and mints pages --- .../my-wallet/components/create-wallet.tsx | 2 +- .../{relay-field => }/editable-lists.tsx | 3 +- .../my-wallet/components/wallet-mints.tsx | 69 +++++++++++++++++++ .../my-wallet/components/wallet-relays.tsx | 69 +++++++++++++++++++ src/features/ui/index.tsx | 4 ++ src/features/ui/util/async-components.ts | 2 + src/locales/en.json | 4 +- 7 files changed, 150 insertions(+), 3 deletions(-) rename src/features/my-wallet/components/{relay-field => }/editable-lists.tsx (96%) create mode 100644 src/features/my-wallet/components/wallet-mints.tsx create mode 100644 src/features/my-wallet/components/wallet-relays.tsx diff --git a/src/features/my-wallet/components/create-wallet.tsx b/src/features/my-wallet/components/create-wallet.tsx index 7934d7532..72d3fe648 100644 --- a/src/features/my-wallet/components/create-wallet.tsx +++ b/src/features/my-wallet/components/create-wallet.tsx @@ -10,7 +10,7 @@ import HStack from 'soapbox/components/ui/hstack.tsx'; import Stack from 'soapbox/components/ui/stack.tsx'; import SvgIcon from 'soapbox/components/ui/svg-icon.tsx'; import Text from 'soapbox/components/ui/text.tsx'; -import { MintEditor } from 'soapbox/features/my-wallet/components/relay-field/editable-lists.tsx'; +import { MintEditor } from 'soapbox/features/my-wallet/components/editable-lists.tsx'; import { useApi } from 'soapbox/hooks/useApi.ts'; import { useOwnAccount } from 'soapbox/hooks/useOwnAccount.ts'; import { WalletData, baseWalletSchema } from 'soapbox/schemas/wallet.ts'; diff --git a/src/features/my-wallet/components/relay-field/editable-lists.tsx b/src/features/my-wallet/components/editable-lists.tsx similarity index 96% rename from src/features/my-wallet/components/relay-field/editable-lists.tsx rename to src/features/my-wallet/components/editable-lists.tsx index 8f5b60124..3b84593a1 100644 --- a/src/features/my-wallet/components/relay-field/editable-lists.tsx +++ b/src/features/my-wallet/components/editable-lists.tsx @@ -55,4 +55,5 @@ const RelayEditor: React.FC> = ({ items, setItems }) => { return ; }; -export { RelayEditor, MintEditor }; \ No newline at end of file +export { RelayEditor, MintEditor }; +export type { IEditableList }; \ No newline at end of file diff --git a/src/features/my-wallet/components/wallet-mints.tsx b/src/features/my-wallet/components/wallet-mints.tsx new file mode 100644 index 000000000..138e1f3ed --- /dev/null +++ b/src/features/my-wallet/components/wallet-mints.tsx @@ -0,0 +1,69 @@ +import { useEffect, useState } from 'react'; +import { defineMessages, useIntl } from 'react-intl'; + +import Button from 'soapbox/components/ui/button.tsx'; +import { Column } from 'soapbox/components/ui/column.tsx'; +import Stack from 'soapbox/components/ui/stack.tsx'; +import { RelayEditor } from 'soapbox/features/my-wallet/components/editable-lists.tsx'; +import { useApi } from 'soapbox/hooks/useApi.ts'; +import { WalletData, baseWalletSchema } from 'soapbox/schemas/wallet.ts'; +import toast from 'soapbox/toast.tsx'; + +const messages = defineMessages({ + title: { id: 'my_wallet.mints', defaultMessage: 'Mints' }, + error: { id: 'my_wallet.loading_error', defaultMessage: 'An unexpected error occurred while loading your wallet data.' }, + send: { id: 'common.send', defaultMessage: 'Send' }, +}); + +const MyWalletMints = () => { + const intl = useIntl(); + const api = useApi(); + + const [mints, setMints] = useState([]); + + const fetchWallet = async () => { + try { + const response = await api.get('/api/v1/ditto/cashu/wallet'); + const data: WalletData = await response.json(); + if (data) { + const normalizedData = baseWalletSchema.parse(data); + setMints(normalizedData.mints); + } + + } catch (error) { + toast.error(intl.formatMessage(messages.error)); + } + }; + + const handleClick = async () =>{ + try { + const response = await api.post('/api/v1/ditto/cashu/wallet'); + const data: WalletData = await response.json(); + if (data) { + const normalizedData = baseWalletSchema.parse(data); + setMints(normalizedData.mints); + } + + } catch (error) { + toast.error('Wallet not found'); + } + }; + + useEffect(() => { + fetchWallet(); + }, []); + + return ( + + + + + + + + ); +}; + +export default MyWalletMints; diff --git a/src/features/my-wallet/components/wallet-relays.tsx b/src/features/my-wallet/components/wallet-relays.tsx new file mode 100644 index 000000000..cb7eaf7d9 --- /dev/null +++ b/src/features/my-wallet/components/wallet-relays.tsx @@ -0,0 +1,69 @@ +import { useEffect, useState } from 'react'; +import { defineMessages, useIntl } from 'react-intl'; + +import Button from 'soapbox/components/ui/button.tsx'; +import { Column } from 'soapbox/components/ui/column.tsx'; +import Stack from 'soapbox/components/ui/stack.tsx'; +import { RelayEditor } from 'soapbox/features/my-wallet/components/editable-lists.tsx'; +import { useApi } from 'soapbox/hooks/useApi.ts'; +import { WalletData, baseWalletSchema } from 'soapbox/schemas/wallet.ts'; +import toast from 'soapbox/toast.tsx'; + +const messages = defineMessages({ + title: { id: 'my_wallet.relays', defaultMessage: 'Wallet Relays' }, + error: { id: 'my_wallet.loading_error', defaultMessage: 'An unexpected error occurred while loading your wallet data.' }, + send: { id: 'common.send', defaultMessage: 'Send' }, +}); + +const MyWalletRelays = () => { + const intl = useIntl(); + const api = useApi(); + + const [relays, setRelays] = useState(['teste.com']); + + const fetchWallet = async () => { + try { + const response = await api.get('/api/v1/ditto/cashu/wallet'); + const data: WalletData = await response.json(); + if (data) { + const normalizedData = baseWalletSchema.parse(data); + setRelays(normalizedData.relays); + } + + } catch (error) { + toast.error(intl.formatMessage(messages.error)); + } + }; + + const handleClick = async () =>{ + try { + const response = await api.post('/api/v1/ditto/cashu/wallet'); + const data: WalletData = await response.json(); + if (data) { + const normalizedData = baseWalletSchema.parse(data); + setRelays(normalizedData.relays); + } + + } catch (error) { + toast.error('Wallet not found'); + } + }; + + useEffect(() => { + fetchWallet(); + }, []); + + return ( + + + + + + + + ); +}; + +export default MyWalletRelays; diff --git a/src/features/ui/index.tsx b/src/features/ui/index.tsx index 17e2b09e1..eff69bc7d 100644 --- a/src/features/ui/index.tsx +++ b/src/features/ui/index.tsx @@ -74,6 +74,8 @@ import { Bookmarks, Settings, MyWallet, + MyWalletRelays, + MyWalletMints, EditProfile, EditEmail, EditPassword, @@ -333,6 +335,8 @@ const SwitchingColumnsArea: React.FC = ({ children }) => + + diff --git a/src/features/ui/util/async-components.ts b/src/features/ui/util/async-components.ts index 7565054e0..6b630b00c 100644 --- a/src/features/ui/util/async-components.ts +++ b/src/features/ui/util/async-components.ts @@ -182,4 +182,6 @@ export const ZapSplitModal = lazy(() => import('soapbox/features/ui/components/m export const CaptchaModal = lazy(() => import('soapbox/features/ui/components/modals/captcha-modal/captcha-modal.tsx')); export const NostrBunkerLogin = lazy(() => import('soapbox/features/nostr/nostr-bunker-login.tsx')); export const MyWallet = lazy(() => import('soapbox/features/my-wallet/index.tsx')); +export const MyWalletRelays = lazy(() => import('soapbox/features/my-wallet/components/wallet-relays.tsx')); +export const MyWalletMints = lazy(() => import('soapbox/features/my-wallet/components/wallet-mints.tsx')); export const StreakModal = lazy(() => import('soapbox/features/ui/components/modals/streak-modal.tsx')); diff --git a/src/locales/en.json b/src/locales/en.json index 8ce7f9e7f..e3005d672 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -439,6 +439,7 @@ "column_forbidden.title": "Forbidden", "common.cancel": "Cancel", "common.save": "Save", + "common.send": "Send", "compare_history_modal.header": "Edit history", "compose.character_counter.title": "Used {chars} out of {maxChars} {maxChars, plural, one {character} other {characters}}", "compose.edit_success": "Your post was edited", @@ -1117,9 +1118,10 @@ "my_wallet.create_wallet.button": "Create wallet", "my_wallet.create_wallet.question": "Do you want create one?", "my_wallet.create_wallet.title": "You don't have a wallet", + "my_wallet.loading_error": "An unexpected error occurred while loading your wallet data.", "my_wallet.management": "Wallet Management", "my_wallet.mints": "Mints", - "my_wallet.relays": "Relays", + "my_wallet.relays": "Wallet Relays", "my_wallet.transactions": "Transactions", "navbar.login.action": "Log in", "navbar.login.email.placeholder": "E-mail address",