@getpara/cosmos-wallet-connectors 2.0.0-alpha.16 → 2.0.0-alpha.18
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.
|
@@ -25,6 +25,7 @@ export type CosmosExternalWalletContextType = {
|
|
|
25
25
|
cosmosPublicKeyHex?: string;
|
|
26
26
|
cosmosSigner?: string;
|
|
27
27
|
error?: string;
|
|
28
|
+
addressBech32?: string;
|
|
28
29
|
}>;
|
|
29
30
|
};
|
|
30
31
|
export type CosmosExternalWalletProviderConfig = {
|
|
@@ -34,10 +35,12 @@ export type CosmosExternalWalletProviderConfig = {
|
|
|
34
35
|
}) => void;
|
|
35
36
|
para: ParaWeb;
|
|
36
37
|
walletsWithFullAuth: TExternalWallet[];
|
|
38
|
+
includeWalletVerification?: boolean;
|
|
39
|
+
connectionOnly?: boolean;
|
|
37
40
|
connectedWallet?: Omit<Wallet, 'signer'> | null;
|
|
38
41
|
};
|
|
39
42
|
export type CosmosExternalWalletProviderConfigFull = {
|
|
40
43
|
wallets: WalletWithType[];
|
|
41
44
|
} & Omit<ParaCosmosProviderConfig, 'wallets'> & CosmosExternalWalletProviderConfig;
|
|
42
45
|
export declare const CosmosExternalWalletContext: import("react").Context<CosmosExternalWalletContextType>;
|
|
43
|
-
export declare function CosmosExternalWalletProvider({ children, onSwitchWallet, selectedChainId, wallets: incompleteWallets, chains, multiChain, shouldUseSuggestChainAndConnect, onSwitchChain, para, walletsWithFullAuth, connectedWallet, }: CosmosExternalWalletProviderConfigFull & PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
46
|
+
export declare function CosmosExternalWalletProvider({ children, onSwitchWallet, selectedChainId, wallets: incompleteWallets, chains, multiChain, shouldUseSuggestChainAndConnect, onSwitchChain, para, walletsWithFullAuth, connectedWallet, includeWalletVerification, connectionOnly, }: CosmosExternalWalletProviderConfigFull & PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
getWallet as grazGetWallet
|
|
19
19
|
} from "@getpara/graz";
|
|
20
20
|
import { useExternalWalletStore } from "../stores/useStore.js";
|
|
21
|
+
import { formatEthHexAddress } from "../utils/formatEthHexAddress.js";
|
|
21
22
|
const defaultCosmosExternalWallet = {
|
|
22
23
|
wallets: [],
|
|
23
24
|
chains: [],
|
|
@@ -40,9 +41,11 @@ function CosmosExternalWalletProvider({
|
|
|
40
41
|
onSwitchChain,
|
|
41
42
|
para,
|
|
42
43
|
walletsWithFullAuth,
|
|
43
|
-
connectedWallet
|
|
44
|
+
connectedWallet,
|
|
45
|
+
includeWalletVerification,
|
|
46
|
+
connectionOnly
|
|
44
47
|
}) {
|
|
45
|
-
var _a, _b;
|
|
48
|
+
var _a, _b, _c, _d;
|
|
46
49
|
const { suggestAndConnectAsync } = useSuggestChainAndConnect();
|
|
47
50
|
const {
|
|
48
51
|
data: account,
|
|
@@ -58,8 +61,8 @@ function CosmosExternalWalletProvider({
|
|
|
58
61
|
const { walletType } = useActiveWalletType();
|
|
59
62
|
const isLocalConnecting = useExternalWalletStore((state) => state.isConnecting);
|
|
60
63
|
const updateExternalWalletState = useExternalWalletStore((state) => state.updateState);
|
|
61
|
-
const
|
|
62
|
-
const address = multiChain ? (
|
|
64
|
+
const ethAddress = multiChain ? (_b = (_a = account == null ? void 0 : account[selectedChainId]) == null ? void 0 : _a.ethereumHexAddress) == null ? void 0 : _b.toLowerCase() : (_c = account == null ? void 0 : account.ethereumHexAddress) == null ? void 0 : _c.toLowerCase();
|
|
65
|
+
const address = multiChain ? (_d = account == null ? void 0 : account[selectedChainId]) == null ? void 0 : _d.bech32Address : account == null ? void 0 : account.bech32Address;
|
|
63
66
|
const verificationMessage = useRef();
|
|
64
67
|
const reset = () => __async(this, null, function* () {
|
|
65
68
|
yield disconnectAsync();
|
|
@@ -80,7 +83,7 @@ function CosmosExternalWalletProvider({
|
|
|
80
83
|
}
|
|
81
84
|
const connectedWallet2 = yield shouldUseSuggestChainAndConnect ? suggestAndConnectAsync({ walletType, chainInfo }) : connectAsync({ walletType, chainId });
|
|
82
85
|
changeResp.address = connectedWallet2.accounts[chainId].bech32Address;
|
|
83
|
-
changeResp.
|
|
86
|
+
changeResp.ethAddress = formatEthHexAddress(connectedWallet2.accounts[chainId].address);
|
|
84
87
|
} catch (err) {
|
|
85
88
|
if (err.message === "No wallet exists") {
|
|
86
89
|
changeResp.error = err.message;
|
|
@@ -92,26 +95,30 @@ function CosmosExternalWalletProvider({
|
|
|
92
95
|
onSwitchWallet(changeResp);
|
|
93
96
|
if (!changeResp.error) {
|
|
94
97
|
onSwitchChain(chainId);
|
|
95
|
-
const storedExternalWallet = para.externalWallets[(_a2 = changeResp.
|
|
98
|
+
const storedExternalWallet = para.externalWallets[(_a2 = changeResp.ethAddress) != null ? _a2 : ""];
|
|
96
99
|
para.setExternalWallet({
|
|
97
|
-
address: changeResp.
|
|
100
|
+
address: changeResp.ethAddress,
|
|
98
101
|
type: "COSMOS",
|
|
99
102
|
provider: getProviderName(walletType),
|
|
100
103
|
addressBech32: changeResp.address,
|
|
101
|
-
withFullParaAuth: storedExternalWallet.isExternalWithParaAuth
|
|
104
|
+
withFullParaAuth: storedExternalWallet.isExternalWithParaAuth,
|
|
105
|
+
withVerification: includeWalletVerification,
|
|
106
|
+
isConnectionOnly: connectionOnly
|
|
102
107
|
});
|
|
103
108
|
}
|
|
104
109
|
return { error };
|
|
105
110
|
});
|
|
106
|
-
const login = (
|
|
111
|
+
const login = (ethAddress2, address2, isFullAuthWallet, providerName) => __async(this, null, function* () {
|
|
107
112
|
try {
|
|
108
113
|
return yield para.loginExternalWallet({
|
|
109
114
|
externalWallet: {
|
|
110
|
-
address:
|
|
115
|
+
address: ethAddress2,
|
|
111
116
|
type: "COSMOS",
|
|
112
117
|
provider: providerName,
|
|
113
118
|
addressBech32: address2,
|
|
114
|
-
withFullParaAuth: isFullAuthWallet
|
|
119
|
+
withFullParaAuth: isFullAuthWallet,
|
|
120
|
+
withVerification: includeWalletVerification,
|
|
121
|
+
isConnectionOnly: connectionOnly
|
|
115
122
|
}
|
|
116
123
|
});
|
|
117
124
|
} catch (err) {
|
|
@@ -120,8 +127,8 @@ function CosmosExternalWalletProvider({
|
|
|
120
127
|
}
|
|
121
128
|
});
|
|
122
129
|
useEffect(() => {
|
|
123
|
-
const storedExternalWallet = para.externalWallets[
|
|
124
|
-
if (isConnected && !isConnecting && !isReconnecting && !isLocalConnecting && !!
|
|
130
|
+
const storedExternalWallet = para.externalWallets[ethAddress != null ? ethAddress : ""];
|
|
131
|
+
if (isConnected && !isConnecting && !isReconnecting && !isLocalConnecting && !!ethAddress && !storedExternalWallet && walletType !== GrazWalletType.PARA) {
|
|
125
132
|
reset();
|
|
126
133
|
}
|
|
127
134
|
}, [isConnecting, isLocalConnecting, isReconnecting, isConnected]);
|
|
@@ -151,7 +158,8 @@ function CosmosExternalWalletProvider({
|
|
|
151
158
|
const publicKey = (yield wallet.getKey(selectedChainId)).pubKey;
|
|
152
159
|
const signature = yield wallet.signArbitrary(selectedChainId, address, message);
|
|
153
160
|
return {
|
|
154
|
-
address:
|
|
161
|
+
address: ethAddress,
|
|
162
|
+
addressBech32: address,
|
|
155
163
|
signature: signature.signature,
|
|
156
164
|
cosmosPublicKeyHex: Buffer.from(publicKey).toString("hex"),
|
|
157
165
|
cosmosSigner: address
|
|
@@ -181,7 +189,7 @@ function CosmosExternalWalletProvider({
|
|
|
181
189
|
return;
|
|
182
190
|
}
|
|
183
191
|
let address2;
|
|
184
|
-
let
|
|
192
|
+
let ethAddress2;
|
|
185
193
|
let error;
|
|
186
194
|
let authState;
|
|
187
195
|
if (!walletType2) {
|
|
@@ -204,14 +212,14 @@ function CosmosExternalWalletProvider({
|
|
|
204
212
|
const connectedWallet2 = yield shouldUseSuggestChainAndConnect ? suggestAndConnectAsync({ walletType: walletType2, chainInfo }) : connectAsync({ walletType: walletType2, chainId: _chainId });
|
|
205
213
|
const firstChain = !chainId ? selectedChainId : typeof _chainId === "string" ? _chainId : _chainId[0];
|
|
206
214
|
address2 = connectedWallet2.accounts[firstChain].bech32Address;
|
|
207
|
-
|
|
215
|
+
ethAddress2 = formatEthHexAddress(connectedWallet2.accounts[firstChain].address);
|
|
208
216
|
if (connectedWallet2.accounts[firstChain]) {
|
|
209
217
|
try {
|
|
210
|
-
authState = yield login(
|
|
218
|
+
authState = yield login(ethAddress2, address2, isFullAuthWallet, getProviderName(walletType2));
|
|
211
219
|
verificationMessage.current = authState.stage === "verify" ? authState.signatureVerificationMessage : void 0;
|
|
212
220
|
} catch (err) {
|
|
213
221
|
authState = void 0;
|
|
214
|
-
|
|
222
|
+
ethAddress2 = void 0;
|
|
215
223
|
address2 = void 0;
|
|
216
224
|
error = err;
|
|
217
225
|
}
|
|
@@ -226,7 +234,7 @@ function CosmosExternalWalletProvider({
|
|
|
226
234
|
}
|
|
227
235
|
}
|
|
228
236
|
updateExternalWalletState({ isConnecting: false });
|
|
229
|
-
return { authState, address: address2,
|
|
237
|
+
return { authState, address: address2, ethAddress: ethAddress2, error };
|
|
230
238
|
});
|
|
231
239
|
const getWallet = (walletType2) => incompleteWallets.find((w) => w.grazType === walletType2 || w.grazMobileType === walletType2);
|
|
232
240
|
const getProviderName = (walletType2) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatEthHexAddress(address: Uint8Array): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/cosmos-wallet-connectors",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.18",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
"@cosmjs/stargate": "<=0.33.1",
|
|
21
21
|
"@cosmjs/tendermint-rpc": "<=0.31.3",
|
|
22
22
|
"@getpara/graz": "^1.0.0-dev.2",
|
|
23
|
-
"@getpara/web-sdk": "2.0.0-alpha.
|
|
23
|
+
"@getpara/web-sdk": "2.0.0-alpha.18",
|
|
24
24
|
"@leapwallet/cosmos-social-login-capsule-provider": "^0.0.41",
|
|
25
25
|
"zustand": "^4.5.2",
|
|
26
26
|
"zustand-sync-tabs": "^0.2.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@getpara/react-common": "2.0.0-alpha.
|
|
29
|
+
"@getpara/react-common": "2.0.0-alpha.18",
|
|
30
30
|
"@types/react": "^18.0.31",
|
|
31
31
|
"@types/react-dom": "^18.2.7",
|
|
32
32
|
"typescript": "^5.4.3"
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"dist",
|
|
40
40
|
"package.json"
|
|
41
41
|
],
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "2333bc727fe61593821d448ee12facaee230c4b0"
|
|
43
43
|
}
|