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

⚡️ [FEAT] : Integrate Trustchain logic in LedgerSync LLD - V1 #7131

Merged
merged 55 commits into from
Jul 9, 2024

Conversation

mcayuelas-ledger
Copy link
Contributor

@mcayuelas-ledger mcayuelas-ledger commented Jun 18, 2024

✅ Checklist

  • npx changeset was attached.
  • Covered by automatic tests.
  • Impact of the changes:
    • Trustchain Store is persistent
    • Integration of Trustchain
      • Add Member
      • Remove Member
      • Destroy Trustchain

📝 Description

Integrates the trustchain lib and store integration on the actual UI of the trustchain flows

  • Arch reworked
  • Hooks dedicated

❓ Context


🧐 Checklist for the PR Reviewers

  • The code aligns with the requirements described in the linked JIRA or GitHub issue.
  • The PR description clearly documents the changes made and explains any technical trade-offs or design decisions.
  • There are no undocumented trade-offs, technical debt, or maintainability issues.
  • The PR has been tested thoroughly, and any potential edge cases have been considered and handled.
  • Any new dependencies have been justified and documented.
  • Performance considerations have been taken into account. (changes have been profiled or benchmarked if necessary)

Copy link

vercel bot commented Jun 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

5 Skipped Deployments
Name Status Preview Comments Updated (UTC)
ledger-live-docs ⬜️ Ignored (Inspect) Visit Preview Jul 9, 2024 9:02am
ledger-live-github-bot ⬜️ Ignored (Inspect) Visit Preview Jul 9, 2024 9:02am
native-ui-storybook ⬜️ Ignored (Inspect) Visit Preview Jul 9, 2024 9:02am
react-ui-storybook ⬜️ Ignored (Inspect) Visit Preview Jul 9, 2024 9:02am
web-tools ⬜️ Ignored (Inspect) Visit Preview Jul 9, 2024 9:02am

@live-github-bot live-github-bot bot added desktop Has changes in LLD mobile Has changes in LLM translations Translation files have been touched labels Jun 18, 2024
Copy link
Contributor

@gre gre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some feedbacks

!hasError && stuffHandledByTrustchain();
}, 3000);
}, [hasError, stuffHandledByTrustchain]);
!hasError && stuffHandledByTrustchain();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improvements i see:

  • we need to handle possible error thrown by stuffHandledByTrustchain and display them to user (using the Generic Error rendering which should tell the user the precise error instead of the UnsecuredError )
  • Q: is there a way, as a user, to interrupt the flow? because we don't handle the unsubscribe of these, and it's possible that runWithDevice never ends which can introduce race conditions

const memberCredentials = useSelector(memberCredentialsSelector);

if (!trustchain || !memberCredentials) {
throw new Error("trustchain or memberCredentials is missing");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dangerous to throw in a hook.
to me, instead we should return a callback that will do nothing if trustchain is falsy, because in that case there will be no more things to delete.

setUrl(url);
},
onDisplayDigits: digits => {
dispatch(setQrCodePinCode(digits)); // Should we assert that it is a string of 3 digits ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually today it's "3" but it could be something else, this is a config in the protocol of QR Code, it could be changed in future and UI just need to adapt to the number of digits ideally: https://github.com/LedgerHQ/ledger-live/blob/develop/libs/trustchain/src/qrcode/index.ts#L155

const trustchain = useSelector(trustchainSelector);
const memberCredentials = useSelector(memberCredentialsSelector);

if (!trustchain || !memberCredentials) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should be able to useLiveAuthenticate with these falsy, it hsouldn't throw from the hook.
there will be error cases where we will need to reset the trustchain (e.g. when member is ejected)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as auth(trustchain: Trustchain, memberCredentials: MemberCredentials): Promise<JWT>;
We can't :/

@@ -34,7 +34,7 @@ export async function createQRCodeHostInstance({
}): Promise<void> {
const ephemeralKey = await crypto.randomKeypair();
const publisher = crypto.to_hex(ephemeralKey.publicKey);
const url = `${getEnv("TRUSTCHAIN_API").replace("http", "ws")}/v1/qr?host=${publisher}`;
const url = `${getEnv("TRUSTCHAIN_API")}/v1/qr?host=${publisher}`.replace(/^http/, "ws");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you undo this change? the develop's version is correct

};

export const getInitialStore = (): TrustchainStore => {
return {
trustchain: null,
memberCredentials: null,
jwt: null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should undo this too, no need to store the jwt anymore

@gre
Copy link
Contributor

gre commented Jul 8, 2024

  • don't forget to update & document the PR description

return addMemberMutation.isError ? (
<ErrorDisplay error={addMemberMutation.error} withExportLogs onRetry={onRetry} />
) : (
<FollowStepsOnDevice modelId={device.modelId as DeviceModelId} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<FollowStepsOnDevice modelId={device.modelId as DeviceModelId} />
<FollowStepsOnDevice modelId={device.modelId} />

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the import

@mcayuelas-ledger mcayuelas-ledger merged commit 08e85c3 into develop Jul 9, 2024
54 of 56 checks passed
@mcayuelas-ledger mcayuelas-ledger deleted the feat/integrate-trustchain-logic branch July 9, 2024 12:10
gre added a commit that referenced this pull request Jul 9, 2024

---------

Co-authored-by: Come Grellard <come.grellard@ledger.fr>
Co-authored-by: Gaëtan Renaudeau <renaudeau.gaetan@gmail.com>
KVNLS pushed a commit that referenced this pull request Jul 19, 2024

---------

Co-authored-by: Come Grellard <come.grellard@ledger.fr>
Co-authored-by: Gaëtan Renaudeau <renaudeau.gaetan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
desktop Has changes in LLD translations Translation files have been touched
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants