Skip to content

Commit

Permalink
Merge branch 'fix/dapp_rpc' into tmp/20240730
Browse files Browse the repository at this point in the history
  • Loading branch information
richardo2016x committed Aug 2, 2024
2 parents f43b1d6 + 7667b8d commit e6bca67
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
3 changes: 1 addition & 2 deletions apps/mobile/src/components/Approval/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ export const Approval = () => {

const sourceOrigin = origin || params.origin;
if (
activeDappOrigin &&
!shouldAllowApprovePopup(
{
targetOrigin: sourceOrigin,
fromOrigin: sourceOrigin,
currentActiveOrigin: activeDappOrigin,
},
{ allowSecondaryDomainMatch: !!activeTabId },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ RPCMethodsMiddleParameters) =>
icon: iconRef.current || '',
};

// const targetOrigin = req.origin;
// const notAllowedNow = !shouldAllowApprovePopup(
// {
// targetOrigin,
// currentActiveOrigin: getActiveDappOrigin(),
// },
// { allowSecondaryDomainMatch: true },
// );
const notAllowedNow = !checkTabActive();

const rpcMethods = {
Expand Down
27 changes: 15 additions & 12 deletions apps/mobile/src/core/bridges/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,32 @@ export function globalSetActiveDappState(input: {

export function shouldAllowApprovePopup(
{
targetOrigin = '',
fromOrigin: fromDappOrigin = '',
currentActiveOrigin,
}: {
targetOrigin?: string;
fromOrigin?: string;
currentActiveOrigin: string | null;
},
options?: { allowSecondaryDomainMatch?: boolean },
) {
if (targetOrigin === INTERNAL_REQUEST_ORIGIN) return true;
if (!currentActiveOrigin || !targetOrigin) return false;
if (fromDappOrigin === INTERNAL_REQUEST_ORIGIN) return true;

if (!currentActiveOrigin || !fromDappOrigin) return false;

const { allowSecondaryDomainMatch = false } = options || {};

const currentInfo = urlUtils.canoicalizeDappUrl(currentActiveOrigin);
const targetInfo = urlUtils.canoicalizeDappUrl(targetOrigin);
if (currentActiveOrigin) {
const currentInfo = urlUtils.canoicalizeDappUrl(currentActiveOrigin);
const targetInfo = urlUtils.canoicalizeDappUrl(fromDappOrigin);

if (currentInfo.httpOrigin === targetInfo.httpOrigin) return true;
if (currentInfo.httpOrigin === targetInfo.httpOrigin) return true;

if (
allowSecondaryDomainMatch &&
targetInfo.secondaryDomain === currentInfo.secondaryDomain
) {
return true;
if (
allowSecondaryDomainMatch &&
targetInfo.secondaryDomain === currentInfo.secondaryDomain
) {
return true;
}
}

return false;
Expand Down

0 comments on commit e6bca67

Please sign in to comment.