Skip to content

Commit

Permalink
handle public key creation on accounts with a notification (#3270)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlinton authored Mar 10, 2023
1 parent a8c3555 commit bb7b6af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ import {
UI_RPC_METHOD_KEYRING_DERIVE_WALLET,
UI_RPC_METHOD_KEYRING_STORE_READ_ALL_PUBKEYS,
UI_RPC_METHOD_SIGN_MESSAGE_FOR_PUBLIC_KEY,
UI_RPC_METHOD_USER_ACCOUNT_READ,
} from "@coral-xyz/common";
import {
HardwareIcon,
MnemonicIcon,
PushDetail,
} from "@coral-xyz/react-common";
import {
useAuthenticatedUser,
useBackgroundClient,
useKeyringHasMnemonic,
useUser,
Expand All @@ -42,7 +40,6 @@ export function CreateMenu({ blockchain }: { blockchain: Blockchain }) {
const background = useBackgroundClient();
const hasMnemonic = useKeyringHasMnemonic();
const user = useUser();
const authenticatedUser = useAuthenticatedUser();
const [keyringExists, setKeyringExists] = useState(false);
const [newPublicKey, setNewPublicKey] = useState("");
const [openDrawer, setOpenDrawer] = useState(false);
Expand Down Expand Up @@ -132,17 +129,13 @@ export function CreateMenu({ blockchain }: { blockchain: Blockchain }) {
params: [blockchain],
});
}
await background.request({
method: UI_RPC_METHOD_USER_ACCOUNT_READ,
params: [authenticatedUser?.jwt],
});
setNewPublicKey(newPublicKey);
setLoading(false);
} else {
nav.push("create-mnemonic", {
blockchain,
keyringExists
})
keyringExists,
});
}
};

Expand Down
14 changes: 11 additions & 3 deletions packages/recoil/src/context/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
NOTIFICATION_SOLANA_EXPLORER_UPDATED,
NOTIFICATION_SOLANA_SPL_TOKENS_DID_UPDATE,
NOTIFICATION_USER_ACCOUNT_AUTHENTICATED,
NOTIFICATION_USER_ACCOUNT_PUBLIC_KEY_CREATED,
NOTIFICATION_USER_ACCOUNT_PUBLIC_KEY_DELETED,
NOTIFICATION_USER_ACCOUNT_PUBLIC_KEYS_UPDATED,
NOTIFICATION_XNFT_PREFERENCE_UPDATED,
Expand Down Expand Up @@ -96,7 +97,7 @@ export function NotificationsProvider(props: any) {
};
});
};
const setKeyringHasMnemonic = useSetRecoilState(atoms.keyringHasMnemonic)
const setKeyringHasMnemonic = useSetRecoilState(atoms.keyringHasMnemonic);
const setKeyringStoreState = useSetRecoilState(atoms.keyringStoreState);
const setActiveUser = useSetRecoilState(atoms.user);
const setAuthenticatedUser = useSetRecoilState(atoms.authenticatedUser);
Expand Down Expand Up @@ -333,6 +334,9 @@ export function NotificationsProvider(props: any) {
case NOTIFICATION_USER_ACCOUNT_AUTHENTICATED:
handleUserAccountAuthenticated(notif);
break;
case NOTIFICATION_USER_ACCOUNT_PUBLIC_KEY_CREATED:
handleUserAccountPublicKeyCreated(notif);
break;
case NOTIFICATION_USER_ACCOUNT_PUBLIC_KEY_DELETED:
handleUserAccountPublicKeyDeleted(notif);
break;
Expand All @@ -352,8 +356,8 @@ export function NotificationsProvider(props: any) {
};

const handleKeyringSetMnemonic = () => {
setKeyringHasMnemonic(true)
}
setKeyringHasMnemonic(true);
};

const handleKeyringStoreCreated = (notif: Notification) => {
setPreferences(notif.data.preferences);
Expand Down Expand Up @@ -628,6 +632,10 @@ export function NotificationsProvider(props: any) {
});
};

const handleUserAccountPublicKeyCreated = (notif: Notification) => {
setServerPublicKeys((current) => [...current, notif.data]);
};

const handleUserAccountPublicKeyDeleted = (notif: Notification) => {
setServerPublicKeys((current) =>
current.filter(
Expand Down

1 comment on commit bb7b6af

@vercel
Copy link

@vercel vercel bot commented on bb7b6af Mar 10, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.