-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨feat(llm): trustchain integration to qr code scan
- Loading branch information
1 parent
7781e20
commit 0c8fd3f
Showing
7 changed files
with
132 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useSyncWithQrCode.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { useCallback, useState } from "react"; | ||
import { MemberCredentials } from "@ledgerhq/trustchain/types"; | ||
import { createQRCodeCandidateInstance } from "@ledgerhq/trustchain/qrcode/index"; | ||
import { InvalidDigitsError } from "@ledgerhq/trustchain/errors"; | ||
import { setTrustchain } from "@ledgerhq/trustchain/store"; | ||
import { useDispatch } from "react-redux"; | ||
import { useNavigation } from "@react-navigation/native"; | ||
import { Platform } from "react-native"; | ||
import { Steps } from "../types/Activation"; | ||
import { NavigatorName, ScreenName } from "~/const"; | ||
|
||
export const useSyncWithQrCode = () => { | ||
const [digits, setDigits] = useState<number | null>(null); | ||
const [input, setInput] = useState<string | null>(null); | ||
|
||
const navigation = useNavigation(); | ||
|
||
const [inputCallback, setInputCallback] = useState<((input: string) => void) | null>(null); | ||
const dispatch = useDispatch(); | ||
|
||
const onRequestQRCodeInput = useCallback( | ||
(config: { digits: number }, callback: (input: string) => void) => { | ||
setDigits(config.digits); | ||
setInputCallback(() => callback); | ||
}, | ||
[], | ||
); | ||
|
||
const onSyncFinished = useCallback(() => { | ||
setDigits(null); | ||
setInput(null); | ||
setInputCallback(null); | ||
navigation.navigate(NavigatorName.WalletSync, { | ||
screen: ScreenName.WalletSyncSuccess, | ||
params: { | ||
created: false, | ||
}, | ||
}); | ||
}, [navigation]); | ||
|
||
const handleStart = useCallback( | ||
async ( | ||
url: string, | ||
memberCredentials: MemberCredentials, | ||
setCurrentStep: (step: Steps) => void, | ||
) => { | ||
try { | ||
const trustchain = await createQRCodeCandidateInstance({ | ||
memberCredentials, | ||
scannedUrl: url, | ||
memberName: Platform.OS + " " + Platform.Version, | ||
onRequestQRCodeInput, | ||
}); | ||
dispatch(setTrustchain(trustchain)); | ||
onSyncFinished(); | ||
return true; | ||
} catch (e) { | ||
if (e instanceof InvalidDigitsError) { | ||
setCurrentStep(Steps.SyncError); | ||
return; | ||
} | ||
throw e; | ||
} | ||
}, | ||
[onRequestQRCodeInput, onSyncFinished, dispatch], | ||
); | ||
|
||
const handleSendDigits = useCallback( | ||
(inputCallback: (_: string) => void, input: string) => (inputCallback(input), true), | ||
[], | ||
); | ||
|
||
return { digits, input, handleStart, handleSendDigits, setInput, inputCallback }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 12 additions & 2 deletions
14
apps/ledger-live-mobile/src/newArch/features/WalletSync/screens/Synchronize/PinCodeInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters