-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
bdcb925
to
f5f9810
Compare
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; | ||
} | ||
}; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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) | ||
); | ||
}; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done here ddcf042
Allure Report
smokeTests: ✅ test report for 767d8e2f
|
There was a problem hiding this 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'; |
There was a problem hiding this comment.
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
👍
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; | ||
} | ||
}; |
There was a problem hiding this comment.
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!
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) | ||
); | ||
}; |
There was a problem hiding this comment.
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)
99fbcb4
to
241ffdf
Compare
import { Wallet } from '@lace/cardano'; | ||
|
||
export const isSharedWallet = (wallet?: Wallet.CardanoWallet): boolean => { | ||
if (wallet?.source.wallet.type !== WalletType.Script) return false; |
There was a problem hiding this comment.
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?
There was a problem hiding this 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done here 3a39e8a
241ffdf
to
f0e811d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job @vetalcore
There was a problem hiding this 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 => { |
There was a problem hiding this comment.
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 😉
e9bb448
to
c36b7ee
Compare
c36b7ee
to
767d8e2
Compare
|
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