fix: token app useSearchParams (#1014)

* fix: token app useSearchParams

* chore: typecast url params to enums for token app
This commit is contained in:
Matthew Russell 2022-08-12 09:58:17 +02:00 committed by GitHub
parent 9e89b98bd0
commit 44c628332d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 7 deletions

View File

@ -5,7 +5,8 @@ export function useSearchParams() {
const location = useLocation();
return React.useMemo(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return new URLSearchParams(location.search) as any;
const searchParams = new URLSearchParams(location.search);
// @ts-ignore searchParams doesnt have symbol.iterator
return Object.fromEntries(searchParams);
}, [location]);
}

View File

@ -30,7 +30,9 @@ export const AssociatePage = ({
const [amount, setAmount] = React.useState<string>('');
const [selectedStakingMethod, setSelectedStakingMethod] =
React.useState<StakingMethod | null>(params.method || null);
React.useState<StakingMethod | null>(
(params.method as StakingMethod) || null
);
// Clear the amount when the staking method changes
React.useEffect(() => {
@ -71,7 +73,7 @@ export const AssociatePage = ({
} else if (!zeroVega && zeroVesting) {
setSelectedStakingMethod(StakingMethod.Wallet);
} else {
setSelectedStakingMethod(params.method);
setSelectedStakingMethod(params.method as StakingMethod);
}
}, [params.method, zeroVega, zeroVesting]);

View File

@ -14,7 +14,9 @@ export const DisassociatePageNoVega = () => {
const params = useSearchParams();
const [amount, setAmount] = React.useState<string>('');
const [selectedStakingMethod, setSelectedStakingMethod] =
React.useState<StakingMethod | null>(params.method || null);
React.useState<StakingMethod | null>(
(params.method as StakingMethod) || null
);
return (
<section className="disassociate-page" data-testid="disassociate-page">

View File

@ -26,7 +26,9 @@ export const DisassociatePage = ({
const params = useSearchParams();
const [amount, setAmount] = React.useState<string>('');
const [selectedStakingMethod, setSelectedStakingMethod] =
React.useState<StakingMethod | null>(params.method || null);
React.useState<StakingMethod | null>(
(params.method as StakingMethod) || null
);
const refreshBalances = useRefreshAssociatedBalances();
// Clear the amount when the staking method changes

View File

@ -91,7 +91,9 @@ export const StakingForm = ({
const { sendTx } = useVegaWallet();
const [formState, setFormState] = React.useState(FormState.Default);
const { t } = useTranslation();
const [action, setAction] = React.useState<StakeAction>(params.action);
const [action, setAction] = React.useState<StakeAction>(
params.action as StakeAction
);
const [amount, setAmount] = React.useState('');
const [removeType, setRemoveType] = React.useState<RemoveType>(
RemoveType.EndOfEpoch