Skip to content

Commit

Permalink
Merge pull request #85 from Agoric/fix-cookies-error
Browse files Browse the repository at this point in the history
fix: third-party cookies error
  • Loading branch information
turadg authored Jun 6, 2023
2 parents 1d8ce13 + 20de183 commit 3aedaf7
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions wallet/src/bridge-dapp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,36 +153,26 @@ const handleIncomingMessages = () => {
};

const connectDapp = async () => {
if (!('localStorage' in window)) {
throw new Error('No access to localStorage');
}
checkParentWindow();
handleIncomingMessages();
sendMessage({
type: BridgeProtocol.loaded,
});
};

const sendCookiesDisabledError = () => {
const sendAccessError = (err: Error) => {
sendMessage({
type: BridgeProtocol.error,
message: 'Please enable cross-site cookies to use this functionality.',
message: err.message,
});
};

const Bridge = () => {
useEffect(() => {
const tryConnect = async () => {
if ('requestStorageAccess' in document) {
if (await document.hasStorageAccess()) {
return connectDapp();
} else {
sendCookiesDisabledError();
}
} else if ('localStorage' in window) {
return connectDapp();
} else {
sendCookiesDisabledError();
}
};
void tryConnect();
connectDapp().catch(sendAccessError);
}, []);

return <></>;
Expand Down

0 comments on commit 3aedaf7

Please sign in to comment.