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

fix(extension): [lw-10539] shared wallet settings section #1231

Merged
merged 4 commits into from
Jul 12, 2024

Conversation

vetalcore
Copy link
Contributor

@vetalcore vetalcore commented Jun 19, 2024

Checklist


Proposed solution

Explain how does this PR solves the problem stated in JIRA ticket.
You can also enumerate different alternatives considered while approaching this task.

Testing

Describe here, how the new implementation can be tested.
Provide link or briefly describe User Acceptance Criteria/Tests that need to be met

Screenshots

Attach screenshots here if implementation involves some UI changes

@vetalcore vetalcore self-assigned this Jun 19, 2024
@vetalcore vetalcore requested a review from a team as a code owner June 19, 2024 17:23
@vetalcore vetalcore force-pushed the feat/lw-10539-shared-wallet-settings-section branch from bdcb925 to f5f9810 Compare June 19, 2024 17:25
Comment on lines 6 to 15
const isValidSharedWalletScript = (script: Cardano.NativeScript): boolean => {
switch (script.kind) {
case Cardano.NativeScriptKind.RequireAllOf:
case Cardano.NativeScriptKind.RequireAnyOf:
case Cardano.NativeScriptKind.RequireNOf:
return script.scripts.every((nativeScript) => nativeScript.kind === Cardano.NativeScriptKind.RequireSignature);
default:
return false;
}
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this one exists but not exported from cardano-js-sdk*
could create a pr to export it if required?
@szymonmaslowski wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, why not! I guess exporting this utility from sdk will be pretty quick and then we could update the sdk package version in this PR. Thanks for spotting that!

Copy link
Contributor Author

@vetalcore vetalcore Jun 20, 2024

Choose a reason for hiding this comment

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

pr is merged now
what is the release process in the sdk package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cardano js sdk is bumped now

Comment on lines 17 to 28
export const useIsSharedWallet = (inMemoryWallet: Wallet.ObservableWallet): boolean => {
const walletAddresses = useObservable(inMemoryWallet.addresses$);

return walletAddresses?.some(
(addr) =>
isScriptAddress(addr) &&
Cardano.isNativeScript(addr.scripts.payment) &&
isValidSharedWalletScript(addr.scripts.payment) &&
Cardano.isNativeScript(addr.scripts.stake) &&
isValidSharedWalletScript(addr.scripts.stake)
);
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure this is a proper way to check if current wallet is shared, i've created shared wallet but there are no scripts found in the addresses observable
@szymonmaslowski could you please suggest?

Copy link
Contributor

Choose a reason for hiding this comment

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

Try the following way: (I didn't try it, just scratched this code)

  const { walletId } = useObservable(walletManager.activeWalletId$);
  const wallets = useObservable(walletRepository.wallets$);
  const { paymentScript, stakingScript } = wallets.find((w) => w.walletId === walletId)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done here ddcf042

@@ -0,0 +1,28 @@
import { Cardano } from '@cardano-sdk/core';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should it live in the share-wallet package?
also there are isHardwareWallet and isInMemoryWallet exported from the walletInfoSlice, would it be a proper place for isSaredWallet as well?

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 it is a good idea to have it in the walletInfoSlice along with isHardwareWallet and isInMemoryWallet 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done here ddcf042

Copy link

github-actions bot commented Jun 19, 2024

Allure Report

allure-report-publisher generated test report!

smokeTests: ✅ test report for 767d8e2f

passed failed skipped flaky total result
Total 33 0 0 0 33

Copy link
Contributor

@szymonmaslowski szymonmaslowski left a comment

Choose a reason for hiding this comment

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

GJ!

@@ -0,0 +1,28 @@
import { Cardano } from '@cardano-sdk/core';
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 it is a good idea to have it in the walletInfoSlice along with isHardwareWallet and isInMemoryWallet 👍

Comment on lines 6 to 15
const isValidSharedWalletScript = (script: Cardano.NativeScript): boolean => {
switch (script.kind) {
case Cardano.NativeScriptKind.RequireAllOf:
case Cardano.NativeScriptKind.RequireAnyOf:
case Cardano.NativeScriptKind.RequireNOf:
return script.scripts.every((nativeScript) => nativeScript.kind === Cardano.NativeScriptKind.RequireSignature);
default:
return false;
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, why not! I guess exporting this utility from sdk will be pretty quick and then we could update the sdk package version in this PR. Thanks for spotting that!

Comment on lines 17 to 28
export const useIsSharedWallet = (inMemoryWallet: Wallet.ObservableWallet): boolean => {
const walletAddresses = useObservable(inMemoryWallet.addresses$);

return walletAddresses?.some(
(addr) =>
isScriptAddress(addr) &&
Cardano.isNativeScript(addr.scripts.payment) &&
isValidSharedWalletScript(addr.scripts.payment) &&
Cardano.isNativeScript(addr.scripts.stake) &&
isValidSharedWalletScript(addr.scripts.stake)
);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Try the following way: (I didn't try it, just scratched this code)

  const { walletId } = useObservable(walletManager.activeWalletId$);
  const wallets = useObservable(walletRepository.wallets$);
  const { paymentScript, stakingScript } = wallets.find((w) => w.walletId === walletId)

@vetalcore vetalcore force-pushed the feat/lw-10539-shared-wallet-settings-section branch 2 times, most recently from 99fbcb4 to 241ffdf Compare June 20, 2024 16:48
@vetalcore vetalcore requested a review from a team as a code owner June 20, 2024 16:48
import { Wallet } from '@lace/cardano';

export const isSharedWallet = (wallet?: Wallet.CardanoWallet): boolean => {
if (wallet?.source.wallet.type !== WalletType.Script) return false;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

wallet?.source.wallet.type gives inMemory for me
@szymonmaslowski are we actually creating a shared wallet?
if no - how are we going to pass it to the sdet?

Copy link
Contributor

@szymonmaslowski szymonmaslowski left a comment

Choose a reason for hiding this comment

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

Great Job! This one anyway will need to wait for the changes regarding shared-wallet instance creation. Not approving yet just because of changes in the SharedWalletGetStarted.tsx, they should be ready to be removed soon.

@@ -21,12 +21,12 @@ export type SharedWalletGetStartedSharedProps = {
type SharedWalletGetStartedProps = SharedWalletGetStartedSharedProps &
(
| {
createAndImportOptionsDisabled: true;
createAndImportOptionsDisabled: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess you changed it because there was an build error of the shared-wallet package, right? That is my mistake, somehow it sneaked into the main. The error is fixed here, let's revert the changes in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done here 3a39e8a

@vetalcore vetalcore force-pushed the feat/lw-10539-shared-wallet-settings-section branch from 241ffdf to f0e811d Compare July 8, 2024 08:11
Copy link
Contributor

@danielmain danielmain left a comment

Choose a reason for hiding this comment

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

Great job @vetalcore

Copy link
Contributor

@szymonmaslowski szymonmaslowski left a comment

Choose a reason for hiding this comment

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

GJ! I left one suggestion for later. Please also take a look on sonar cube report.

import { WalletType } from '@cardano-sdk/web-extension';
import { Wallet } from '@lace/cardano';

export const isSharedWallet = (wallet?: Wallet.CardanoWallet): boolean => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move it to the shared-wallets space. Let's do it after merging this PR 😉

@vetalcore vetalcore force-pushed the feat/lw-10539-shared-wallet-settings-section branch 2 times, most recently from e9bb448 to c36b7ee Compare July 11, 2024 04:40
@vetalcore vetalcore force-pushed the feat/lw-10539-shared-wallet-settings-section branch from c36b7ee to 767d8e2 Compare July 12, 2024 13:28
Copy link

@vetalcore vetalcore enabled auto-merge (squash) July 12, 2024 13:31
@vetalcore vetalcore merged commit 5796e23 into main Jul 12, 2024
27 of 29 checks passed
@vetalcore vetalcore deleted the feat/lw-10539-shared-wallet-settings-section branch July 12, 2024 13:48
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