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

magic wallet prompt only shows when using magic #10390

Merged
merged 7 commits into from
Jan 9, 2025

Conversation

Israellund
Copy link
Collaborator

Link to Issue

Closes: #10374

Description of Changes

  • Added logic to only show Magic wallet propmpts when the current address being used is a magic wallet

Test Plan

  • Log in with a user that has a magic wallet and any other wallet connected to that account
  • click into a community while using a Magic address and confirm you see the Open Wallet prompt in the upper right next to the address
  • switch to a non-magic address and confirm you no longer see icon/prompt
  • do the same with the user menu dropdown
  • if not in a community with stake go to one
  • open Buy stake modal with a Magic address
  • confirm you see "Add Funds" text
  • switch to non-magic address and confirm you no longer see the "Add Funds" text/button in the modal

Copy link
Contributor

@masvelio masvelio left a comment

Choose a reason for hiding this comment

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

not fan of this solution of setting local state. This should be either custom hook that returns boolean or we could add it to the userStore as a computed property

eg

// ... existing imports ...
import { WalletId } from '@hicommonwealth/core'; // Add this import

type CommonProps = {
  // ... existing properties ...
  hasMagicWallet: boolean; // Add this computed property
};

export const userStore = createStore<UserStoreProps>()(
  devtools((set, get) => ({
    // ... existing default values ...
    hasMagicWallet: false,

    setData: (data) => {
      if (Object.keys(data).length > 0) {
        set((state) => {
          const newState = { ...state, ...data };
          
          // Compute hasMagicWallet whenever addresses or activeAccount changes
          const currentAddressInfo = newState.addresses?.find(
            (addr) => addr.address === newState.activeAccount?.address,
          );
          const hasMagicWallet = currentAddressInfo?.walletId === WalletId.Magic;

          return {
            ...newState,
            hasMagicWallet,
          };
        });
      }
    },
  })),
);

or selector

export const selectHasMagicWallet = (state: CommonProps) => {
  const currentAddressInfo = state.addresses?.find(
    (addr) => addr.address === state.activeAccount?.address,
  );
  return currentAddressInfo?.walletId === WalletId.Magic;
};

const hasMagic = useUserStore(selectHasMagicWallet);

@Israellund
Copy link
Collaborator Author

This is a much cleaner implementation, thanks for catching that. Just pushed the changes

@Israellund Israellund merged commit b493423 into master Jan 9, 2025
10 checks passed
@Israellund Israellund deleted the israel.10374.showing-magic-wallet-correctly branch January 9, 2025 19:03
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.

Magic wallet prompts should only be shown when magic wallet is being used
3 participants