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(frontend): add sol wallet worker #4037

Merged
merged 43 commits into from
Jan 7, 2025
Merged

Conversation

loki344
Copy link
Collaborator

@loki344 loki344 commented Dec 19, 2024

Motivation

We integrate SOL with the same worker approach as btc and ic.

Changes

Implement worker and scheduler.

Tests

Unit tests provided, same as for btc worker.

Additionally:

Bildschirmaufnahme.2024-12-19.um.21.53.30.mov

Note

During the development there were some error messages for mainnet (even though we use alchemy now).

image

image

Not reproducable at the moment. Will address this with @StefanBerger-DFINITY to check if the alchemy dashboard shows something.

loki344 and others added 25 commits December 19, 2024 18:02
…alance' into feat(frontend)/add-sol-api-for-balance
…nto feat(frontend)/add-sol-worker

# Conflicts:
#	src/frontend/src/lib/components/loaders/LoaderWallets.svelte
github-actions bot and others added 2 commits December 19, 2024 20:58
…l-worker

# Conflicts:
#	src/frontend/src/sol/api/solana.api.ts
#	src/frontend/src/sol/types/network.ts
@loki344 loki344 marked this pull request as ready for review December 20, 2024 15:55
@loki344 loki344 requested a review from a team as a code owner December 20, 2024 15:55
params: LoadSolWalletParams
): Promise<CertifiedData<bigint | null>> => ({
data: await loadSolLamportsBalance({ network: params.solanaNetwork, address: params.address }),
certified: true
Copy link
Contributor

Choose a reason for hiding this comment

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

The balance you're fetching here (from 3rd party API) is not certified. Same as with Infura and ETH.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hm ok, what does certified mean? By default the SDK uses commitment level 'finalized', so the transaction is definite. https://solana.com/docs/rpc#default-commitment

Copy link
Member

Choose a reason for hiding this comment

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

certified mean

Certified as trustworthy or provided by the Internet Computer through a certified query or update call.

Since it comes from a Web2 platform without any verification or certification of validity, it can only be trusted to some extent; hence, certified: false.

Copy link
Member

@peterpeterparker peterpeterparker left a comment

Choose a reason for hiding this comment

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

I did not review the two ...Wallets.svelte components. Can you please provide those in a separate PR with their tests.

params: LoadSolWalletParams
): Promise<CertifiedData<bigint | null>> => ({
data: await loadSolLamportsBalance({ network: params.solanaNetwork, address: params.address }),
certified: true
Copy link
Member

Choose a reason for hiding this comment

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

certified mean

Certified as trustworthy or provided by the Internet Computer through a certified query or update call.

Since it comes from a Web2 platform without any verification or certification of validity, it can only be trusted to some extent; hence, certified: false.

private loadBalance = async (
params: LoadSolWalletParams
): Promise<CertifiedData<bigint | null>> => ({
data: await loadSolLamportsBalance({ network: params.solanaNetwork, address: params.address }),
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: if you would like to adhere to the coding style, you can destruct the params

const newBalance =
isNullish(this.store.balance) ||
this.store.balance.data !== balance.data ||
(!this.store.balance.certified && balance.certified);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should rather crash an error if certified become true?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, yeah sounds reasonable - The btc-wallet.scheduler.ts has the same logic ATM. I'll adjust it here and add a todo there for another PR

this.postMessageWallet({
wallet: {
balance,
newTransactions: ''
Copy link
Member

Choose a reason for hiding this comment

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

  • It's probably better to fully omit the transactions until those are effectively loaded
  • You do no need to provide the certified flag here as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  1. Let's keep them - They're not hurting atm and will follow shortly. They are already defined in the schema and I don't want to go back and forth.
  2. I don't think so, the certified flag is included in the balance and set to false above.

Copy link
Member

Choose a reason for hiding this comment

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

  1. It's hurting I think because the message are parsed with JSON on the UI side and '' is not a valid value for JSON.parse('')

  2. Coolio

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed txns, note that this will touch an additional file

@loki344
Copy link
Collaborator Author

loki344 commented Jan 6, 2025

I did not review the two ...Wallets.svelte components. Can you please provide those in a separate PR with their tests.

opened #4080

Copy link
Member

@peterpeterparker peterpeterparker left a comment

Choose a reason for hiding this comment

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

LGTM, thx

solanaNetwork: data.solanaNetwork
});

//todo implement loading transactions
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: while we do not have an eslint rule for it, maybe something we can setup (?), we generally use // TODO:. Maybe easier to retrieve if you use the same pattern?

syncWalletError({
tokenId,
error: (data.data as PostMessageDataResponseError).error,
hideToast: isTestnetNetwork || isDevnetNetwork || isLocalNetwork
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a TODO to review this at some point. As far as I remember neither @DenysKarmazynDFINITY nor myself were super happy with this pattern hideToast. Right Denys?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, we wanted to revisit the approach at some point (e.g. by avoiding requests (or launching wallets in this case) that we know in advance are not gonna succeed, rather than making a call + failing silently).

describe('sol-wallet.scheduler', () => {
let spyLoadBalance: MockInstance;

const mockBalance = 100n;
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated to this review, I just asked myself if the Solana balance was effectively a bigint, which it is. Then I had a look at loadSolLamportsBalance, which contains a comment about lamports.

Long story short, if I get it right, what do you think of creating a type type Lamports = bigint? It might be handy to retrieve those kinds of values instead of searching for bigint. Since we often have a type for values, maybe it makes sense in terms of consistency too.

Again, unrelated to this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I can follow up with a PR for this.

@loki344 loki344 enabled auto-merge (squash) January 7, 2025 08:17
@loki344 loki344 merged commit a3eda58 into main Jan 7, 2025
21 checks passed
@loki344 loki344 deleted the feat(frontend)/add-sol-worker branch January 7, 2025 08:19
loki344 added a commit that referenced this pull request Jan 7, 2025
# Note
First review #4037

# Motivation

Integrate the worker from
#4037 in the SolLoaderWallets
component to trigger the loading.

# Changes

Implement SolLoaderWallets.

# Tests

Unit tests provided

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
loki344 added a commit that referenced this pull request Jan 7, 2025
# Motivation

As pointed out in #4037 it
matches the style of the repo to use a separate type for Lamports. The
Solana rpc already offers such types, so it makes sense to use it from
there.

# Changes

Use Typing from solana RPC npm package.

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants