diff --git a/package.json b/package.json index 1b60cd88e5..9b46fb4321 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "private": true, "devDependencies": { "@ethersproject/experimental": "^5.2.0", + "@gnosis.pm/safe-apps-web3-react": "^0.6.0", "@graphql-codegen/cli": "1.21.5", "@graphql-codegen/typescript": "1.22.3", "@graphql-codegen/typescript-operations": "^1.18.2", diff --git a/public/images/256x256_App_Icon_Pink.svg b/public/images/256x256_App_Icon_Pink.svg new file mode 100644 index 0000000000..8c8286838d --- /dev/null +++ b/public/images/256x256_App_Icon_Pink.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/public/manifest.json b/public/manifest.json index 5489752e0d..a267390d2f 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -2,6 +2,7 @@ "background_color": "#fff", "display": "standalone", "homepage_url": "https://app.uniswap.org", + "providedBy": { "name": "Uniswap", "url": "https://uniswap.org" }, "icons": [ { "src": "./images/192x192_App_Icon.png", @@ -18,6 +19,8 @@ ], "orientation": "portrait", "name": "Uniswap", + "description": "Swap or provide liquidity on the Uniswap Protocol", + "iconPath": "./images/256x256_App_Icon_Pink.svg", "short_name": "Uniswap", "start_url": ".", "theme_color": "#ff007a" diff --git a/src/connectors/index.ts b/src/connectors/index.ts index 6f862cd036..74705c7d13 100644 --- a/src/connectors/index.ts +++ b/src/connectors/index.ts @@ -1,4 +1,5 @@ import { Web3Provider } from '@ethersproject/providers' +import { SafeAppConnector } from '@gnosis.pm/safe-apps-web3-react' import { InjectedConnector } from '@web3-react/injected-connector' import { PortisConnector } from '@web3-react/portis-connector' import { WalletConnectConnector } from '@web3-react/walletconnect-connector' @@ -44,6 +45,8 @@ export const injected = new InjectedConnector({ supportedChainIds: ALL_SUPPORTED_CHAIN_IDS, }) +export const gnosisSafe = new SafeAppConnector() + export const walletconnect = new WalletConnectConnector({ supportedChainIds: ALL_SUPPORTED_CHAIN_IDS, rpc: NETWORK_URLS, diff --git a/src/hooks/web3.ts b/src/hooks/web3.ts index 1ad13c8cfa..ba9c45c215 100644 --- a/src/hooks/web3.ts +++ b/src/hooks/web3.ts @@ -1,9 +1,10 @@ import { Web3Provider } from '@ethersproject/providers' +import { useSafeAppConnection } from '@gnosis.pm/safe-apps-web3-react' import { useWeb3React as useWeb3ReactCore } from '@web3-react/core' import { Web3ReactContextInterface } from '@web3-react/core/dist/types' import { useEffect, useState } from 'react' import { isMobile } from 'react-device-detect' -import { injected } from '../connectors' +import { gnosisSafe, injected } from '../connectors' import { NetworkContextName } from '../constants/misc' export function useActiveWeb3React(): Web3ReactContextInterface { @@ -16,30 +17,34 @@ export function useEagerConnect() { const { activate, active } = useWeb3ReactCore() // specifically using useWeb3ReactCore because of what this hook does const [tried, setTried] = useState(false) + const triedToConnectToSafe = useSafeAppConnection(gnosisSafe) + useEffect(() => { - injected.isAuthorized().then((isAuthorized) => { - if (isAuthorized) { - activate(injected, undefined, true).catch(() => { - setTried(true) - }) - } else { - if (isMobile && window.ethereum) { + if (triedToConnectToSafe && !active) { + injected.isAuthorized().then((isAuthorized) => { + if (isAuthorized) { activate(injected, undefined, true).catch(() => { setTried(true) }) } else { - setTried(true) + if (isMobile && window.ethereum) { + activate(injected, undefined, true).catch(() => { + setTried(true) + }) + } else { + setTried(true) + } } - } - }) - }, [activate]) // intentionally only running on mount (make sure it's only mounted once :)) + }) + } + }, [activate, active, triedToConnectToSafe]) // 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 useEffect(() => { - if (active) { + if (active && triedToConnectToSafe) { setTried(true) } - }, [active]) + }, [active, triedToConnectToSafe]) return tried } diff --git a/yarn.lock b/yarn.lock index 1e8d212429..2bed394e0f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1862,6 +1862,28 @@ "@ethersproject/properties" "^5.2.0" "@ethersproject/strings" "^5.2.0" +"@gnosis.pm/safe-apps-provider@0.6.0": + version "0.6.0" + resolved "https://registry.yarnpkg.com/@gnosis.pm/safe-apps-provider/-/safe-apps-provider-0.6.0.tgz#07cc78df57ca4d0fa9c24c4040ea6322ac759a23" + integrity sha512-xtB3lbEqJocYUhg6CVXJVBIah6hZCfRSUXw1e7VHe7QkZlwNIhuom4bF5ZIQlmNPzXF/XjC/Bl4//1R88rjs+w== + dependencies: + "@gnosis.pm/safe-apps-sdk" "4.0.0" + events "^3.3.0" + +"@gnosis.pm/safe-apps-sdk@4.0.0": + version "4.0.0" + resolved "https://registry.yarnpkg.com/@gnosis.pm/safe-apps-sdk/-/safe-apps-sdk-4.0.0.tgz#2fa53ba3e6a88c606787cc7c4d7836181e256024" + integrity sha512-D+jFrRnhzmDbuA3D6tLH615WXdOtBEsv3qCAbBfXFDUiDbXFPVZbMdgnWUowA8he6PBbBYTn7LbSJaq/K5T3ZA== + +"@gnosis.pm/safe-apps-web3-react@^0.6.0": + version "0.6.0" + resolved "https://registry.yarnpkg.com/@gnosis.pm/safe-apps-web3-react/-/safe-apps-web3-react-0.6.0.tgz#ac77f569ee7bafe3bb6b4492e94905177a0f2e5d" + integrity sha512-mJCShSqxO5Z1q9O7qGzVApYhrgAeE5X4+JxoFVlU+wNk+UKHnP8segU6ujyFAFq9xOVvShszlSl6p2qAAvP6xA== + dependencies: + "@gnosis.pm/safe-apps-provider" "0.6.0" + "@gnosis.pm/safe-apps-sdk" "4.0.0" + "@web3-react/abstract-connector" "6.0.7" + "@graphql-codegen/cli@1.21.5": version "1.21.5" resolved "https://registry.yarnpkg.com/@graphql-codegen/cli/-/cli-1.21.5.tgz#b9041553747cfb2dee7c3473a2e2461ec3e7ada5" @@ -4271,7 +4293,7 @@ "@walletconnect/utils" "^1.5.0-rc.5" web3-provider-engine "16.0.1" -"@web3-react/abstract-connector@^6.0.7": +"@web3-react/abstract-connector@6.0.7", "@web3-react/abstract-connector@^6.0.7": version "6.0.7" resolved "https://registry.npmjs.org/@web3-react/abstract-connector/-/abstract-connector-6.0.7.tgz" integrity sha512-RhQasA4Ox8CxUC0OENc1AJJm8UTybu/oOCM61Zjg6y0iF7Z0sqv1Ai1VdhC33hrQpA8qSBgoXN9PaP8jKmtdqg== @@ -9394,7 +9416,7 @@ eventemitter3@^3.1.0: resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-3.1.2.tgz#2d3d48f9c346698fce83a85d7d664e98535df6e7" integrity sha512-tvtQIeLVHjDkJYnzf2dgVMxfuSGJeM/7UCG17TT4EumTfNtF+0nebF/4zWOIkCreAbtNqhGEboB6BWrwqNaw4Q== -events@^3.0.0: +events@^3.0.0, events@^3.3.0: version "3.3.0" resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400" integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==