@dynamic-labs/wagmi-connector 0.16.0-RC.8 → 0.16.0
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/CHANGELOG.md +108 -0
- package/LICENSE +21 -0
- package/_virtual/_tslib.es.js +26 -0
- package/package.json +11 -9
- package/src/index.es.js +1 -0
- package/src/lib/Connector.d.ts +1 -1
- package/src/lib/Connector.es.js +126 -0
- package/src/lib/DynamicWagmiConnector.d.ts +1 -1
- package/src/lib/DynamicWagmiConnector.es.js +42 -0
- package/src/lib/SyncDynamicWagmi.es.js +32 -0
- package/src/lib/getWagmiChainsFromDynamicChains.d.ts +1 -1
- package/src/lib/getWagmiChainsFromDynamicChains.es.js +9 -0
- package/src/lib/getWagmiProvidersFromDynamicChains.d.ts +1 -1
- package/src/lib/getWagmiProvidersFromDynamicChains.es.js +22 -0
- package/src/lib/mappers/chain.d.ts +1 -1
- package/src/lib/mappers/chain.es.js +47 -0
- package/index.cjs +0 -2110
- package/index.js +0 -2083
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,112 @@
|
|
|
1
1
|
|
|
2
|
+
## [0.16.0](https://github.com/dynamic-labs/DynamicAuth/compare/v0.15.0...v0.16.0) (2023-04-14)
|
|
3
|
+
It is has been a bit over a month since our last stable launch, and here comes V0.16.0!
|
|
4
|
+
We have some cool features for you and one breaking change that you should be aware of (We try our best to minimize these, but we gotta keep on cleaning legacy stuff).
|
|
5
|
+
|
|
6
|
+
### ⚠ BREAKING CHANGES
|
|
7
|
+
* With the introduction of email login and social verification we moved to `verifiedCredentials` instead of `blockchainAccounts`. `blockChainAccounts` was removed from the [user's object](https://dash.readme.com/project/dynamic/v2.5/docs/userprofile) and from the [JWT payload](https://docs.dynamic.xyz/docs/user-payload).
|
|
8
|
+
|
|
9
|
+
### Feature Highlights
|
|
10
|
+
* Support for social verifications (Github, Google, Facebook, Twitter, and Discord).
|
|
11
|
+
* Support for Cosmos and Keplr Wallet.
|
|
12
|
+
* Support for hCaptcha.
|
|
13
|
+
* Magic Wallet improvements: OTP authentication, network switching, send transaction/sign-message page, and performance improvements.
|
|
14
|
+
* Improvements to the Starknet integration.
|
|
15
|
+
* Expose updateSelf method that handles all the side effects that involve in updating a profile.
|
|
16
|
+
* User profile has a new boolean (newUser) to indicate (suprise) whether it is a new user that was just created.
|
|
17
|
+
* [defaultNumberOfWalletsToShow](https://docs.dynamic.xyz/docs/sort-and-filter-wallets#sortwallets) is a param that can control how many wallets to show on the wallet listing when a walletFilter is applied.
|
|
18
|
+
* Two new callbacks were added: [onConnectSuccess](https://docs.dynamic.xyz/docs/onconnectsuccess), and [onUserProfileUpdate](https://docs.dynamic.xyz/docs/onuserprofileupdate)
|
|
19
|
+
* Added support for multiple additional wallets (such as: Uniswap and Dawn).
|
|
20
|
+
|
|
21
|
+
And tons of other small improvements and bug fixes.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## [0.16.0-RC.14](https://github.com/dynamic-labs/DynamicAuth/compare/v0.16.0-RC.13...v0.16.0-RC.14) (2023-04-12)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Features
|
|
28
|
+
|
|
29
|
+
* **DYN-2073:** use emailOnly property to decide whether to show wallet list or not ([#1855](https://github.com/dynamic-labs/DynamicAuth/issues/1855)) ([9f98713](https://github.com/dynamic-labs/DynamicAuth/commit/9f9871343811e9bcaa4bad3b01407fcab7401630))
|
|
30
|
+
* **Keplr:** sign message with walletconnect and authorize ([699d438](https://github.com/dynamic-labs/DynamicAuth/commit/699d438e9c14ce5f562cbebe9c4895530bbeb0cf))
|
|
31
|
+
* **Keplr:** support network switch ([28c98b3](https://github.com/dynamic-labs/DynamicAuth/commit/28c98b31010bfd74b0a1a767165311a7ca1bca8a))
|
|
32
|
+
* **KeplrWalletCnnect:** fetch balance ([d42aad9](https://github.com/dynamic-labs/DynamicAuth/commit/d42aad9c848ced5eff782da23fd0ed50a1727f74))
|
|
33
|
+
* **KeplrWalletCnnect:** fetch balance ([bd0f854](https://github.com/dynamic-labs/DynamicAuth/commit/bd0f854ea95425dabdc918f87a3e85c1f30e42c9))
|
|
34
|
+
* **magic:** handle network switching ([c9636ef](https://github.com/dynamic-labs/DynamicAuth/commit/c9636ef61bc72970fde4182f7c2e5c05fcccf1bf))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### Bug Fixes
|
|
38
|
+
|
|
39
|
+
* **Keplr:** authorize with persited network ([82e9e94](https://github.com/dynamic-labs/DynamicAuth/commit/82e9e945039d9ee39a64193d6b14f993b9f980f0))
|
|
40
|
+
* remove extend WalletConnect from keplrWalletConnect ([9ae62be](https://github.com/dynamic-labs/DynamicAuth/commit/9ae62be5d47e1b17a986bd4c84aba3a8d3583743))
|
|
41
|
+
|
|
42
|
+
## [0.16.0-RC.13](https://github.com/dynamic-labs/DynamicAuth/compare/v0.16.0-RC.12...v0.16.0-RC.13) (2023-04-11)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
### Features
|
|
46
|
+
|
|
47
|
+
* add cosmos to the new wallet chain options ([ba93570](https://github.com/dynamic-labs/DynamicAuth/commit/ba93570a1b51d79135e985273c9a8ac7b417b690))
|
|
48
|
+
* add glow and starknet to shouldManuallyReconnectOnRefresh ([a971787](https://github.com/dynamic-labs/DynamicAuth/commit/a97178750aa2ff6b2e6c8b84bf8587f43faaf243))
|
|
49
|
+
* starknet update signature for getWeb3Provider and updated isInstalled ([94e84ac](https://github.com/dynamic-labs/DynamicAuth/commit/94e84ac04e4ceb20a6b13ede4ff22230b0bb08f5))
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
### Bug Fixes
|
|
53
|
+
|
|
54
|
+
* **connect-only:** manually reconnect connector based on shouldManuallyReconnectOnRefresh ([e81ec1c](https://github.com/dynamic-labs/DynamicAuth/commit/e81ec1ccee9fe4361dc4e12e358a4d199b750478))
|
|
55
|
+
* remove useFetchPublicAddress ([5cb5659](https://github.com/dynamic-labs/DynamicAuth/commit/5cb5659aa8b3d03589f6e6a065a087ff54afe863))
|
|
56
|
+
* starknet properly teardown the listeners ([1212251](https://github.com/dynamic-labs/DynamicAuth/commit/121225146ed2d7e6dff58f00681f7876ba20bd6e))
|
|
57
|
+
* update kycEnabled value when projectSettings change ([#1836](https://github.com/dynamic-labs/DynamicAuth/issues/1836)) ([56f4312](https://github.com/dynamic-labs/DynamicAuth/commit/56f431218648d34275d4ea0ab5e5dbfadd8ed7b3))
|
|
58
|
+
|
|
59
|
+
## [0.16.0-RC.12](https://github.com/dynamic-labs/DynamicAuth/compare/v0.16.0-RC.11...v0.16.0-RC.12) (2023-04-06)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
### Bug Fixes
|
|
63
|
+
|
|
64
|
+
* only display ouath providers in social accounts profile section ([1d11297](https://github.com/dynamic-labs/DynamicAuth/commit/1d11297bad425867068b5f6bf90473aa014166cc))
|
|
65
|
+
* social auth updates ([#1819](https://github.com/dynamic-labs/DynamicAuth/issues/1819)) ([ade0aba](https://github.com/dynamic-labs/DynamicAuth/commit/ade0aba4f02be756456c947cd634f605517942e3))
|
|
66
|
+
* update multi-wallet list ([#1814](https://github.com/dynamic-labs/DynamicAuth/issues/1814)) ([3d97ebd](https://github.com/dynamic-labs/DynamicAuth/commit/3d97ebd50b8458bece4ad1946d0c397232e28a48))
|
|
67
|
+
* update wallets list so the tiles look stacked again ([#1813](https://github.com/dynamic-labs/DynamicAuth/issues/1813)) ([299f46b](https://github.com/dynamic-labs/DynamicAuth/commit/299f46b89e3dcddc0886509502ede9c2e72d58f3))
|
|
68
|
+
|
|
69
|
+
## [0.16.0-RC.11](https://github.com/dynamic-labs/DynamicAuth/compare/v0.16.0-RC.10...v0.16.0-RC.11) (2023-04-05)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
### Features
|
|
73
|
+
|
|
74
|
+
* **DYN-1710:** Add Manual Switch Network view ([3526a5d](https://github.com/dynamic-labs/DynamicAuth/commit/3526a5d869e2b8b8b404959f02360b1e7db75f97))
|
|
75
|
+
* **DYN-2030:** replace hardcoded network properties to api response ([5af6d5e](https://github.com/dynamic-labs/DynamicAuth/commit/5af6d5efba280bfffa196075cf7b9d9ca702296e))
|
|
76
|
+
* enable social profiles integration ([#1729](https://github.com/dynamic-labs/DynamicAuth/issues/1729)) ([d33ae28](https://github.com/dynamic-labs/DynamicAuth/commit/d33ae2859cbe097de58b9caa654c3c5aec13f9fa))
|
|
77
|
+
* export the type of DynamicContextProp ([452fe1b](https://github.com/dynamic-labs/DynamicAuth/commit/452fe1b066b293659357b9722c5383025639f197))
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
### Bug Fixes
|
|
81
|
+
|
|
82
|
+
* add missing dependecy to the useEffect ([cacbcc4](https://github.com/dynamic-labs/DynamicAuth/commit/cacbcc4bc2ec813bb8b4298eefee8e893377434d))
|
|
83
|
+
* **Button:** loading state ([af7a9b0](https://github.com/dynamic-labs/DynamicAuth/commit/af7a9b0e937bbc859f551ba7fc5463e61d7fc1c4))
|
|
84
|
+
* make Wallets the 1st option in widget switcher ([#1794](https://github.com/dynamic-labs/DynamicAuth/issues/1794)) ([7156b37](https://github.com/dynamic-labs/DynamicAuth/commit/7156b37ee4a94fd4e74e3889d93a5613f39fdf0f))
|
|
85
|
+
* only show ens name/avatar if there's any for the selected wallet ([#1779](https://github.com/dynamic-labs/DynamicAuth/issues/1779)) ([1a6cf6b](https://github.com/dynamic-labs/DynamicAuth/commit/1a6cf6b583f55c67d190bc962451073839b3ecfb))
|
|
86
|
+
* update 'wallet not connected' pop up (update copy, add logout button and spinner) ([#1780](https://github.com/dynamic-labs/DynamicAuth/issues/1780)) ([0b2701f](https://github.com/dynamic-labs/DynamicAuth/commit/0b2701fbfb07b23c646f77608a21eff183fdc0ab))
|
|
87
|
+
* update 'wallet not connected' prompt ([#1793](https://github.com/dynamic-labs/DynamicAuth/issues/1793)) ([a9b9064](https://github.com/dynamic-labs/DynamicAuth/commit/a9b906438255d46ac1a4e3b0dd8efaa3c5d92e1c))
|
|
88
|
+
|
|
89
|
+
## [0.16.0-RC.10](https://github.com/dynamic-labs/DynamicAuth/compare/v0.16.0-RC.9...v0.16.0-RC.10) (2023-03-31)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
### Features
|
|
93
|
+
|
|
94
|
+
* **DYN-2093:** add new_user boolean flag to UserProfile ([4150047](https://github.com/dynamic-labs/DynamicAuth/commit/4150047ae5598ec949f1e1e4484d08be6e84eba5))
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
### Bug Fixes
|
|
98
|
+
|
|
99
|
+
* **magic-otp:** reload the page on click edit email ([11af506](https://github.com/dynamic-labs/DynamicAuth/commit/11af506b50462b8e121d5b95b1b1ec53ed09992b))
|
|
100
|
+
* **multi-wallet:** display OTP view when reconnecting wallet ([4a3ad0a](https://github.com/dynamic-labs/DynamicAuth/commit/4a3ad0a96912edba8451697252de47ea5858fe31))
|
|
101
|
+
* **Portal:** allow for custom element id ([d27589d](https://github.com/dynamic-labs/DynamicAuth/commit/d27589de093e0933c69041a90fe18bb35325cfc8))
|
|
102
|
+
|
|
103
|
+
## [0.16.0-RC.9](https://github.com/dynamic-labs/DynamicAuth/compare/v0.16.0-RC.8...v0.16.0-RC.9) (2023-03-30)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
### Features
|
|
107
|
+
|
|
108
|
+
* **DYN-2030:** cosmos/keplr integration ([#1756](https://github.com/dynamic-labs/DynamicAuth/issues/1756)) ([1521dac](https://github.com/dynamic-labs/DynamicAuth/commit/1521dac370b6dbecfedf7eaa367c436ce4d9286d))
|
|
109
|
+
|
|
2
110
|
## [0.16.0-RC.8](https://github.com/dynamic-labs/DynamicAuth/compare/v0.16.0-RC.7...v0.16.0-RC.8) (2023-03-29)
|
|
3
111
|
|
|
4
112
|
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Dynamic Labs, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
|
|
16
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
17
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { __awaiter };
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/wagmi-connector",
|
|
3
|
-
"version": "0.16.0
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "0.16.0",
|
|
5
4
|
"repository": {
|
|
6
5
|
"type": "git",
|
|
7
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -12,18 +11,21 @@
|
|
|
12
11
|
"react": "^17.0.2 || ^18.0.0",
|
|
13
12
|
"ethers": "^5.7.2",
|
|
14
13
|
"wagmi": "~0.10.3",
|
|
15
|
-
"@dynamic-labs/sdk-react": "0.16.0
|
|
14
|
+
"@dynamic-labs/sdk-react": "0.16.0",
|
|
15
|
+
"@dynamic-labs/sdk-react-core": "0.16.0"
|
|
16
16
|
},
|
|
17
17
|
"license": "MIT",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
18
|
+
"main": "./src/index.es.js",
|
|
19
|
+
"module": "./src/index.es.js",
|
|
20
20
|
"types": "./src/index.d.ts",
|
|
21
|
+
"type": "module",
|
|
21
22
|
"exports": {
|
|
22
23
|
".": {
|
|
23
24
|
"types": "./src/index.d.ts",
|
|
24
|
-
"import": "./index.js",
|
|
25
|
-
"require": "./index.
|
|
26
|
-
}
|
|
25
|
+
"import": "./src/index.es.js",
|
|
26
|
+
"require": "./src/index.es.js"
|
|
27
|
+
},
|
|
28
|
+
"./package.json": "./package.json"
|
|
27
29
|
},
|
|
28
30
|
"dependencies": {}
|
|
29
|
-
}
|
|
31
|
+
}
|
package/src/index.es.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DynamicWagmiConnector } from './lib/DynamicWagmiConnector.es.js';
|
package/src/lib/Connector.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
2
|
import { Address, Connector as BaseWagmiConnector, ConnectorData, Chain } from 'wagmi';
|
|
3
|
-
import { WalletConnector } from '@dynamic-labs/sdk-react';
|
|
3
|
+
import { WalletConnector } from '@dynamic-labs/sdk-react-core';
|
|
4
4
|
export declare class Connector extends BaseWagmiConnector<ethers.providers.Web3Provider, undefined, ethers.providers.JsonRpcSigner> {
|
|
5
5
|
handleLogOut: () => void;
|
|
6
6
|
walletConnector: WalletConnector;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { __awaiter } from '../../_virtual/_tslib.es.js';
|
|
2
|
+
import { Connector as Connector$1 } from 'wagmi';
|
|
3
|
+
import { getAddress, hexValue } from 'ethers/lib/utils.js';
|
|
4
|
+
|
|
5
|
+
class Connector extends Connector$1 {
|
|
6
|
+
constructor({ chains, handleLogOut, walletConnector, }) {
|
|
7
|
+
super({ chains, options: undefined });
|
|
8
|
+
// wagmi properties
|
|
9
|
+
this.id = 'dynamic';
|
|
10
|
+
this.name = 'Dynamic';
|
|
11
|
+
// also a wagmi prop, but is only used for auto-connect
|
|
12
|
+
// which we have implemented ourselves, so this value
|
|
13
|
+
// doesn't matter
|
|
14
|
+
this.ready = false;
|
|
15
|
+
this.onAccountsChanged = (accounts) => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
this.emit('change', {
|
|
17
|
+
account: getAddress(accounts[0]),
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
this.onChainChanged = (chain) => __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
this.emit('change', {
|
|
22
|
+
chain: { id: Number(chain), unsupported: false },
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
this.onDisconnect = () => __awaiter(this, void 0, void 0, function* () { });
|
|
26
|
+
this.handleLogOut = handleLogOut;
|
|
27
|
+
this.walletConnector = walletConnector;
|
|
28
|
+
this.setupEventListeners();
|
|
29
|
+
}
|
|
30
|
+
setupEventListeners() {
|
|
31
|
+
this.walletConnector.setupEventListeners({
|
|
32
|
+
onAccountChange: this.onAccountsChanged,
|
|
33
|
+
onChainChange: this.onChainChanged,
|
|
34
|
+
onDisconnect: this.onDisconnect,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
connect(config) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
if (!this.walletConnector) {
|
|
40
|
+
throw new Error('WalletConnector is not defined');
|
|
41
|
+
}
|
|
42
|
+
const account = yield this.getAccount();
|
|
43
|
+
this.setupEventListeners();
|
|
44
|
+
this.emit('message', { type: 'connecting' });
|
|
45
|
+
const web3Provider = yield this.getProvider();
|
|
46
|
+
const { provider } = web3Provider;
|
|
47
|
+
return {
|
|
48
|
+
account,
|
|
49
|
+
chain: { id: yield this.getChainId(), unsupported: false },
|
|
50
|
+
provider,
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
disconnect() {
|
|
55
|
+
var _a, _b, _c;
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const web3Provider = yield this.getProvider();
|
|
58
|
+
const { provider } = web3Provider;
|
|
59
|
+
provider.removeListener('accountsChanged', this.onAccountsChanged);
|
|
60
|
+
provider.removeListener('chainChanged', this.onChainChanged);
|
|
61
|
+
provider.removeListener('disconnect', this.onDisconnect);
|
|
62
|
+
yield ((_b = (_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.endSession) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
63
|
+
(_c = this.handleLogOut) === null || _c === void 0 ? void 0 : _c.call(this);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
getAccount() {
|
|
67
|
+
var _a;
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const address = yield ((_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.fetchPublicAddress());
|
|
70
|
+
if (!address) {
|
|
71
|
+
throw new Error('Not connected');
|
|
72
|
+
}
|
|
73
|
+
return getAddress(address);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
getChainId() {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
if (!this.walletConnector) {
|
|
79
|
+
throw new Error('WalletConnector is not defined');
|
|
80
|
+
}
|
|
81
|
+
const network = yield this.walletConnector.getNetwork();
|
|
82
|
+
if (!network) {
|
|
83
|
+
throw new Error('Network is not defined');
|
|
84
|
+
}
|
|
85
|
+
return network;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
getProvider(config) {
|
|
89
|
+
var _a;
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
return (_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.getWeb3Provider();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
getSigner(config) {
|
|
95
|
+
var _a;
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
return (_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.getSigner();
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
isAuthorized() {
|
|
101
|
+
var _a, _b;
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const accounts = (_b = (yield ((_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.getConnectedAccounts()))) !== null && _b !== void 0 ? _b : [];
|
|
104
|
+
return accounts.length > 0;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
switchChain(chainId) {
|
|
108
|
+
var _a, _b;
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
yield ((_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.switchNetwork({ networkChainId: chainId }));
|
|
111
|
+
const id = hexValue(chainId);
|
|
112
|
+
return ((_b = this.chains.find((x) => x.id === chainId)) !== null && _b !== void 0 ? _b : {
|
|
113
|
+
id: chainId,
|
|
114
|
+
name: `Chain ${id}`,
|
|
115
|
+
nativeCurrency: { decimals: 18, name: 'Ether', symbol: 'ETH' },
|
|
116
|
+
network: `${id}`,
|
|
117
|
+
rpcUrls: { default: { http: [''] } },
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
watchAsset(asset) {
|
|
122
|
+
throw new Error('Method not implemented.');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export { Connector };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { configureChains, mainnet, createClient, WagmiConfig } from 'wagmi';
|
|
3
|
+
import { publicProvider } from 'wagmi/providers/public';
|
|
4
|
+
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
|
|
5
|
+
import { Connector } from './Connector.es.js';
|
|
6
|
+
import { SyncDynamicWagmi } from './SyncDynamicWagmi.es.js';
|
|
7
|
+
import { getWagmiChainsFromDynamicChains } from './getWagmiChainsFromDynamicChains.es.js';
|
|
8
|
+
import { getWagmiProvidersFromDynamicChains } from './getWagmiProvidersFromDynamicChains.es.js';
|
|
9
|
+
|
|
10
|
+
const { provider } = configureChains([mainnet], [publicProvider()]);
|
|
11
|
+
const client = createClient({
|
|
12
|
+
provider,
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* we create a "default" (static chain and provider) client to use in the WagmiConfig
|
|
16
|
+
* until we've loaded the dynamic chains and providers, at which point we update the client
|
|
17
|
+
*/
|
|
18
|
+
let connector = undefined;
|
|
19
|
+
const DynamicWagmiConnector = ({ evmNetworks: customerSuppliedEvmNetworks, children, }) => {
|
|
20
|
+
var _a;
|
|
21
|
+
const { networkConfigurations, walletConnector, handleLogOut } = useDynamicContext();
|
|
22
|
+
const evmNetworks = (_a = customerSuppliedEvmNetworks !== null && customerSuppliedEvmNetworks !== void 0 ? customerSuppliedEvmNetworks : networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.evm) !== null && _a !== void 0 ? _a : [];
|
|
23
|
+
const mappedChains = getWagmiChainsFromDynamicChains(evmNetworks);
|
|
24
|
+
const mappedProviders = getWagmiProvidersFromDynamicChains(evmNetworks);
|
|
25
|
+
const { chains, provider } = configureChains(mappedChains, mappedProviders);
|
|
26
|
+
if (!connector && walletConnector) {
|
|
27
|
+
connector = new Connector({
|
|
28
|
+
chains,
|
|
29
|
+
handleLogOut,
|
|
30
|
+
walletConnector,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
else if (connector && !walletConnector) {
|
|
34
|
+
connector = undefined;
|
|
35
|
+
}
|
|
36
|
+
client.config = Object.assign(Object.assign({}, client.config), { connectors: connector ? [connector] : [], provider });
|
|
37
|
+
// use React.createElement to prevent bunding react/jsx-runtime,
|
|
38
|
+
// which is not compatible when bundling apps using React 17
|
|
39
|
+
return React.createElement(WagmiConfig, { client: client }, React.createElement(SyncDynamicWagmi, { connector }, children));
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export { DynamicWagmiConnector };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import { useClient, useConnect, useDisconnect } from 'wagmi';
|
|
3
|
+
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
|
|
4
|
+
|
|
5
|
+
const SyncDynamicWagmi = ({ children, connector, }) => {
|
|
6
|
+
const { status: clientStatus } = useClient();
|
|
7
|
+
const { walletConnector } = useDynamicContext();
|
|
8
|
+
const { connect, status } = useConnect();
|
|
9
|
+
const { disconnect } = useDisconnect();
|
|
10
|
+
if (walletConnector) {
|
|
11
|
+
// after connection is successful, re-setup event listeners after a short delay
|
|
12
|
+
// so that they are not cleared by the teardown in useWalletEventListeners
|
|
13
|
+
if (status === 'success') {
|
|
14
|
+
setTimeout(() => {
|
|
15
|
+
connector === null || connector === void 0 ? void 0 : connector.setupEventListeners();
|
|
16
|
+
}, 100);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!walletConnector) {
|
|
21
|
+
disconnect();
|
|
22
|
+
}
|
|
23
|
+
else if (connector && clientStatus !== 'connected') {
|
|
24
|
+
connect({ connector });
|
|
25
|
+
}
|
|
26
|
+
}, [clientStatus, connect, connector, disconnect, walletConnector]);
|
|
27
|
+
// use React.createElement to prevent bunding react/jsx-runtime,
|
|
28
|
+
// which is not compatible when bundling apps using React 17
|
|
29
|
+
return React.createElement(React.Fragment, null, children);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { SyncDynamicWagmi };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { mainnet } from 'wagmi';
|
|
2
|
+
import { mapDynamicChainToWagmi } from './mappers/chain.es.js';
|
|
3
|
+
|
|
4
|
+
const getWagmiChainsFromDynamicChains = (dynamicChains) => {
|
|
5
|
+
const mappedChains = dynamicChains.map(mapDynamicChainToWagmi);
|
|
6
|
+
return mappedChains.length > 0 ? mappedChains : [mainnet];
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { getWagmiChainsFromDynamicChains };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { providers } from 'ethers';
|
|
2
2
|
import { Chain, ChainProviderFn } from 'wagmi';
|
|
3
|
-
import { EvmNetwork } from '@dynamic-labs/sdk-react';
|
|
3
|
+
import { EvmNetwork } from '@dynamic-labs/sdk-react-core';
|
|
4
4
|
export declare const getWagmiProvidersFromDynamicChains: (dynamicChains: EvmNetwork[]) => ChainProviderFn<providers.JsonRpcProvider, providers.WebSocketProvider, Chain>[];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { publicProvider } from 'wagmi/providers/public';
|
|
2
|
+
import { providers } from 'ethers';
|
|
3
|
+
|
|
4
|
+
const getWagmiProvidersFromDynamicChains = (dynamicChains) => {
|
|
5
|
+
var _a;
|
|
6
|
+
const wagmiProviders = [];
|
|
7
|
+
for (const dynamicChain of dynamicChains) {
|
|
8
|
+
for (const url of (_a = dynamicChain.privateCustomerRpcUrls) !== null && _a !== void 0 ? _a : []) {
|
|
9
|
+
wagmiProviders.push((chain) => {
|
|
10
|
+
if (chain.id !== dynamicChain.chainId)
|
|
11
|
+
return null;
|
|
12
|
+
return {
|
|
13
|
+
chain,
|
|
14
|
+
provider: () => new providers.JsonRpcProvider(url, chain.id),
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return [...wagmiProviders, publicProvider()];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { getWagmiProvidersFromDynamicChains };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as allChains from 'wagmi/chains';
|
|
2
|
+
|
|
3
|
+
// eslint-disable-next-line import/no-namespace
|
|
4
|
+
/**
|
|
5
|
+
* this is to map chains from Dynamic to the corresponding chain in Wagmi, if it exists.
|
|
6
|
+
* this is so that the exact same chain object is used across renders, which is important for
|
|
7
|
+
* the underlying ethers library to work correctly.
|
|
8
|
+
*/
|
|
9
|
+
const mapping = {};
|
|
10
|
+
Object.values(allChains).forEach((chain) => {
|
|
11
|
+
mapping[chain.id] = chain;
|
|
12
|
+
});
|
|
13
|
+
const mapDynamicChainToWagmi = (dynamicChain) => {
|
|
14
|
+
var _a, _b, _c, _d, _e;
|
|
15
|
+
const wagmiChain = mapping[dynamicChain.chainId];
|
|
16
|
+
if (wagmiChain) {
|
|
17
|
+
return wagmiChain;
|
|
18
|
+
}
|
|
19
|
+
const rpcUrls = {
|
|
20
|
+
default: {
|
|
21
|
+
http: dynamicChain.rpcUrls,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
const alchemyUrl = (_a = dynamicChain.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a.find((url) => url.includes('alchemy'));
|
|
25
|
+
if (alchemyUrl) {
|
|
26
|
+
rpcUrls.alchemy = { http: [alchemyUrl] };
|
|
27
|
+
}
|
|
28
|
+
const infuraUrl = (_b = dynamicChain.privateCustomerRpcUrls) === null || _b === void 0 ? void 0 : _b.find((url) => url.includes('infura'));
|
|
29
|
+
if (infuraUrl) {
|
|
30
|
+
rpcUrls.infura = { http: [infuraUrl] };
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
blockExplorers: {
|
|
34
|
+
default: {
|
|
35
|
+
name: '',
|
|
36
|
+
url: (_d = (_c = dynamicChain.blockExplorerUrls) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : '',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
id: dynamicChain.chainId,
|
|
40
|
+
name: (_e = dynamicChain.vanityName) !== null && _e !== void 0 ? _e : dynamicChain.chainName,
|
|
41
|
+
nativeCurrency: dynamicChain.nativeCurrency,
|
|
42
|
+
network: dynamicChain.chainName,
|
|
43
|
+
rpcUrls,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { mapDynamicChainToWagmi };
|