Skip to content

Commit

Permalink
refactor(compose_txn): remove need for useState and useEffect to calc…
Browse files Browse the repository at this point in the history
…ulate URL for back button
  • Loading branch information
No-Cash-7970 committed Oct 11, 2024
1 parent f613d36 commit 3947067
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/app/[lang]/txn/compose/components/ComposeForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client';

import { useEffect, useState } from 'react';
import Link from 'next/link';
import dynamic from 'next/dynamic';
import { useSearchParams } from 'next/navigation';
Expand Down Expand Up @@ -179,17 +178,6 @@ export default function ComposeForm({ lng }: Props) {
const txnType = useAtomValue(txnDataAtoms.txnType);
const currentURLParams = useSearchParams();
const preset = currentURLParams.get(Preset.ParamName);
const [urlParams, setUrlParams] = useState(currentURLParams.toString());

useEffect(() => {
// Remove URL parameter for preset if it is specified.
// This is for the link (back button) to the Presets page
const newURLParams = new URLSearchParams(urlParams);
newURLParams.delete(Preset.ParamName);
setUrlParams(newURLParams.toString());
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentURLParams]);

return (
<form
id='compose-txn-form'
Expand Down Expand Up @@ -307,9 +295,16 @@ export default function ComposeForm({ lng }: Props) {
<ComposeSubmitButton lng={lng} />
</div>
<div className='sm:order-first'>
<Link type='button' className='btn w-full'
href={`/${lng}/txn${urlParams ? '?'+urlParams : ''}`}
>
<Link type='button' className='btn w-full' href={{
pathname: `/${lng}/txn`,
query: (() => {
// Remove URL parameter for preset if it is specified.
// This is for the link (back button) to the Presets page
const newURLParams = new URLSearchParams(currentURLParams.toString());
newURLParams.delete(Preset.ParamName);
return newURLParams.toString();
})()
}}>
<Icons.IconArrowLeft aria-hidden className='rtl:hidden' />
<Icons.IconArrowRight aria-hidden className='hidden rtl:inline' />
{t('txn_presets_btn')}
Expand Down

0 comments on commit 3947067

Please sign in to comment.