import { getGetServerSideProps } from '@/api/ssrApollo' import { Form, ClientInput, ClientCheckbox, PasswordInput } from '@/components/form' import { CenterLayout } from '@/components/layout' import { WalletSecurityBanner } from '@/components/banners' import { WalletLogs } from '@/components/wallet-logger' import { useToast } from '@/components/toast' import { useRouter } from 'next/router' import { useWallet, Status } from 'wallets' import Info from '@/components/info' import Text from '@/components/text' import { AutowithdrawSettings } from '@/components/autowithdraw-shared' import dynamic from 'next/dynamic' import { useEffect, useState } from 'react' const WalletButtonBar = dynamic(() => import('@/components/wallet-buttonbar.js'), { ssr: false }) export const getServerSideProps = getGetServerSideProps({ authRequired: true }) export default function WalletSettings () { const toaster = useToast() const router = useRouter() const { wallet: name } = router.query const wallet = useWallet(name) const [mounted, setMounted] = useState(false) useEffect(() => { // mounted is required since available might depend // on values that are only available on the client (and not during SSR) // and thus we need to render the component again on the client setMounted(true) }, []) const initial = wallet.fields.reduce((acc, field) => { // We still need to run over all wallet fields via reduce // even though we use wallet.config as the initial value // since wallet.config is empty when wallet is not configured. // Also, wallet.config includes general fields like // 'enabled' and 'priority' which are not defined in wallet.fields. return { ...acc, [field.name]: wallet.config?.[field.name] || '' } }, wallet.config) // check if wallet uses the form-level validation built into Formik or a Yup schema const validateProps = typeof wallet.fieldValidation === 'function' ? { validate: wallet.fieldValidation } : { schema: wallet.fieldValidation } const available = mounted && wallet.available !== undefined ? wallet.available : wallet.isConfigured return (

{wallet.card.title}

{wallet.card.subtitle}
{!wallet.walletType && wallet.hasConfig > 0 && }
{ try { const newConfig = !wallet.isConfigured // enable wallet if wallet was just configured if (newConfig) { values.enabled = true } await wallet.save(values) if (values.enabled) wallet.enable() else wallet.disable() toaster.success('saved settings') router.push('/settings/wallets') } catch (err) { console.error(err) const message = 'failed to attach: ' + err.message || err.toString?.() toaster.danger(message) } }} > {wallet.walletType ? : ( )} { try { await wallet.delete() toaster.success('saved settings') router.push('/settings/wallets') } catch (err) { console.error(err) const message = 'failed to detach: ' + err.message || err.toString?.() toaster.danger(message) } }} />
) } function WalletFields ({ wallet: { config, fields, isConfigured } }) { return fields .map(({ name, label, type, help, optional, editable, ...props }, i) => { const rawProps = { ...props, name, initialValue: config?.[name], readOnly: isConfigured && editable === false, groupClassName: props.hidden ? 'd-none' : undefined, label: label ? (
{label} {/* help can be a string or object to customize the label */} {help && ( {help.text || help} )} {optional && ( {typeof optional === 'boolean' ? 'optional' : {optional}} )}
) : undefined, required: !optional, autoFocus: i === 0 } if (type === 'text') { return } if (type === 'password') { return } return null }) }