Skip to content

Commit

Permalink
fix(ui): fix background issue after join multi sign
Browse files Browse the repository at this point in the history
  • Loading branch information
Vu Van Duc authored and Vu Van Duc committed Jul 15, 2024
1 parent cc10297 commit 3837e1f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 36 deletions.
46 changes: 22 additions & 24 deletions src/ui/components/Scanner/Scanner.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
import {
BarcodeScanner,
SupportedFormat,
} from "@capacitor-community/barcode-scanner";
import {
IonCol,
IonGrid,
Expand All @@ -7,46 +10,41 @@ import {
IonSpinner,
isPlatform,
} from "@ionic/react";
import {
BarcodeScanner,
SupportedFormat,
} from "@capacitor-community/barcode-scanner";
import { scanOutline } from "ionicons/icons";
import "./Scanner.scss";
import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
import { Agent } from "../../../core/agent/agent";
import { KeriConnectionType } from "../../../core/agent/agent.types";
import { i18n } from "../../../i18n";
import { useAppDispatch, useAppSelector } from "../../../store/hooks";
import {
getMultiSigGroupCache,
setMultiSigGroupCache,
} from "../../../store/reducers/identifiersCache";
import { MultiSigGroup } from "../../../store/reducers/identifiersCache/identifiersCache.types";
import { setBootUrl, setConnectUrl } from "../../../store/reducers/ssiAgent";
import {
getCurrentOperation,
getCurrentRoute,
getToastMsg,
setCurrentOperation,
setToastMsg,
} from "../../../store/reducers/stateCache";
import { TabsRoutePath } from "../navigation/TabsMenu";
import { setPendingConnection } from "../../../store/reducers/walletConnectionsCache";
import { OperationType, ToastMsgType } from "../../globals/types";
import { Agent } from "../../../core/agent/agent";
import { ScannerProps } from "./Scanner.types";
import { KeriConnectionType } from "../../../core/agent/agent.types";
import {
getMultiSigGroupCache,
setMultiSigGroupCache,
} from "../../../store/reducers/identifiersCache";
import { MultiSigGroup } from "../../../store/reducers/identifiersCache/identifiersCache.types";
import { PageFooter } from "../PageFooter";
import { CreateIdentifier } from "../CreateIdentifier";
import { CustomInput } from "../CustomInput";
import { TabsRoutePath } from "../navigation/TabsMenu";
import { OptionModal } from "../OptionsModal";
import { setPendingConnection } from "../../../store/reducers/walletConnectionsCache";
import { CreateIdentifier } from "../CreateIdentifier";
import { setBootUrl, setConnectUrl } from "../../../store/reducers/ssiAgent";
import { PageFooter } from "../PageFooter";
import "./Scanner.scss";
import { ScannerProps } from "./Scanner.types";

const Scanner = forwardRef(
({ setIsValueCaptured, handleReset }: ScannerProps, ref) => {
({ routePath, setIsValueCaptured, handleReset }: ScannerProps, ref) => {
const componentId = "scanner";
const dispatch = useAppDispatch();
const multiSigGroupCache = useAppSelector(getMultiSigGroupCache);
const currentOperation = useAppSelector(getCurrentOperation);
const currentToastMsg = useAppSelector(getToastMsg);
const currentRoute = useAppSelector(getCurrentRoute);
const [createIdentifierModalIsOpen, setCreateIdentifierModalIsOpen] =
useState(false);
const [pasteModalIsOpen, setPasteModalIsOpen] = useState(false);
Expand Down Expand Up @@ -202,7 +200,7 @@ const Scanner = forwardRef(

useEffect(() => {
if (
((currentRoute?.path === TabsRoutePath.SCAN ||
((routePath === TabsRoutePath.SCAN ||
[
OperationType.SCAN_CONNECTION,
OperationType.SCAN_WALLET_CONNECTION,
Expand All @@ -218,7 +216,7 @@ const Scanner = forwardRef(
} else {
stopScan();
}
}, [currentOperation, currentRoute]);
}, [currentOperation, currentToastMsg, routePath]);

const handlePrimaryButtonAction = () => {
stopScan();
Expand Down
1 change: 1 addition & 0 deletions src/ui/components/Scanner/Scanner.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
interface ScannerProps {
routePath?: string;
setIsValueCaptured?: (value: boolean) => void;
handleReset?: () => void;
}
Expand Down
11 changes: 7 additions & 4 deletions src/ui/pages/Scan/Scan.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { OperationType } from "../../globals/types";
import { Scan } from "./Scan";

const startScan = jest.fn(
(args: any) =>
(args: unknown) =>
new Promise((resolve) => {
setTimeout(() => {
resolve({
Expand All @@ -30,7 +30,7 @@ jest.mock("@capacitor-community/barcode-scanner", () => {
granted: true,
}),
hideBackground: jest.fn(),
startScan: (args: any) => startScan(args),
startScan: (args: unknown) => startScan(args),
stopScan: jest.fn(),
showBackground: jest.fn(),
},
Expand All @@ -50,7 +50,7 @@ jest.mock("../../../core/agent/agent", () => ({
agent: {
connections: {
connectByOobiUrl: () => connectByOobiUrlMock(),
getMultisigLinkedContacts: (args: any) =>
getMultisigLinkedContacts: (args: unknown) =>
getMultisigLinkedContactsMock(args),
},
},
Expand All @@ -61,9 +61,12 @@ const historyPushMock = jest.fn();
jest.mock("react-router-dom", () => ({
...jest.requireActual("react-router-dom"),
useHistory: () => ({
push: (args: any) => {
push: (args: unknown) => {
historyPushMock(args);
},
location: {
pathname: TabsRoutePath.SCAN,
},
}),
}));

Expand Down
19 changes: 11 additions & 8 deletions src/ui/pages/Scan/Scan.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { useIonViewWillEnter } from "@ionic/react";
import { useEffect, useState } from "react";
import { useHistory } from "react-router-dom";
import { useIonViewWillEnter } from "@ionic/react";
import { TabLayout } from "../../components/layout/TabLayout";
import { getNextRoute } from "../../../routes/nextRoute";
import { DataProps } from "../../../routes/nextRoute/nextRoute.types";
import { TabsRoutePath } from "../../../routes/paths";
import { useAppDispatch, useAppSelector } from "../../../store/hooks";
import {
getCurrentOperation,
getStateCache,
getToastMsg,
setCurrentRoute,
} from "../../../store/reducers/stateCache";
import { TabsRoutePath } from "../../../routes/paths";
import { updateReduxState } from "../../../store/utils";
import { TabLayout } from "../../components/layout/TabLayout";
import { Scanner } from "../../components/Scanner";
import { OperationType } from "../../globals/types";
import "./Scan.scss";
import { DataProps } from "../../../routes/nextRoute/nextRoute.types";
import { getNextRoute } from "../../../routes/nextRoute";
import { updateReduxState } from "../../../store/utils";
import { OperationType, ToastMsgType } from "../../globals/types";

const Scan = () => {
const pageId = "scan-tab";
Expand Down Expand Up @@ -65,7 +65,10 @@ const Scan = () => {
pageId={pageId}
header={false}
>
<Scanner setIsValueCaptured={setIsValueCaptured} />
<Scanner
routePath={history.location.pathname}
setIsValueCaptured={setIsValueCaptured}
/>
</TabLayout>
);
};
Expand Down

0 comments on commit 3837e1f

Please sign in to comment.