Fix sendPayment called with empty config
* removed useEffect such that config is available on first render * fix hydration error using dynamic import without SSR
This commit is contained in:
parent
4a16cc17aa
commit
d7c81cfa9f
|
@ -1,12 +1,11 @@
|
||||||
import { useCallback, useEffect, useState } from 'react'
|
import { SSR } from '@/lib/constants'
|
||||||
|
import { useCallback, useState } from 'react'
|
||||||
|
|
||||||
export default function useLocalState (storageKey, initialValue = '') {
|
export default function useLocalState (storageKey, initialValue = '') {
|
||||||
const [value, innerSetValue] = useState(initialValue)
|
const [value, innerSetValue] = useState(
|
||||||
|
initialValue ||
|
||||||
useEffect(() => {
|
(SSR ? null : JSON.parse(window.localStorage.getItem(storageKey)))
|
||||||
const value = window.localStorage.getItem(storageKey)
|
)
|
||||||
innerSetValue(JSON.parse(value))
|
|
||||||
}, [storageKey])
|
|
||||||
|
|
||||||
const setValue = useCallback((newValue) => {
|
const setValue = useCallback((newValue) => {
|
||||||
window.localStorage.setItem(storageKey, JSON.stringify(newValue))
|
window.localStorage.setItem(storageKey, JSON.stringify(newValue))
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { Button } from 'react-bootstrap'
|
||||||
|
import CancelButton from './cancel-button'
|
||||||
|
import { SubmitButton } from './form'
|
||||||
|
|
||||||
|
export default function WalletButtonBar ({
|
||||||
|
wallet, disable,
|
||||||
|
className, children, onDelete, onCancel, hasCancel = true,
|
||||||
|
createText = 'attach', deleteText = 'detach', editText = 'save'
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className={`mt-3 ${className}`}>
|
||||||
|
<div className='d-flex justify-content-between'>
|
||||||
|
{wallet.isConfigured &&
|
||||||
|
<Button onClick={onDelete} variant='grey-medium'>{deleteText}</Button>}
|
||||||
|
{children}
|
||||||
|
<div className='d-flex align-items-center ms-auto'>
|
||||||
|
{hasCancel && <CancelButton onClick={onCancel} />}
|
||||||
|
<SubmitButton variant='primary' disabled={disable}>{wallet.isConfigured ? editText : createText}</SubmitButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
|
@ -1,10 +1,8 @@
|
||||||
import { Badge, Button, Card } from 'react-bootstrap'
|
import { Badge, Card } from 'react-bootstrap'
|
||||||
import styles from '@/styles/wallet.module.css'
|
import styles from '@/styles/wallet.module.css'
|
||||||
import Plug from '@/svgs/plug.svg'
|
import Plug from '@/svgs/plug.svg'
|
||||||
import Gear from '@/svgs/settings-5-fill.svg'
|
import Gear from '@/svgs/settings-5-fill.svg'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import CancelButton from './cancel-button'
|
|
||||||
import { SubmitButton } from './form'
|
|
||||||
import { useWallet, Status } from './wallet'
|
import { useWallet, Status } from './wallet'
|
||||||
|
|
||||||
export function WalletCard ({ name, title, badges, status }) {
|
export function WalletCard ({ name, title, badges, status }) {
|
||||||
|
@ -51,23 +49,3 @@ export function WalletCard ({ name, title, badges, status }) {
|
||||||
</Card>
|
</Card>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function WalletButtonBar ({
|
|
||||||
wallet, disable,
|
|
||||||
className, children, onDelete, onCancel, hasCancel = true,
|
|
||||||
createText = 'attach', deleteText = 'detach', editText = 'save'
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<div className={`mt-3 ${className}`}>
|
|
||||||
<div className='d-flex justify-content-between'>
|
|
||||||
{wallet.isConfigured &&
|
|
||||||
<Button onClick={onDelete} variant='grey-medium'>{deleteText}</Button>}
|
|
||||||
{children}
|
|
||||||
<div className='d-flex align-items-center ms-auto'>
|
|
||||||
{hasCancel && <CancelButton onClick={onCancel} />}
|
|
||||||
<SubmitButton variant='primary' disabled={disable}>{wallet.isConfigured ? editText : createText}</SubmitButton>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { getGetServerSideProps } from '@/api/ssrApollo'
|
import { getGetServerSideProps } from '@/api/ssrApollo'
|
||||||
import { Form, ClientInput, ClientCheckbox, PasswordInput } from '@/components/form'
|
import { Form, ClientInput, ClientCheckbox, PasswordInput } from '@/components/form'
|
||||||
import { CenterLayout } from '@/components/layout'
|
import { CenterLayout } from '@/components/layout'
|
||||||
import { WalletButtonBar } from '@/components/wallet-card'
|
|
||||||
import { WalletSecurityBanner } from '@/components/banners'
|
import { WalletSecurityBanner } from '@/components/banners'
|
||||||
import { WalletLogs } from '@/components/wallet-logger'
|
import { WalletLogs } from '@/components/wallet-logger'
|
||||||
import { useToast } from '@/components/toast'
|
import { useToast } from '@/components/toast'
|
||||||
|
@ -10,6 +9,9 @@ import { useWallet, Status } from '@/components/wallet'
|
||||||
import Info from '@/components/info'
|
import Info from '@/components/info'
|
||||||
import Text from '@/components/text'
|
import Text from '@/components/text'
|
||||||
import { AutowithdrawSettings } from '@/components/autowithdraw-shared'
|
import { AutowithdrawSettings } from '@/components/autowithdraw-shared'
|
||||||
|
import dynamic from 'next/dynamic'
|
||||||
|
|
||||||
|
const WalletButtonBar = dynamic(() => import('@/components/wallet-buttonbar.js'), { ssr: false })
|
||||||
|
|
||||||
export const getServerSideProps = getGetServerSideProps({ authRequired: true })
|
export const getServerSideProps = getGetServerSideProps({ authRequired: true })
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue