Skip to content

Commit

Permalink
Prevent unnecessary /display requests each time the modal is opened
Browse files Browse the repository at this point in the history
  • Loading branch information
amitx13 committed Jul 16, 2024
1 parent d18e3ed commit 9996488
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/components/Send/SendForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ interface InnerSendFormProps {
feeConfigValues?: FeeValues
reloadFeeConfigValues: () => void
disabled?: boolean
isDisplayReloadInShowUtxos: boolean
setIsDisplayReloadInShowUtxos: (arg: boolean) => void
}

const InnerSendForm = ({
Expand All @@ -241,6 +243,8 @@ const InnerSendForm = ({
feeConfigValues,
reloadFeeConfigValues,
disabled = false,
isDisplayReloadInShowUtxos,
setIsDisplayReloadInShowUtxos,
}: InnerSendFormProps) => {
const { t } = useTranslation()
const serviceInfo = useServiceInfo()
Expand Down Expand Up @@ -279,6 +283,8 @@ const InnerSendForm = ({
isLoading={isLoading}
disabled={disabled}
variant={showCoinjoinPreconditionViolationAlert ? 'warning' : 'default'}
isDisplayReloadInShowUtxos={isDisplayReloadInShowUtxos}
setIsDisplayReloadInShowUtxos={setIsDisplayReloadInShowUtxos}
/>
{showCoinjoinPreconditionViolationAlert && (
<div className="mb-4">
Expand Down Expand Up @@ -380,6 +386,8 @@ type SendFormProps = Omit<InnerSendFormProps, 'props' | 'className'> & {
formRef?: React.Ref<FormikProps<SendFormValues>>
blurred?: boolean
wallet: CurrentWallet
isDisplayReloadInShowUtxos: boolean
setIsDisplayReloadInShowUtxos: (arg: boolean) => void
}

export const SendForm = ({
Expand Down
20 changes: 17 additions & 3 deletions src/components/Send/ShowUtxos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ interface ShowUtxosProps {
isOpen: boolean
onCancel: () => void
jarIndex: String
isDisplayReloadInShowUtxos: boolean
setIsDisplayReloadInShowUtxos: (arg: boolean) => void
}

interface UtxoRowProps {
Expand Down Expand Up @@ -283,7 +285,15 @@ const Divider = ({ isState, setIsState, className }: DividerProps) => {
)
}

const ShowUtxos = ({ walletInfo, wallet, isOpen, onCancel, jarIndex }: ShowUtxosProps) => {
const ShowUtxos = ({
walletInfo,
wallet,
isOpen,
onCancel,
jarIndex,
isDisplayReloadInShowUtxos,
setIsDisplayReloadInShowUtxos,
}: ShowUtxosProps) => {
const [alert, setAlert] = useState<SimpleAlert | undefined>(undefined)
const [showFrozenUtxos, setShowFrozenUtxos] = useState<boolean>(false)
const [unFrozenUtxos, setUnFrozenUtxos] = useState<UtxoList>([])
Expand Down Expand Up @@ -326,15 +336,19 @@ const ShowUtxos = ({ walletInfo, wallet, isOpen, onCancel, jarIndex }: ShowUtxos
const abortCtrl = new AbortController()
try {
setIsLoading(true)
await reloadCurrentWalletInfo.reloadDisplay({ signal: abortCtrl.signal })
await reloadCurrentWalletInfo.reloadUtxos({ signal: abortCtrl.signal })
if (isDisplayReloadInShowUtxos) {
await reloadCurrentWalletInfo.reloadDisplay({ signal: abortCtrl.signal })
setIsDisplayReloadInShowUtxos(false)
}
loadData(walletInfo)
setIsLoading(false)
} catch (err: any) {
if (!abortCtrl.signal.aborted) {
setAlert({ variant: 'danger', message: err.message, dismissible: true })
}
}
}, [reloadCurrentWalletInfo, loadData, walletInfo])
}, [isDisplayReloadInShowUtxos, setIsDisplayReloadInShowUtxos, reloadCurrentWalletInfo, loadData, walletInfo])

//Effect to Reload walletInfo only once
useEffect(() => {
Expand Down
6 changes: 6 additions & 0 deletions src/components/Send/SourceJarSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export type SourceJarSelectorProps = {
wallet: CurrentWallet
isLoading: boolean
disabled?: boolean
isDisplayReloadInShowUtxos: boolean
setIsDisplayReloadInShowUtxos: (arg: boolean) => void
}

interface ShowUtxosProps {
Expand All @@ -32,6 +34,8 @@ export const SourceJarSelector = ({
variant,
isLoading,
disabled = false,
isDisplayReloadInShowUtxos,
setIsDisplayReloadInShowUtxos,
}: SourceJarSelectorProps) => {
const { t } = useTranslation()

Expand Down Expand Up @@ -71,6 +75,8 @@ export const SourceJarSelector = ({
})
}}
jarIndex={showUtxos.jarIndex}
isDisplayReloadInShowUtxos={isDisplayReloadInShowUtxos}
setIsDisplayReloadInShowUtxos={setIsDisplayReloadInShowUtxos}
/>
)}
{jarBalances.map((it) => {
Expand Down
5 changes: 5 additions & 0 deletions src/components/Send/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export default function Send({ wallet }: SendProps) {
const reloadServiceInfo = useReloadServiceInfo()
const loadConfigValue = useLoadConfigValue()

const [isDisplayReloadInShowUtxos, setIsDisplayReloadInShowUtxos] = useState<boolean>(true)

const isCoinjoinInProgress = useMemo(() => serviceInfo?.coinjoinInProgress === true, [serviceInfo])
const isMakerRunning = useMemo(() => serviceInfo?.makerRunning === true, [serviceInfo])
const isRescanningInProgress = useMemo(() => serviceInfo?.rescanning === true, [serviceInfo])
Expand Down Expand Up @@ -266,6 +268,7 @@ export default function Send({ wallet }: SendProps) {
txid,
}),
})
setIsDisplayReloadInShowUtxos(true)
setWaitForUtxosToBeSpent(inputs.map((it: any) => it.outpoint))
success = true
} else {
Expand Down Expand Up @@ -490,6 +493,8 @@ export default function Send({ wallet }: SendProps) {
loadNewWalletAddress={loadNewWalletAddress}
feeConfigValues={feeConfigValues}
reloadFeeConfigValues={reloadFeeConfigValues}
isDisplayReloadInShowUtxos={isDisplayReloadInShowUtxos}
setIsDisplayReloadInShowUtxos={setIsDisplayReloadInShowUtxos}
/>

{showConfirmAbortModal && (
Expand Down

0 comments on commit 9996488

Please sign in to comment.