Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix token field reset and set selected token in SendTokens step #129

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/components/Transaction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { TransactionBox } from "./styled";
type TxData = {
to: string;
amount: string;
token: string;
token: string | undefined;
chain: ChainExtended;
};

Expand All @@ -60,6 +60,19 @@ export const Transaction = ({ pspToken }: { pspToken?: string }) => {
const isLastStep = currentStep === steps.length - 1;
const Component = steps[currentStep].Component;

const resetTxData = () => {
setTxData((prevTxData) => {
const updatedData = {
...prevTxData,
to: "",
amount: "0 SBY",
token: "",
} as TxData;
return updatedData;
});
setErrors([]);
};

const setField = useCallback((field: string, value: unknown) => {
setTxData((prevTxData) => {
const updatedData = {
Expand Down Expand Up @@ -210,7 +223,10 @@ export const Transaction = ({ pspToken }: { pspToken?: string }) => {
>
{currentStep > 0 && (
<Button
onClick={() => setCurrentStep(currentStep - 1)}
onClick={() => {
resetTxData();
setCurrentStep(currentStep - 1);
}}
variant="outlined"
disabled={isLoading}
>
Expand Down
10 changes: 6 additions & 4 deletions src/components/Transaction/steps/SendTokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { balanceToFixed } from "@/utils/formatString";
import InputWithMax from "../inputs/InputWithMax";

type Props = {
setField: (field: string, value: string | number) => void;
setField: (field: string, value: string | number | undefined) => void;
setErrors: (errors: string[]) => void;
errors: string[];
amount: string;
Expand Down Expand Up @@ -171,6 +171,7 @@ export const SendTokens = (props: Props) => {
setInputValue("0");
isInputDirty.current.amount = false;
if (selectedAsset) {
setField("token", selectedAsset.address);
setTokenSelected({
symbol: selectedAsset.name,
isNative: false,
Expand All @@ -181,13 +182,14 @@ export const SendTokens = (props: Props) => {
>
<MenuItem
value="native"
onClick={() =>
onClick={() => {
setField("token", undefined);
setTokenSelected({
symbol: tokenSymbol,
isNative: true,
address: "native",
})
}
});
}}
>
<Box display="flex" alignItems="center" gap={1}>
<Avatar src={chain?.logo.src} alt={chain?.logo.alt} />
Expand Down
Loading