@wagmi/connectors 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -14
- package/dist/{chunk-LNIFBRWC.js → chunk-6IU3YKWQ.js} +1 -1
- package/dist/injected.js +1 -1
- package/dist/metaMask.js +1 -1
- package/dist/safe.d.ts +53 -0
- package/dist/safe.js +119 -0
- package/package.json +9 -2
- package/safe/package.json +4 -0
package/README.md
CHANGED
|
@@ -18,25 +18,11 @@ Configure your wagmi client with connectors!
|
|
|
18
18
|
import { configureChains, createClient } from 'wagmi'
|
|
19
19
|
|
|
20
20
|
import { InjectedConnector } from '@wagmi/connectors/injected'
|
|
21
|
-
import { CoinbaseWalletConnector } from '@wagmi/connectors/coinbaseWallet'
|
|
22
|
-
import { WalletConnectConnector } from '@wagmi/connectors/walletConnect'
|
|
23
21
|
|
|
24
22
|
const { chains, provider } = configureChains(...)
|
|
25
23
|
|
|
26
24
|
const client = createClient({
|
|
27
25
|
connectors: [
|
|
28
|
-
new CoinbaseWalletConnector({
|
|
29
|
-
chains,
|
|
30
|
-
options: {
|
|
31
|
-
appName: 'wagmi',
|
|
32
|
-
},
|
|
33
|
-
}),
|
|
34
|
-
new WalletConnectConnector({
|
|
35
|
-
chains,
|
|
36
|
-
options: {
|
|
37
|
-
qrcode: true,
|
|
38
|
-
},
|
|
39
|
-
}),
|
|
40
26
|
new InjectedConnector({ chains }),
|
|
41
27
|
],
|
|
42
28
|
provider,
|
|
@@ -52,6 +38,7 @@ const client = createClient({
|
|
|
52
38
|
- [`LedgerConnector`](/packages/connectors/src/ledger.ts)
|
|
53
39
|
- [`MetaMaskConnector`](/packages/connectors/src/metaMask.ts)
|
|
54
40
|
- [`MockConnector`](/packages/connectors/src/mock.ts)
|
|
41
|
+
- [`SafeConnector`](/packages/connectors/src/safe.ts)
|
|
55
42
|
- [`WalletConnectConnector`](/packages/connectors/src/walletConnect.ts)
|
|
56
43
|
|
|
57
44
|
## Contributing
|
|
@@ -98,7 +98,7 @@ var InjectedConnector = class extends Connector {
|
|
|
98
98
|
__publicField(this, "ready");
|
|
99
99
|
__privateAdd(this, _provider, void 0);
|
|
100
100
|
__privateAdd(this, _switchingChains, void 0);
|
|
101
|
-
__publicField(this, "shimDisconnectKey",
|
|
101
|
+
__publicField(this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
|
|
102
102
|
__publicField(this, "onAccountsChanged", (accounts) => {
|
|
103
103
|
if (accounts.length === 0)
|
|
104
104
|
this.emit("disconnect");
|
package/dist/injected.js
CHANGED
package/dist/metaMask.js
CHANGED
package/dist/safe.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SafeAppProvider } from '@safe-global/safe-apps-provider';
|
|
2
|
+
import { Opts } from '@safe-global/safe-apps-sdk';
|
|
3
|
+
import { Chain } from '@wagmi/core';
|
|
4
|
+
import { providers } from 'ethers';
|
|
5
|
+
import { C as Connector } from './base-84a689bb.js';
|
|
6
|
+
import '@wagmi/core/chains';
|
|
7
|
+
import 'eventemitter3';
|
|
8
|
+
|
|
9
|
+
type SafeConnectorProvider = SafeAppProvider;
|
|
10
|
+
type SafeConnectorOptions = Opts & {
|
|
11
|
+
/**
|
|
12
|
+
* Connector automatically connects when used as Safe App.
|
|
13
|
+
*
|
|
14
|
+
* This flag simulates the disconnect behavior by keeping track of connection status in storage
|
|
15
|
+
* and only autoconnecting when previously connected by user action (e.g. explicitly choosing to connect).
|
|
16
|
+
*
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
shimDisconnect?: boolean;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Connector for [Safe Wallet](https://safe.global)
|
|
23
|
+
*/
|
|
24
|
+
declare class SafeConnector extends Connector<SafeConnectorProvider, SafeConnectorOptions> {
|
|
25
|
+
#private;
|
|
26
|
+
readonly id = "safe";
|
|
27
|
+
readonly name = "Safe";
|
|
28
|
+
ready: boolean;
|
|
29
|
+
protected shimDisconnectKey: string;
|
|
30
|
+
constructor({ chains, options: options_, }: {
|
|
31
|
+
chains?: Chain[];
|
|
32
|
+
options?: SafeConnectorOptions;
|
|
33
|
+
});
|
|
34
|
+
connect(): Promise<{
|
|
35
|
+
account: `0x${string}`;
|
|
36
|
+
provider: SafeAppProvider;
|
|
37
|
+
chain: {
|
|
38
|
+
id: number;
|
|
39
|
+
unsupported: boolean;
|
|
40
|
+
};
|
|
41
|
+
}>;
|
|
42
|
+
disconnect(): Promise<void>;
|
|
43
|
+
getAccount(): Promise<`0x${string}`>;
|
|
44
|
+
getChainId(): Promise<number>;
|
|
45
|
+
getProvider(): Promise<SafeAppProvider>;
|
|
46
|
+
getSigner(): Promise<providers.JsonRpcSigner>;
|
|
47
|
+
isAuthorized(): Promise<boolean>;
|
|
48
|
+
protected onAccountsChanged(_accounts: string[]): void;
|
|
49
|
+
protected onChainChanged(_chainId: string | number): void;
|
|
50
|
+
protected onDisconnect(): void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { SafeConnector, SafeConnectorOptions, SafeConnectorProvider };
|
package/dist/safe.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Connector,
|
|
3
|
+
__privateAdd,
|
|
4
|
+
__privateGet,
|
|
5
|
+
__privateSet,
|
|
6
|
+
__publicField
|
|
7
|
+
} from "./chunk-5NCTPR6C.js";
|
|
8
|
+
|
|
9
|
+
// src/safe.ts
|
|
10
|
+
import { SafeAppProvider } from "@safe-global/safe-apps-provider";
|
|
11
|
+
import { default as SafeAppsSDK } from "@safe-global/safe-apps-sdk";
|
|
12
|
+
import {
|
|
13
|
+
ConnectorNotFoundError,
|
|
14
|
+
getClient,
|
|
15
|
+
normalizeChainId
|
|
16
|
+
} from "@wagmi/core";
|
|
17
|
+
import { providers } from "ethers";
|
|
18
|
+
import { getAddress } from "ethers/lib/utils.js";
|
|
19
|
+
var _provider, _sdk;
|
|
20
|
+
var SafeConnector = class extends Connector {
|
|
21
|
+
constructor({
|
|
22
|
+
chains,
|
|
23
|
+
options: options_
|
|
24
|
+
}) {
|
|
25
|
+
const options = {
|
|
26
|
+
shimDisconnect: false,
|
|
27
|
+
...options_
|
|
28
|
+
};
|
|
29
|
+
super({ chains, options });
|
|
30
|
+
__publicField(this, "id", "safe");
|
|
31
|
+
__publicField(this, "name", "Safe");
|
|
32
|
+
__publicField(this, "ready", !(typeof window === "undefined") && window?.parent !== window);
|
|
33
|
+
__privateAdd(this, _provider, void 0);
|
|
34
|
+
__privateAdd(this, _sdk, void 0);
|
|
35
|
+
__publicField(this, "shimDisconnectKey", `${this.id}.shimDisconnect`);
|
|
36
|
+
__privateSet(this, _sdk, new SafeAppsSDK(options));
|
|
37
|
+
}
|
|
38
|
+
async connect() {
|
|
39
|
+
const provider = await this.getProvider();
|
|
40
|
+
if (!provider)
|
|
41
|
+
throw new ConnectorNotFoundError();
|
|
42
|
+
if (provider.on) {
|
|
43
|
+
provider.on("accountsChanged", this.onAccountsChanged);
|
|
44
|
+
provider.on("chainChanged", this.onChainChanged);
|
|
45
|
+
provider.on("disconnect", this.onDisconnect);
|
|
46
|
+
}
|
|
47
|
+
this.emit("message", { type: "connecting" });
|
|
48
|
+
const account = await this.getAccount();
|
|
49
|
+
const id = await this.getChainId();
|
|
50
|
+
if (this.options.shimDisconnect)
|
|
51
|
+
getClient().storage?.setItem(this.shimDisconnectKey, true);
|
|
52
|
+
return {
|
|
53
|
+
account,
|
|
54
|
+
provider,
|
|
55
|
+
chain: { id, unsupported: this.isChainUnsupported(id) }
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
async disconnect() {
|
|
59
|
+
const provider = await this.getProvider();
|
|
60
|
+
if (!provider?.removeListener)
|
|
61
|
+
return;
|
|
62
|
+
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
63
|
+
provider.removeListener("chainChanged", this.onChainChanged);
|
|
64
|
+
provider.removeListener("disconnect", this.onDisconnect);
|
|
65
|
+
if (this.options.shimDisconnect)
|
|
66
|
+
getClient().storage?.removeItem(this.shimDisconnectKey);
|
|
67
|
+
}
|
|
68
|
+
async getAccount() {
|
|
69
|
+
const provider = await this.getProvider();
|
|
70
|
+
if (!provider)
|
|
71
|
+
throw new ConnectorNotFoundError();
|
|
72
|
+
const accounts = await provider.request({
|
|
73
|
+
method: "eth_accounts"
|
|
74
|
+
});
|
|
75
|
+
return getAddress(accounts[0]);
|
|
76
|
+
}
|
|
77
|
+
async getChainId() {
|
|
78
|
+
const provider = await this.getProvider();
|
|
79
|
+
if (!provider)
|
|
80
|
+
throw new ConnectorNotFoundError();
|
|
81
|
+
return normalizeChainId(provider.chainId);
|
|
82
|
+
}
|
|
83
|
+
async getProvider() {
|
|
84
|
+
if (!__privateGet(this, _provider)) {
|
|
85
|
+
const safe = await __privateGet(this, _sdk).safe.getInfo();
|
|
86
|
+
if (!safe)
|
|
87
|
+
throw new Error("Could not load Safe information");
|
|
88
|
+
__privateSet(this, _provider, new SafeAppProvider(safe, __privateGet(this, _sdk)));
|
|
89
|
+
}
|
|
90
|
+
return __privateGet(this, _provider);
|
|
91
|
+
}
|
|
92
|
+
async getSigner() {
|
|
93
|
+
const provider = await this.getProvider();
|
|
94
|
+
const account = await this.getAccount();
|
|
95
|
+
return new providers.Web3Provider(provider).getSigner(account);
|
|
96
|
+
}
|
|
97
|
+
async isAuthorized() {
|
|
98
|
+
try {
|
|
99
|
+
if (this.options.shimDisconnect && !getClient().storage?.getItem(this.shimDisconnectKey))
|
|
100
|
+
return false;
|
|
101
|
+
const account = await this.getAccount();
|
|
102
|
+
return !!account;
|
|
103
|
+
} catch {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
onAccountsChanged(_accounts) {
|
|
108
|
+
}
|
|
109
|
+
onChainChanged(_chainId) {
|
|
110
|
+
}
|
|
111
|
+
onDisconnect() {
|
|
112
|
+
this.emit("disconnect");
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
_provider = new WeakMap();
|
|
116
|
+
_sdk = new WeakMap();
|
|
117
|
+
export {
|
|
118
|
+
SafeConnector
|
|
119
|
+
};
|
package/package.json
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"name": "@wagmi/connectors",
|
|
3
3
|
"description": "A collection of connectors for wagmi",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "0.2.
|
|
5
|
+
"version": "0.2.4",
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"@wagmi/core": ">=0.9.x",
|
|
8
|
-
"ethers": ">=5.5.1",
|
|
8
|
+
"ethers": ">=5.5.1 <6",
|
|
9
9
|
"typescript": ">=4.9.4"
|
|
10
10
|
},
|
|
11
11
|
"peerDependenciesMeta": {
|
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
"@ledgerhq/connect-kit-loader": "^1.0.1",
|
|
22
22
|
"@walletconnect/ethereum-provider": "^1.8.0",
|
|
23
23
|
"@walletconnect/universal-provider": "^2.3.3",
|
|
24
|
+
"@safe-global/safe-apps-provider": "^0.15.2",
|
|
25
|
+
"@safe-global/safe-apps-sdk": "^7.9.0",
|
|
24
26
|
"@web3modal/standalone": "^2.0.0",
|
|
25
27
|
"abitype": "^0.3.0",
|
|
26
28
|
"eventemitter3": "^4.0.7"
|
|
@@ -57,6 +59,10 @@
|
|
|
57
59
|
"types": "./dist/mock/index.d.ts",
|
|
58
60
|
"default": "./dist/mock/index.js"
|
|
59
61
|
},
|
|
62
|
+
"./safe": {
|
|
63
|
+
"types": "./dist/safe.d.ts",
|
|
64
|
+
"default": "./dist/safe.js"
|
|
65
|
+
},
|
|
60
66
|
"./walletConnect": {
|
|
61
67
|
"types": "./dist/walletConnect.d.ts",
|
|
62
68
|
"default": "./dist/walletConnect.js"
|
|
@@ -69,6 +75,7 @@
|
|
|
69
75
|
"/ledger",
|
|
70
76
|
"/metaMask",
|
|
71
77
|
"/mock",
|
|
78
|
+
"/safe",
|
|
72
79
|
"/walletConnect",
|
|
73
80
|
"/dist"
|
|
74
81
|
],
|