Skip to content

Commit

Permalink
Bug: safe app check takes 300ms when not in iframe (#226)
Browse files Browse the repository at this point in the history
* add checks to web3react/web3modal

* add comments

* add changeset

Sent from my iPhone

* fix iframe check

Sent from my iPhone

* build dist

Sent from my iPhone
  • Loading branch information
mmv08 authored Oct 7, 2021
1 parent 23e8abc commit 8137ae6
Show file tree
Hide file tree
Showing 17 changed files with 547 additions and 454 deletions.
9 changes: 9 additions & 0 deletions .changeset/khaki-rats-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@gnosis.pm/safe-apps-web3-react': patch
'@gnosis.pm/safe-apps-web3modal': patch
---

dependency bump
in isSafeApp check, check if running inside an iframe

Sent from my iPhone
13 changes: 13 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"mode": "pre",
"tag": "next",
"initialVersions": {
"@gnosis.pm/cra-template-safe-app": "4.0.0",
"@gnosis.pm/safe-apps-provider": "0.8.0",
"@gnosis.pm/safe-apps-react-sdk": "4.0.4",
"@gnosis.pm/safe-apps-sdk": "4.3.0",
"@gnosis.pm/safe-apps-web3-react": "0.6.3",
"@gnosis.pm/safe-apps-web3modal": "3.0.0"
},
"changesets": []
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
"lerna": "^4.0.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.31.0",
"@typescript-eslint/parser": "^4.31.0",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "27.1.1",
"prettier": "^2.4.0",
"jest": "27.2.4",
"prettier": "^2.4.1",
"ts-jest": "^27.0.5",
"typescript": "^4.4.2"
"typescript": "^4.4.3"
}
}
9 changes: 3 additions & 6 deletions packages/safe-apps-react-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,16 @@
"@gnosis.pm/safe-apps-sdk": "4.3.0"
},
"peerDependencies": {
"@types/node": "^14.0.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.2",
"react": "16.x.x || 17.x.x"
},
"devDependencies": {
"@types/jest": "^27.0.1",
"@types/jest": "^27.0.2",
"@types/react-dom": "^17.0.9",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-flowtype": "^5.9.0",
"eslint-plugin-flowtype": "^6.1.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react": "^7.26.1",
"eslint-plugin-react-hooks": "^4.2.0",
"rimraf": "^3.0.2"
},
Expand Down
10 changes: 3 additions & 7 deletions packages/safe-apps-sdk/dist/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gnosis.pm/safe-apps-sdk",
"version": "4.3.0-next.2",
"version": "4.3.0",
"description": "SDK developed to integrate third-party apps with Safe-Multisig app.",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
Expand All @@ -15,21 +15,17 @@
],
"scripts": {
"test": "jest",
"format-dist": "sed -i 's/\"files\":/\"_files\":/' dist/package.json",
"format-dist": "sed -i '' 's/\"files\":/\"_files\":/' dist/package.json",
"build": "yarn rimraf dist && tsc && yarn format-dist",
"lint": "tslint -p tsconfig.json"
},
"author": "Gnosis (https://gnosis.io)",
"license": "MIT",
"dependencies": {
"@changesets/cli": "^2.16.0",
"ethers": "^5.4.5"
"ethers": "^5.4.7"
},
"devDependencies": {
"@types/jest": "^27.0.1",
"@types/node": "^16.9.0",
"@typescript-eslint/eslint-plugin": "^4.31.0",
"@typescript-eslint/parser": "^4.31.0",
"rimraf": "^3.0.2"
},
"repository": {
Expand Down
6 changes: 1 addition & 5 deletions packages/safe-apps-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@
"license": "MIT",
"dependencies": {
"@changesets/cli": "^2.16.0",
"ethers": "^5.4.5"
"ethers": "^5.4.7"
},
"devDependencies": {
"@types/jest": "^27.0.1",
"@types/node": "^16.9.0",
"@typescript-eslint/eslint-plugin": "^4.31.0",
"@typescript-eslint/parser": "^4.31.0",
"rimraf": "^3.0.2"
},
"repository": {
Expand Down
4 changes: 4 additions & 0 deletions packages/safe-apps-web3-react/dist/connector.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/safe-apps-web3-react/dist/connector.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/safe-apps-web3-react/dist/useSafeAppConnection.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/safe-apps-web3-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"react": "16.x.x || 17.x.x"
},
"devDependencies": {
"@types/jest": "^27.0.1",
"@types/node": "^16.9.0",
"@types/jest": "^27.0.2",
"@types/node": "^16.10.3",
"@web3-react/core": "6.1.9",
"react": "17.0.2",
"rimraf": "^3.0.2"
Expand Down
5 changes: 5 additions & 0 deletions packages/safe-apps-web3-react/src/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class SafeAppConnector extends AbstractConnector {
}

public async isSafeApp(): Promise<boolean> {
// check if we're in an iframe
if (window?.parent === window) {
return false;
}

const safe = await Promise.race([
this.getSafeInfo(),
new Promise<undefined>((resolve) => setTimeout(resolve, 300)),
Expand Down
2 changes: 1 addition & 1 deletion packages/safe-apps-web3-react/src/useSafeAppConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function useSafeAppConnection(connector: SafeAppConnector): boolean {
setTried(true);
}
});
}, [activate]); // intentionally only running on mount (make sure it's only mounted once :))
}, [activate, connector]); // intentionally only running on mount (make sure it's only mounted once :))

// if the connection worked, wait until we get confirmation of that to flip the flag
React.useEffect(() => {
Expand Down
4 changes: 4 additions & 0 deletions packages/safe-apps-web3modal/dist/modal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/safe-apps-web3modal/dist/modal.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions packages/safe-apps-web3modal/src/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export class SafeAppWeb3Modal extends Web3Modal {
};

public async isSafeApp(): Promise<boolean> {
// check if we're in an iframe
if (window?.parent === window) {
return false;
}

const safe = await this.getConnectedSafe();

return !!safe;
Expand Down
Loading

0 comments on commit 8137ae6

Please sign in to comment.