-
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 5412cb1
Showing
10 changed files
with
154 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"live-mobile": patch | ||
--- | ||
|
||
Trustchain integration on LLM scan qr code. We can now join a trustchain scanning a qr code |
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
12 changes: 12 additions & 0 deletions
12
apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useInstanceName.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,12 @@ | ||
import { getEnv } from "@ledgerhq/live-env"; | ||
import { Platform } from "react-native"; | ||
|
||
const platformMap: Record<string, string | undefined> = { | ||
ios: "iOS", | ||
android: "Android", | ||
}; | ||
|
||
export function useInstanceName(): string { | ||
const hash = getEnv("USER_ID").slice(0, 5); | ||
return `${platformMap[Platform.OS] ?? Platform.OS} ${Platform.Version} ${hash ? " " + hash : ""}`; | ||
} |
75 changes: 75 additions & 0 deletions
75
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,75 @@ | ||
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 { Steps } from "../types/Activation"; | ||
import { NavigatorName, ScreenName } from "~/const"; | ||
import { useInstanceName } from "./useInstanceName"; | ||
|
||
export const useSyncWithQrCode = () => { | ||
const [digits, setDigits] = useState<number | null>(null); | ||
const [input, setInput] = useState<string | null>(null); | ||
const instanceName = useInstanceName(); | ||
|
||
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: instanceName, | ||
onRequestQRCodeInput, | ||
}); | ||
dispatch(setTrustchain(trustchain)); | ||
onSyncFinished(); | ||
return true; | ||
} catch (e) { | ||
if (e instanceof InvalidDigitsError) { | ||
setCurrentStep(Steps.SyncError); | ||
return; | ||
} | ||
throw e; | ||
} | ||
}, | ||
[instanceName, 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
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