Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

166: Added Gnosis Safe app support #222

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@ module.exports = {
typescript: {
enableTypeChecking: true,
},
devServer: {
headers: {
"Access-Control-Allow-Origin": "https://app.safe.global",
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization",
"Access-Control-Allow-Credentials": "true"
},
}
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@web3-react/abstract-connector": "^6.0.7",
"@web3-react/coinbase-wallet": "^8.2.3",
"@web3-react/core": "^8.2.3",
"@web3-react/gnosis-safe": "^8.2.4",
"@web3-react/injected-connector": "^6.0.7",
"@web3-react/metamask": "^8.2.4",
"@web3-react/store": "^8.2.3",
Expand Down
6 changes: 4 additions & 2 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"short_name": "AirSwap",
"name": "AirSwap",
"short_name": "Marketplace",
"name": "Airswap NFT Marketplace",
"description": "An NFT marketplace by Airswap",
"iconPath": "logo512.png",
"icons": [
{
"src": "favicon.ico",
Expand Down
7 changes: 3 additions & 4 deletions src/web3-connectors/coinbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
import { CoinbaseWallet } from '@web3-react/coinbase-wallet';
import { initializeConnector } from '@web3-react/core';

import { rpcUrls } from '../constants/rpc';
import { SupportedChain } from '../constants/supportedChains';
import { getRpcUrl } from '../helpers/ethers';
import { Connection, ConnectionType } from './connections';
import { onConnectionError } from './helpers';

const chainId = process.env.REACT_APP_CHAIN_ID || '1';
const rpcUrl = chainId ? rpcUrls[Number(chainId) as SupportedChain] : process.env.REACT_APP_RPC_URL_1;
const chainId = +(process.env.REACT_APP_CHAIN_ID || '1');
const rpcUrl = getRpcUrl(chainId);

export function buildCoinbaseWalletConnector() {
// @ts-ignore
Expand Down
7 changes: 7 additions & 0 deletions src/web3-connectors/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Web3ReactHooks } from '@web3-react/core';
import { Connector } from '@web3-react/types';

import { buildCoinbaseWalletConnector } from './coinbase';
import { buildGnosisSafeConnector } from './gnosis';
import { buildInjectedConnector } from './injected';
import { buildWalletConnectConnector } from './walletConnect';

Expand All @@ -15,12 +16,14 @@ export enum ConnectionType {
coinbase = 'coinbase',
injected = 'injected',
walletConnect = 'walletConnect',
gnosis = 'gnosis',
}

export const prioritizedConnectors: { [key in ConnectionType]: Connection } = {
[ConnectionType.coinbase]: buildCoinbaseWalletConnector(),
[ConnectionType.injected]: buildInjectedConnector(),
[ConnectionType.walletConnect]: buildWalletConnectConnector(),
[ConnectionType.gnosis]: buildGnosisSafeConnector(),
};

export function getConnection(c: Connector | ConnectionType): Connection {
Expand All @@ -41,5 +44,9 @@ export function getConnection(c: Connector | ConnectionType): Connection {
return prioritizedConnectors[ConnectionType.walletConnect];
}

if (c === ConnectionType.gnosis) {
return prioritizedConnectors[ConnectionType.gnosis];
}

return prioritizedConnectors[ConnectionType.injected];
}
22 changes: 22 additions & 0 deletions src/web3-connectors/gnosis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { initializeConnector } from '@web3-react/core';
import { GnosisSafe } from '@web3-react/gnosis-safe';

import { Connection, ConnectionType } from './connections';

export function buildGnosisSafeConnector() {
const [gnosisSafe, gnosisSafeHooks] = initializeConnector<GnosisSafe>(
(actions) => new GnosisSafe({
actions,
options: {
debug: true,
},
}),
);
const gnosisSafeConnection: Connection = {
connector: gnosisSafe,
hooks: gnosisSafeHooks,
type: ConnectionType.gnosis,
};

return gnosisSafeConnection;
}
11 changes: 11 additions & 0 deletions src/widgets/WalletConnector/WalletConnector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useAppDispatch, useAppSelector } from '../../redux/hooks';
import { getLastProviderFromLocalStorage } from '../../redux/stores/web3/web3Api';
import { setConnectionType, setIsInitialized, setUserHasClosedConnectModal } from '../../redux/stores/web3/web3Slice';
import { ConnectionType, getConnection } from '../../web3-connectors/connections';
import { buildGnosisSafeConnector } from '../../web3-connectors/gnosis';
import { tryActivateConnector } from '../../web3-connectors/helpers';
import walletProviders, { WalletProvider } from '../../web3-connectors/walletProviders';
import WalletProviderList from './subcomponents/WalletProviderList/WalletProviderList';
Expand Down Expand Up @@ -80,6 +81,16 @@ const WalletConnector: FC<WalletConnectorProps> = ({ onCloseButtonClick, classNa
activateWalletEagerly(getConnection(type).connector, type);
}, []);

useEffect(() => {
const gnosisSafe = buildGnosisSafeConnector();

try {
activateWalletEagerly(gnosisSafe.connector, gnosisSafe.type);
} catch (e) {
console.error(e);
}
}, []);

useEffect(() => {
setIsActiveState(isActive);

Expand Down
97 changes: 95 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
resolved "https://registry.yarnpkg.com/@adobe/css-tools/-/css-tools-4.3.2.tgz#a6abc715fb6884851fca9dad37fc34739a04fd11"
integrity sha512-DA5a1C0gD/pLOvhv33YMrbf2FK3oUzwNl9oOJqE4XVjuEtt6XIakRcsd7eLiOSPkp1kTRQGICTA8cKra/vFbjw==

"@adraffy/ens-normalize@1.10.0":
version "1.10.0"
resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.10.0.tgz#d2a39395c587e092d77cbbc80acf956a54f38bf7"
integrity sha512-nA9XHtlAkYfJxY7bce8DcN7eKxWWCWkU+1GR9d+U6MbNpfwQp8TI7vqOsBsMcHoT4mBu2kypKoSKnghEzOOq5Q==

"@airswap/batch-call@4.2.1":
version "4.2.1"
resolved "https://registry.yarnpkg.com/@airswap/batch-call/-/batch-call-4.2.1.tgz#1fad437d1f159679071d6f6276a42691ebc3d5da"
Expand Down Expand Up @@ -2178,6 +2183,13 @@
dependencies:
"@noble/hashes" "1.3.1"

"@noble/curves@1.2.0", "@noble/curves@~1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.2.0.tgz#92d7e12e4e49b23105a2555c6984d41733d65c35"
integrity sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==
dependencies:
"@noble/hashes" "1.3.2"

"@noble/curves@^1.2.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.3.0.tgz#01be46da4fd195822dab821e72f71bf4aeec635e"
Expand All @@ -2190,7 +2202,12 @@
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.1.tgz#8831ef002114670c603c458ab8b11328406953a9"
integrity sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==

"@noble/hashes@1.3.3", "@noble/hashes@^1.3.1", "@noble/hashes@~1.3.0", "@noble/hashes@~1.3.1":
"@noble/hashes@1.3.2":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39"
integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==

"@noble/hashes@1.3.3", "@noble/hashes@^1.3.1", "@noble/hashes@~1.3.0", "@noble/hashes@~1.3.1", "@noble/hashes@~1.3.2":
version "1.3.3"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.3.tgz#39908da56a4adc270147bb07968bf3b16cfe1699"
integrity sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==
Expand Down Expand Up @@ -2396,7 +2413,36 @@
estree-walker "^1.0.1"
picomatch "^2.2.2"

"@scure/base@~1.1.0":
"@safe-global/safe-apps-provider@^0.17.1":
version "0.17.1"
resolved "https://registry.yarnpkg.com/@safe-global/safe-apps-provider/-/safe-apps-provider-0.17.1.tgz#72df2a66be5343940ed505efe594ed3b0f2f7015"
integrity sha512-lYfRqrbbK1aKU1/UGkYWc/X7PgySYcumXKc5FB2uuwAs2Ghj8uETuW5BrwPqyjBknRxutFbTv+gth/JzjxAhdQ==
dependencies:
"@safe-global/safe-apps-sdk" "8.0.0"
events "^3.3.0"

"@safe-global/safe-apps-sdk@8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@safe-global/safe-apps-sdk/-/safe-apps-sdk-8.0.0.tgz#9bdfe0e0d85e1b2d279bb840f40c4b930aaf8bc1"
integrity sha512-gYw0ki/EAuV1oSyMxpqandHjnthZjYYy+YWpTAzf8BqfXM3ItcZLpjxfg+3+mXW8HIO+3jw6T9iiqEXsqHaMMw==
dependencies:
"@safe-global/safe-gateway-typescript-sdk" "^3.5.3"
viem "^1.0.0"

"@safe-global/safe-apps-sdk@^8.0.0":
version "8.1.0"
resolved "https://registry.yarnpkg.com/@safe-global/safe-apps-sdk/-/safe-apps-sdk-8.1.0.tgz#d1d0c69cd2bf4eef8a79c5d677d16971926aa64a"
integrity sha512-XJbEPuaVc7b9n23MqlF6c+ToYIS3f7P2Sel8f3cSBQ9WORE4xrSuvhMpK9fDSFqJ7by/brc+rmJR/5HViRr0/w==
dependencies:
"@safe-global/safe-gateway-typescript-sdk" "^3.5.3"
viem "^1.0.0"

"@safe-global/safe-gateway-typescript-sdk@^3.5.3":
version "3.18.0"
resolved "https://registry.yarnpkg.com/@safe-global/safe-gateway-typescript-sdk/-/safe-gateway-typescript-sdk-3.18.0.tgz#59377cd7929e3a87d3c1dcc2092faa0142a1a17d"
integrity sha512-Do+zK2uyeaXHyQsZ0JVjAQYnOox8QoBiezdBVdDGlztQTWW8QbL0J7Us2XaXEXJAYwvrt58wvIn3iLOs0lmkwQ==

"@scure/base@~1.1.0", "@scure/base@~1.1.2":
version "1.1.5"
resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.5.tgz#1d85d17269fe97694b9c592552dd9e5e33552157"
integrity sha512-Brj9FiG2W1MRQSTB212YVPRrcbjkv48FoZi/u4l/zds/ieRrqsh7aUf6CLwkAq61oKXr/ZlTzlY66gLIj3TFTQ==
Expand All @@ -2410,6 +2456,15 @@
"@noble/hashes" "~1.3.1"
"@scure/base" "~1.1.0"

"@scure/bip32@1.3.2":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@scure/bip32/-/bip32-1.3.2.tgz#90e78c027d5e30f0b22c1f8d50ff12f3fb7559f8"
integrity sha512-N1ZhksgwD3OBlwTv3R6KFEcPojl/W4ElJOeCZdi+vuI5QmTFwLq3OFf2zd2ROpKvxFdgZ6hUpb0dx9bVNEwYCA==
dependencies:
"@noble/curves" "~1.2.0"
"@noble/hashes" "~1.3.2"
"@scure/base" "~1.1.2"

"@scure/bip39@1.2.1":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@scure/bip39/-/bip39-1.2.1.tgz#5cee8978656b272a917b7871c981e0541ad6ac2a"
Expand Down Expand Up @@ -3650,6 +3705,15 @@
optionalDependencies:
"@ethersproject/providers" "^5"

"@web3-react/gnosis-safe@^8.2.4":
version "8.2.4"
resolved "https://registry.yarnpkg.com/@web3-react/gnosis-safe/-/gnosis-safe-8.2.4.tgz#1f595a64bd26506a2e537b8a6734b5bf243d4e36"
integrity sha512-4M0CFludHJXtLsKJlKBIeMZcdTO60e6psYhYm2GLy76do9K9JJvBE8U4YVFBHLpk7sWpySsrCuYcaVZyzZ/xtA==
dependencies:
"@safe-global/safe-apps-provider" "^0.17.1"
"@safe-global/safe-apps-sdk" "^8.0.0"
"@web3-react/types" "^8.2.3"

"@web3-react/injected-connector@^6.0.7":
version "6.0.7"
resolved "https://registry.yarnpkg.com/@web3-react/injected-connector/-/injected-connector-6.0.7.tgz#1e0be23f51fa07fe6547fe986768a46b74c3a426"
Expand Down Expand Up @@ -3871,6 +3935,11 @@ abab@^2.0.3, abab@^2.0.5:
resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.6.tgz#41b80f2c871d19686216b82309231cfd3cb3d291"
integrity sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA==

abitype@0.9.8:
version "0.9.8"
resolved "https://registry.yarnpkg.com/abitype/-/abitype-0.9.8.tgz#1f120b6b717459deafd213dfbf3a3dd1bf10ae8c"
integrity sha512-puLifILdm+8sjyss4S+fsUN09obiT1g2YW6CtcQF+QDzxR0euzgEB29MZujC6zMk2a6SVmtttq1fc6+YFA7WYQ==

accepts@~1.3.4, accepts@~1.3.5, accepts@~1.3.8:
version "1.3.8"
resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.8.tgz#0bf0be125b67014adcb0b0921e62db7bffe16b2e"
Expand Down Expand Up @@ -8863,6 +8932,11 @@ isomorphic-ws@^4.0.1:
resolved "https://registry.yarnpkg.com/isomorphic-ws/-/isomorphic-ws-4.0.1.tgz#55fd4cd6c5e6491e76dc125938dd863f5cd4f2dc"
integrity sha512-BhBvN2MBpWTaSHdWRb/bwdZJ1WaehQ2L1KngkCkfLUGF0mAWAT1sQUQacEmQ0jXkFw/czDXPNQSL5u2/Krsz1w==

isows@1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/isows/-/isows-1.0.3.tgz#93c1cf0575daf56e7120bab5c8c448b0809d0d74"
integrity sha512-2cKei4vlmg2cxEjm3wVSqn8pcoRF/LX/wpifuuNquFO4SQmPwarClT+SUCA2lt+l581tTeZIPIZuIDo2jWN1fg==

istanbul-lib-coverage@^3.0.0, istanbul-lib-coverage@^3.2.0:
version "3.2.2"
resolved "https://registry.yarnpkg.com/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.2.tgz#2d166c4b0644d43a39f04bf6c2edd1e585f31756"
Expand Down Expand Up @@ -14674,6 +14748,20 @@ vendors@^1.0.0:
resolved "https://registry.yarnpkg.com/vendors/-/vendors-1.0.4.tgz#e2b800a53e7a29b93506c3cf41100d16c4c4ad8e"
integrity sha512-/juG65kTL4Cy2su4P8HjtkTxk6VmJDiOPBufWniqQ6wknac6jNiXS9vU+hO3wgusiyqWlzTbVHi0dyJqRONg3w==

viem@^1.0.0:
version "1.21.4"
resolved "https://registry.yarnpkg.com/viem/-/viem-1.21.4.tgz#883760e9222540a5a7e0339809202b45fe6a842d"
integrity sha512-BNVYdSaUjeS2zKQgPs+49e5JKocfo60Ib2yiXOWBT6LuVxY1I/6fFX3waEtpXvL1Xn4qu+BVitVtMh9lyThyhQ==
dependencies:
"@adraffy/ens-normalize" "1.10.0"
"@noble/curves" "1.2.0"
"@noble/hashes" "1.3.2"
"@scure/bip32" "1.3.2"
"@scure/bip39" "1.2.1"
abitype "0.9.8"
isows "1.0.3"
ws "8.13.0"

vm-browserify@^1.0.1:
version "1.1.2"
resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-1.1.2.tgz#78641c488b8e6ca91a75f511e7a3b32a86e5dda0"
Expand Down Expand Up @@ -15196,6 +15284,11 @@ ws@7.4.6:
resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.6.tgz#5654ca8ecdeee47c33a9a4bf6d28e2be2980377c"
integrity sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==

ws@8.13.0:
version "8.13.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0"
integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==

ws@^6.2.1:
version "6.2.2"
resolved "https://registry.yarnpkg.com/ws/-/ws-6.2.2.tgz#dd5cdbd57a9979916097652d78f1cc5faea0c32e"
Expand Down