@web3auth/no-modal 10.4.0 → 10.5.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/dist/lib.cjs/base/analytics.js +2 -0
- package/dist/lib.cjs/base/utils.js +1 -1
- package/dist/lib.cjs/connectors/auth-connector/authConnector.js +10 -2
- package/dist/lib.cjs/connectors/coinbase-connector/coinbaseConnector.js +10 -3
- package/dist/lib.cjs/connectors/injected-evm-connector/injectedEvmConnector.js +10 -3
- package/dist/lib.cjs/connectors/injected-solana-connector/walletStandardConnector.js +10 -3
- package/dist/lib.cjs/connectors/metamask-connector/metamaskConnector.js +11 -5
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +22 -9
- package/dist/lib.cjs/noModal.js +8 -1
- package/dist/lib.cjs/plugins/wallet-services-plugin/plugin.js +37 -13
- package/dist/lib.cjs/react/hooks/useFunding.js +47 -0
- package/dist/lib.cjs/react/hooks/useReceive.js +47 -0
- package/dist/lib.cjs/react/index.js +4 -0
- package/dist/lib.cjs/types/base/analytics.d.ts +2 -0
- package/dist/lib.cjs/types/base/connector/interfaces.d.ts +2 -0
- package/dist/lib.cjs/types/connectors/auth-connector/authConnector.d.ts +2 -4
- package/dist/lib.cjs/types/connectors/injected-evm-connector/injectedEvmConnector.d.ts +2 -4
- package/dist/lib.cjs/types/connectors/injected-solana-connector/walletStandardConnector.d.ts +2 -4
- package/dist/lib.cjs/types/plugins/wallet-services-plugin/plugin.d.ts +2 -0
- package/dist/lib.cjs/types/react/hooks/index.d.ts +2 -0
- package/dist/lib.cjs/types/react/hooks/useFunding.d.ts +8 -0
- package/dist/lib.cjs/types/react/hooks/useReceive.d.ts +8 -0
- package/dist/lib.cjs/types/vue/composables/index.d.ts +2 -0
- package/dist/lib.cjs/types/vue/composables/useFunding.d.ts +9 -0
- package/dist/lib.cjs/types/vue/composables/useReceive.d.ts +9 -0
- package/dist/lib.cjs/vue/composables/useFunding.js +47 -0
- package/dist/lib.cjs/vue/composables/useReceive.js +47 -0
- package/dist/lib.cjs/vue/index.js +4 -0
- package/dist/lib.esm/base/analytics.js +2 -0
- package/dist/lib.esm/base/utils.js +1 -1
- package/dist/lib.esm/connectors/auth-connector/authConnector.js +10 -2
- package/dist/lib.esm/connectors/coinbase-connector/coinbaseConnector.js +10 -3
- package/dist/lib.esm/connectors/injected-evm-connector/injectedEvmConnector.js +10 -3
- package/dist/lib.esm/connectors/injected-solana-connector/walletStandardConnector.js +10 -3
- package/dist/lib.esm/connectors/metamask-connector/metamaskConnector.js +11 -5
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +22 -9
- package/dist/lib.esm/noModal.js +9 -1
- package/dist/lib.esm/plugins/wallet-services-plugin/plugin.js +39 -13
- package/dist/lib.esm/react/hooks/useFunding.js +32 -0
- package/dist/lib.esm/react/hooks/useReceive.js +32 -0
- package/dist/lib.esm/react/index.js +2 -0
- package/dist/lib.esm/vue/composables/useFunding.js +32 -0
- package/dist/lib.esm/vue/composables/useReceive.js +32 -0
- package/dist/lib.esm/vue/index.js +2 -0
- package/dist/noModal.umd.min.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseEmbedControllerState } from "@toruslabs/base-controllers";
|
|
2
|
+
import { Web3AuthError } from "../../base";
|
|
3
|
+
export interface IUseFunding {
|
|
4
|
+
loading: boolean;
|
|
5
|
+
error: Web3AuthError | null;
|
|
6
|
+
showFunding: (showFundingParams?: BaseEmbedControllerState["showFunding"]) => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare const useFunding: () => IUseFunding;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseEmbedControllerState } from "@toruslabs/base-controllers";
|
|
2
|
+
import { Web3AuthError } from "../../base";
|
|
3
|
+
export interface IUseReceive {
|
|
4
|
+
loading: boolean;
|
|
5
|
+
error: Web3AuthError | null;
|
|
6
|
+
showReceive: (showReceiveParams?: BaseEmbedControllerState["showReceive"]) => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare const useReceive: () => IUseReceive;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export * from "./useCheckout";
|
|
2
2
|
export * from "./useEnableMFA";
|
|
3
|
+
export * from "./useFunding";
|
|
3
4
|
export * from "./useIdentityToken";
|
|
4
5
|
export * from "./useManageMFA";
|
|
6
|
+
export * from "./useReceive";
|
|
5
7
|
export * from "./useSwap";
|
|
6
8
|
export * from "./useSwitchChain";
|
|
7
9
|
export * from "./useWalletConnectScanner";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseEmbedControllerState } from "@toruslabs/base-controllers";
|
|
2
|
+
import { Ref } from "vue";
|
|
3
|
+
import { Web3AuthError } from "../../base";
|
|
4
|
+
export interface IUseFunding {
|
|
5
|
+
loading: Ref<boolean>;
|
|
6
|
+
error: Ref<Web3AuthError | null>;
|
|
7
|
+
showFunding: (showFundingParams?: BaseEmbedControllerState["showFunding"]) => Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare const useFunding: () => IUseFunding;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseEmbedControllerState } from "@toruslabs/base-controllers";
|
|
2
|
+
import { Ref } from "vue";
|
|
3
|
+
import { Web3AuthError } from "../../base";
|
|
4
|
+
export interface IUseReceive {
|
|
5
|
+
loading: Ref<boolean>;
|
|
6
|
+
error: Ref<Web3AuthError | null>;
|
|
7
|
+
showReceive: (showReceiveParams?: BaseEmbedControllerState["showReceive"]) => Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare const useReceive: () => IUseReceive;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var vue = require('vue');
|
|
4
|
+
require('@babel/runtime/helpers/objectSpread2');
|
|
5
|
+
require('@babel/runtime/helpers/defineProperty');
|
|
6
|
+
require('@segment/analytics-next');
|
|
7
|
+
require('../../base/loglevel.js');
|
|
8
|
+
require('@toruslabs/base-controllers');
|
|
9
|
+
require('@web3auth/auth');
|
|
10
|
+
require('../../base/errors/index.js');
|
|
11
|
+
require('../../base/wallet/index.js');
|
|
12
|
+
require('../../base/connector/constants.js');
|
|
13
|
+
require('jwt-decode');
|
|
14
|
+
var errors = require('../../base/plugin/errors.js');
|
|
15
|
+
require('../../base/plugin/IPlugin.js');
|
|
16
|
+
require('@toruslabs/constants');
|
|
17
|
+
require('@toruslabs/http-helpers');
|
|
18
|
+
var useWalletServicesPlugin = require('./useWalletServicesPlugin.js');
|
|
19
|
+
|
|
20
|
+
const useFunding = () => {
|
|
21
|
+
const {
|
|
22
|
+
plugin,
|
|
23
|
+
ready
|
|
24
|
+
} = useWalletServicesPlugin.useWalletServicesPlugin();
|
|
25
|
+
const loading = vue.ref(false);
|
|
26
|
+
const error = vue.ref(null);
|
|
27
|
+
const showFunding = async showFundingParams => {
|
|
28
|
+
loading.value = true;
|
|
29
|
+
error.value = null;
|
|
30
|
+
try {
|
|
31
|
+
if (!plugin) throw errors.WalletServicesPluginError.notInitialized();
|
|
32
|
+
if (!ready) throw errors.WalletServicesPluginError.walletPluginNotConnected();
|
|
33
|
+
await plugin.value.showFunding(showFundingParams);
|
|
34
|
+
} catch (err) {
|
|
35
|
+
error.value = err;
|
|
36
|
+
} finally {
|
|
37
|
+
loading.value = false;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
loading,
|
|
42
|
+
error,
|
|
43
|
+
showFunding
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
exports.useFunding = useFunding;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var vue = require('vue');
|
|
4
|
+
require('@babel/runtime/helpers/objectSpread2');
|
|
5
|
+
require('@babel/runtime/helpers/defineProperty');
|
|
6
|
+
require('@segment/analytics-next');
|
|
7
|
+
require('../../base/loglevel.js');
|
|
8
|
+
require('@toruslabs/base-controllers');
|
|
9
|
+
require('@web3auth/auth');
|
|
10
|
+
require('../../base/errors/index.js');
|
|
11
|
+
require('../../base/wallet/index.js');
|
|
12
|
+
require('../../base/connector/constants.js');
|
|
13
|
+
require('jwt-decode');
|
|
14
|
+
var errors = require('../../base/plugin/errors.js');
|
|
15
|
+
require('../../base/plugin/IPlugin.js');
|
|
16
|
+
require('@toruslabs/constants');
|
|
17
|
+
require('@toruslabs/http-helpers');
|
|
18
|
+
var useWalletServicesPlugin = require('./useWalletServicesPlugin.js');
|
|
19
|
+
|
|
20
|
+
const useReceive = () => {
|
|
21
|
+
const {
|
|
22
|
+
plugin,
|
|
23
|
+
ready
|
|
24
|
+
} = useWalletServicesPlugin.useWalletServicesPlugin();
|
|
25
|
+
const loading = vue.ref(false);
|
|
26
|
+
const error = vue.ref(null);
|
|
27
|
+
const showReceive = async showReceiveParams => {
|
|
28
|
+
loading.value = true;
|
|
29
|
+
error.value = null;
|
|
30
|
+
try {
|
|
31
|
+
if (!plugin) throw errors.WalletServicesPluginError.notInitialized();
|
|
32
|
+
if (!ready) throw errors.WalletServicesPluginError.walletPluginNotConnected();
|
|
33
|
+
await plugin.value.showReceive(showReceiveParams);
|
|
34
|
+
} catch (err) {
|
|
35
|
+
error.value = err;
|
|
36
|
+
} finally {
|
|
37
|
+
loading.value = false;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
loading,
|
|
42
|
+
error,
|
|
43
|
+
showReceive
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
exports.useReceive = useReceive;
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var useCheckout = require('./composables/useCheckout.js');
|
|
4
4
|
var useEnableMFA = require('./composables/useEnableMFA.js');
|
|
5
|
+
var useFunding = require('./composables/useFunding.js');
|
|
5
6
|
var useIdentityToken = require('./composables/useIdentityToken.js');
|
|
6
7
|
var useManageMFA = require('./composables/useManageMFA.js');
|
|
8
|
+
var useReceive = require('./composables/useReceive.js');
|
|
7
9
|
var useSwap = require('./composables/useSwap.js');
|
|
8
10
|
var useSwitchChain = require('./composables/useSwitchChain.js');
|
|
9
11
|
var useWalletConnectScanner = require('./composables/useWalletConnectScanner.js');
|
|
@@ -20,8 +22,10 @@ var Web3AuthProvider = require('./Web3AuthProvider.js');
|
|
|
20
22
|
|
|
21
23
|
exports.useCheckout = useCheckout.useCheckout;
|
|
22
24
|
exports.useEnableMFA = useEnableMFA.useEnableMFA;
|
|
25
|
+
exports.useFunding = useFunding.useFunding;
|
|
23
26
|
exports.useIdentityToken = useIdentityToken.useIdentityToken;
|
|
24
27
|
exports.useManageMFA = useManageMFA.useManageMFA;
|
|
28
|
+
exports.useReceive = useReceive.useReceive;
|
|
25
29
|
exports.useSwap = useSwap.useSwap;
|
|
26
30
|
exports.useSwitchChain = useSwitchChain.useSwitchChain;
|
|
27
31
|
exports.useWalletConnectScanner = useWalletConnectScanner.useWalletConnectScanner;
|
|
@@ -112,7 +112,9 @@ const ANALYTICS_EVENTS = {
|
|
|
112
112
|
// Wallet Plugin
|
|
113
113
|
WALLET_UI_CLICKED: "Wallet UI Clicked",
|
|
114
114
|
WALLET_CONNECT_SCANNER_CLICKED: "Wallet Connect Scanner Clicked",
|
|
115
|
+
WALLET_FUNDING_CLICKED: "Wallet Funding Clicked",
|
|
115
116
|
WALLET_CHECKOUT_CLICKED: "Wallet Checkout Clicked",
|
|
117
|
+
WALLET_RECEIVE_CLICKED: "Wallet Receive Clicked",
|
|
116
118
|
WALLET_SWAP_CLICKED: "Wallet Swap Clicked"
|
|
117
119
|
};
|
|
118
120
|
const ANALYTICS_INTEGRATION_TYPE = {
|
|
@@ -145,7 +145,7 @@ const getWalletServicesAnalyticsProperties = walletServicesConfig => {
|
|
|
145
145
|
ws_default_portfolio: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig1 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig1 === void 0 ? void 0 : _walletServicesConfig1.defaultPortfolio
|
|
146
146
|
};
|
|
147
147
|
};
|
|
148
|
-
const sdkVersion = "10.
|
|
148
|
+
const sdkVersion = "10.5.0";
|
|
149
149
|
const getErrorAnalyticsProperties = error => {
|
|
150
150
|
try {
|
|
151
151
|
const code = error instanceof Web3AuthError ? error.code : error === null || error === void 0 ? void 0 : error.code;
|
|
@@ -142,7 +142,8 @@ class AuthConnector extends BaseConnector {
|
|
|
142
142
|
if (sessionId && (options.autoConnect || isRedirectResult)) {
|
|
143
143
|
this.rehydrated = true;
|
|
144
144
|
await this.connect({
|
|
145
|
-
chainId: options.chainId
|
|
145
|
+
chainId: options.chainId,
|
|
146
|
+
getIdentityToken: false
|
|
146
147
|
});
|
|
147
148
|
} else if (!sessionId && options.autoConnect) {
|
|
148
149
|
// if here, this means that the connector is cached but the sessionId is not available.
|
|
@@ -364,11 +365,18 @@ class AuthConnector extends BaseConnector {
|
|
|
364
365
|
});
|
|
365
366
|
if (isLoggedIn) {
|
|
366
367
|
var _this$wsEmbedInstance3;
|
|
368
|
+
// if getIdentityToken is true, then get the identity token
|
|
369
|
+
// No need to get the identity token for auth connector as it is already handled
|
|
370
|
+
let identityTokenInfo;
|
|
371
|
+
if (params.getIdentityToken) {
|
|
372
|
+
identityTokenInfo = await this.getIdentityToken();
|
|
373
|
+
}
|
|
367
374
|
this.status = CONNECTOR_STATUS.CONNECTED;
|
|
368
375
|
this.emit(CONNECTOR_EVENTS.CONNECTED, {
|
|
369
376
|
connector: WALLET_CONNECTORS.AUTH,
|
|
370
377
|
reconnected: this.rehydrated,
|
|
371
|
-
provider: this.provider
|
|
378
|
+
provider: this.provider,
|
|
379
|
+
identityTokenInfo
|
|
372
380
|
});
|
|
373
381
|
// handle disconnect from ws embed
|
|
374
382
|
(_this$wsEmbedInstance3 = this.wsEmbedInstance) === null || _this$wsEmbedInstance3 === void 0 || _this$wsEmbedInstance3.provider.on("accountsChanged", (accounts = []) => {
|
|
@@ -54,7 +54,8 @@ class CoinbaseConnector extends BaseEvmConnector {
|
|
|
54
54
|
if (options.autoConnect) {
|
|
55
55
|
this.rehydrated = true;
|
|
56
56
|
const provider = await this.connect({
|
|
57
|
-
chainId: options.chainId
|
|
57
|
+
chainId: options.chainId,
|
|
58
|
+
getIdentityToken: false
|
|
58
59
|
});
|
|
59
60
|
// the connect function could fail silently as well.
|
|
60
61
|
if (!provider) {
|
|
@@ -67,7 +68,8 @@ class CoinbaseConnector extends BaseEvmConnector {
|
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
async connect({
|
|
70
|
-
chainId
|
|
71
|
+
chainId,
|
|
72
|
+
getIdentityToken
|
|
71
73
|
}) {
|
|
72
74
|
super.checkConnectionRequirements();
|
|
73
75
|
if (!this.coinbaseProvider) throw WalletLoginError.notConnectedError("Connector is not initialized");
|
|
@@ -93,10 +95,15 @@ class CoinbaseConnector extends BaseEvmConnector {
|
|
|
93
95
|
// ready to be connected again
|
|
94
96
|
this.disconnect();
|
|
95
97
|
});
|
|
98
|
+
let identityTokenInfo;
|
|
99
|
+
if (getIdentityToken) {
|
|
100
|
+
identityTokenInfo = await this.getIdentityToken();
|
|
101
|
+
}
|
|
96
102
|
this.emit(CONNECTOR_EVENTS.CONNECTED, {
|
|
97
103
|
connector: WALLET_CONNECTORS.COINBASE,
|
|
98
104
|
reconnected: this.rehydrated,
|
|
99
|
-
provider: this.provider
|
|
105
|
+
provider: this.provider,
|
|
106
|
+
identityTokenInfo
|
|
100
107
|
});
|
|
101
108
|
return this.provider;
|
|
102
109
|
} catch (error) {
|
|
@@ -43,7 +43,8 @@ class InjectedEvmConnector extends BaseEvmConnector {
|
|
|
43
43
|
if (options.autoConnect) {
|
|
44
44
|
this.rehydrated = true;
|
|
45
45
|
const provider = await this.connect({
|
|
46
|
-
chainId: options.chainId
|
|
46
|
+
chainId: options.chainId,
|
|
47
|
+
getIdentityToken: false
|
|
47
48
|
});
|
|
48
49
|
if (!provider) {
|
|
49
50
|
this.rehydrated = false;
|
|
@@ -55,7 +56,8 @@ class InjectedEvmConnector extends BaseEvmConnector {
|
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
async connect({
|
|
58
|
-
chainId
|
|
59
|
+
chainId,
|
|
60
|
+
getIdentityToken
|
|
59
61
|
}) {
|
|
60
62
|
super.checkConnectionRequirements();
|
|
61
63
|
if (!this.injectedProvider) throw WalletLoginError.connectionError("Injected provider is not available");
|
|
@@ -87,10 +89,15 @@ class InjectedEvmConnector extends BaseEvmConnector {
|
|
|
87
89
|
}
|
|
88
90
|
};
|
|
89
91
|
this.injectedProvider.on("accountsChanged", accountDisconnectHandler);
|
|
92
|
+
let identityTokenInfo;
|
|
93
|
+
if (getIdentityToken) {
|
|
94
|
+
identityTokenInfo = await this.getIdentityToken();
|
|
95
|
+
}
|
|
90
96
|
this.emit(CONNECTOR_EVENTS.CONNECTED, {
|
|
91
97
|
connector: this.name,
|
|
92
98
|
reconnected: this.rehydrated,
|
|
93
|
-
provider: this.injectedProvider
|
|
99
|
+
provider: this.injectedProvider,
|
|
100
|
+
identityTokenInfo
|
|
94
101
|
});
|
|
95
102
|
return this.injectedProvider;
|
|
96
103
|
} catch (error) {
|
|
@@ -57,7 +57,8 @@ class WalletStandardConnector extends BaseSolanaConnector {
|
|
|
57
57
|
if (options.autoConnect) {
|
|
58
58
|
this.rehydrated = true;
|
|
59
59
|
const provider = await this.connect({
|
|
60
|
-
chainId: options.chainId
|
|
60
|
+
chainId: options.chainId,
|
|
61
|
+
getIdentityToken: false
|
|
61
62
|
});
|
|
62
63
|
if (!provider) {
|
|
63
64
|
this.rehydrated = false;
|
|
@@ -69,7 +70,8 @@ class WalletStandardConnector extends BaseSolanaConnector {
|
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
async connect({
|
|
72
|
-
chainId
|
|
73
|
+
chainId,
|
|
74
|
+
getIdentityToken
|
|
73
75
|
}) {
|
|
74
76
|
try {
|
|
75
77
|
super.checkConnectionRequirements();
|
|
@@ -86,10 +88,15 @@ class WalletStandardConnector extends BaseSolanaConnector {
|
|
|
86
88
|
}
|
|
87
89
|
if (this.wallet.accounts.length === 0) throw WalletLoginError.connectionError();
|
|
88
90
|
this.status = CONNECTOR_STATUS.CONNECTED;
|
|
91
|
+
let identityTokenInfo;
|
|
92
|
+
if (getIdentityToken) {
|
|
93
|
+
identityTokenInfo = await this.getIdentityToken();
|
|
94
|
+
}
|
|
89
95
|
this.emit(CONNECTOR_EVENTS.CONNECTED, {
|
|
90
96
|
connector: this.name,
|
|
91
97
|
reconnected: this.rehydrated,
|
|
92
|
-
provider: this.provider
|
|
98
|
+
provider: this.provider,
|
|
99
|
+
identityTokenInfo
|
|
93
100
|
});
|
|
94
101
|
return this.provider;
|
|
95
102
|
} catch (error) {
|
|
@@ -37,7 +37,6 @@ class MetaMaskConnector extends BaseEvmConnector {
|
|
|
37
37
|
throw new Error("Not implemented");
|
|
38
38
|
}
|
|
39
39
|
async init(options) {
|
|
40
|
-
var _metamaskOptions$useD;
|
|
41
40
|
await super.init(options);
|
|
42
41
|
const chainConfig = this.coreOptions.chains.find(x => x.chainId === options.chainId);
|
|
43
42
|
super.checkInitializationRequirements({
|
|
@@ -59,7 +58,7 @@ class MetaMaskConnector extends BaseEvmConnector {
|
|
|
59
58
|
});
|
|
60
59
|
this.metamaskSDK = new MetaMaskSDK(_objectSpread(_objectSpread({}, metamaskOptions), {}, {
|
|
61
60
|
_source: "web3auth",
|
|
62
|
-
|
|
61
|
+
preferDesktop: true
|
|
63
62
|
}));
|
|
64
63
|
// Work around: in case there is an existing SDK instance in memory (window.mmsdk exists), it won't initialize the new SDK instance again
|
|
65
64
|
// and return the existing instance instead of undefined (this is an assumption, not sure if it's a bug or feature of the MetaMask SDK)
|
|
@@ -74,7 +73,8 @@ class MetaMaskConnector extends BaseEvmConnector {
|
|
|
74
73
|
if (options.autoConnect) {
|
|
75
74
|
this.rehydrated = true;
|
|
76
75
|
const provider = await this.connect({
|
|
77
|
-
chainId: options.chainId
|
|
76
|
+
chainId: options.chainId,
|
|
77
|
+
getIdentityToken: false
|
|
78
78
|
});
|
|
79
79
|
if (!provider) {
|
|
80
80
|
this.rehydrated = false;
|
|
@@ -86,7 +86,8 @@ class MetaMaskConnector extends BaseEvmConnector {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
async connect({
|
|
89
|
-
chainId
|
|
89
|
+
chainId,
|
|
90
|
+
getIdentityToken
|
|
90
91
|
}) {
|
|
91
92
|
super.checkConnectionRequirements();
|
|
92
93
|
if (!this.metamaskSDK) throw WalletLoginError.notConnectedError("Connector is not initialized");
|
|
@@ -152,10 +153,15 @@ class MetaMaskConnector extends BaseEvmConnector {
|
|
|
152
153
|
duration: Date.now() - startTime
|
|
153
154
|
}));
|
|
154
155
|
}
|
|
156
|
+
let identityTokenInfo;
|
|
157
|
+
if (getIdentityToken) {
|
|
158
|
+
identityTokenInfo = await this.getIdentityToken();
|
|
159
|
+
}
|
|
155
160
|
this.emit(CONNECTOR_EVENTS.CONNECTED, {
|
|
156
161
|
connector: WALLET_CONNECTORS.METAMASK,
|
|
157
162
|
reconnected: this.rehydrated,
|
|
158
|
-
provider: this.metamaskProvider
|
|
163
|
+
provider: this.metamaskProvider,
|
|
164
|
+
identityTokenInfo
|
|
159
165
|
});
|
|
160
166
|
return this.metamaskProvider;
|
|
161
167
|
} catch (error) {
|
|
@@ -99,7 +99,8 @@ class WalletConnectV2Connector extends BaseConnector {
|
|
|
99
99
|
this.rehydrated = true;
|
|
100
100
|
try {
|
|
101
101
|
await this.onConnectHandler({
|
|
102
|
-
chain: chainConfig
|
|
102
|
+
chain: chainConfig,
|
|
103
|
+
getIdentityToken: false
|
|
103
104
|
});
|
|
104
105
|
} catch (error) {
|
|
105
106
|
log.error("wallet auto connect", error);
|
|
@@ -112,7 +113,8 @@ class WalletConnectV2Connector extends BaseConnector {
|
|
|
112
113
|
}
|
|
113
114
|
}
|
|
114
115
|
async connect({
|
|
115
|
-
chainId
|
|
116
|
+
chainId,
|
|
117
|
+
getIdentityToken
|
|
116
118
|
}) {
|
|
117
119
|
super.checkConnectionRequirements();
|
|
118
120
|
const chainConfig = this.coreOptions.chains.find(x => x.chainId === chainId);
|
|
@@ -164,14 +166,16 @@ class WalletConnectV2Connector extends BaseConnector {
|
|
|
164
166
|
// if already connected
|
|
165
167
|
if (this.connected) {
|
|
166
168
|
await this.onConnectHandler({
|
|
167
|
-
chain: chainConfig
|
|
169
|
+
chain: chainConfig,
|
|
170
|
+
getIdentityToken: false
|
|
168
171
|
});
|
|
169
172
|
return this.provider;
|
|
170
173
|
}
|
|
171
174
|
if (this.status !== CONNECTOR_STATUS.CONNECTING) {
|
|
172
175
|
await this.createNewSession({
|
|
173
176
|
chainConfig,
|
|
174
|
-
trackCompletionEvents
|
|
177
|
+
trackCompletionEvents,
|
|
178
|
+
getIdentityToken
|
|
175
179
|
});
|
|
176
180
|
}
|
|
177
181
|
return this.provider;
|
|
@@ -306,7 +310,8 @@ class WalletConnectV2Connector extends BaseConnector {
|
|
|
306
310
|
async createNewSession({
|
|
307
311
|
forceNewSession = false,
|
|
308
312
|
chainConfig,
|
|
309
|
-
trackCompletionEvents
|
|
313
|
+
trackCompletionEvents,
|
|
314
|
+
getIdentityToken
|
|
310
315
|
}) {
|
|
311
316
|
try {
|
|
312
317
|
var _this$activeSession4, _this$connectorOption7;
|
|
@@ -355,7 +360,8 @@ class WalletConnectV2Connector extends BaseConnector {
|
|
|
355
360
|
// Handle the returned session (e.g. update UI to "connected" state).
|
|
356
361
|
await this.onConnectHandler({
|
|
357
362
|
chain: chainConfig,
|
|
358
|
-
trackCompletionEvents
|
|
363
|
+
trackCompletionEvents,
|
|
364
|
+
getIdentityToken
|
|
359
365
|
});
|
|
360
366
|
if (qrcodeModal) {
|
|
361
367
|
qrcodeModal.closeModal();
|
|
@@ -369,7 +375,8 @@ class WalletConnectV2Connector extends BaseConnector {
|
|
|
369
375
|
log.info("retrying to create new wallet connect session since proposal expired");
|
|
370
376
|
return this.createNewSession({
|
|
371
377
|
forceNewSession: true,
|
|
372
|
-
chainConfig
|
|
378
|
+
chainConfig,
|
|
379
|
+
getIdentityToken
|
|
373
380
|
});
|
|
374
381
|
}
|
|
375
382
|
if (this.status === CONNECTOR_STATUS.READY) {
|
|
@@ -384,7 +391,8 @@ class WalletConnectV2Connector extends BaseConnector {
|
|
|
384
391
|
}
|
|
385
392
|
async onConnectHandler({
|
|
386
393
|
chain,
|
|
387
|
-
trackCompletionEvents
|
|
394
|
+
trackCompletionEvents,
|
|
395
|
+
getIdentityToken
|
|
388
396
|
}) {
|
|
389
397
|
var _this$connectorOption8;
|
|
390
398
|
if (!this.connector || !this.wcProvider) throw WalletInitializationError.notReady("Wallet connect connector is not ready yet");
|
|
@@ -405,10 +413,15 @@ class WalletConnectV2Connector extends BaseConnector {
|
|
|
405
413
|
|
|
406
414
|
// track connection events
|
|
407
415
|
if (trackCompletionEvents) trackCompletionEvents();
|
|
416
|
+
let identityTokenInfo;
|
|
417
|
+
if (getIdentityToken) {
|
|
418
|
+
identityTokenInfo = await this.getIdentityToken();
|
|
419
|
+
}
|
|
408
420
|
this.emit(CONNECTOR_EVENTS.CONNECTED, {
|
|
409
421
|
connector: WALLET_CONNECTORS.WALLET_CONNECT_V2,
|
|
410
422
|
reconnected: this.rehydrated,
|
|
411
|
-
provider: this.provider
|
|
423
|
+
provider: this.provider,
|
|
424
|
+
identityTokenInfo
|
|
412
425
|
});
|
|
413
426
|
}
|
|
414
427
|
subscribeEvents() {
|
package/dist/lib.esm/noModal.js
CHANGED
|
@@ -603,6 +603,14 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
603
603
|
const isExternalWalletEnabled = Boolean(projectConfig.externalWalletAuth);
|
|
604
604
|
const isMipdEnabled = isExternalWalletEnabled && ((_this$coreOptions$mul = this.coreOptions.multiInjectedProviderDiscovery) !== null && _this$coreOptions$mul !== void 0 ? _this$coreOptions$mul : true);
|
|
605
605
|
const chainNamespaces = new Set(this.coreOptions.chains.map(chain => chain.chainNamespace));
|
|
606
|
+
|
|
607
|
+
// it's safe to add it here as if there is a MetaMask injected provider, this won't override it
|
|
608
|
+
// only set headless to true if modal SDK is used, otherwise just use the modal from native Metamask SDK
|
|
609
|
+
if (isBrowser() && chainNamespaces.has(CHAIN_NAMESPACES.EIP155) && !chainNamespaces.has(CHAIN_NAMESPACES.SOLANA)) {
|
|
610
|
+
connectorFns.push(metaMaskConnector(modalMode ? {
|
|
611
|
+
headless: true
|
|
612
|
+
} : undefined));
|
|
613
|
+
}
|
|
606
614
|
if (isMipdEnabled && isBrowser()) {
|
|
607
615
|
// Solana chains
|
|
608
616
|
if (chainNamespaces.has(CHAIN_NAMESPACES.SOLANA)) {
|
|
@@ -637,7 +645,7 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
637
645
|
|
|
638
646
|
// it's safe to add it here as if there is a MetaMask injected provider, this won't override it
|
|
639
647
|
// only set headless to true if modal SDK is used, otherwise just use the modal from native Metamask SDK
|
|
640
|
-
if (isBrowser() && (chainNamespaces.has(CHAIN_NAMESPACES.
|
|
648
|
+
if (isBrowser() && (chainNamespaces.has(CHAIN_NAMESPACES.SOLANA) || chainNamespaces.has(CHAIN_NAMESPACES.EIP155))) {
|
|
641
649
|
connectorFns.push(metaMaskConnector(modalMode ? {
|
|
642
650
|
headless: true
|
|
643
651
|
} : undefined));
|
|
@@ -89,36 +89,62 @@ class WalletServicesPlugin extends SafeEventEmitter {
|
|
|
89
89
|
});
|
|
90
90
|
return this.wsEmbedInstance.showWalletConnectScanner(showWalletConnectParams);
|
|
91
91
|
}
|
|
92
|
-
async
|
|
92
|
+
async showFunding(showFundingParams) {
|
|
93
93
|
var _this$wsEmbedInstance3, _this$analytics2;
|
|
94
94
|
if (!((_this$wsEmbedInstance3 = this.wsEmbedInstance) !== null && _this$wsEmbedInstance3 !== void 0 && _this$wsEmbedInstance3.isLoggedIn)) throw WalletServicesPluginError.walletPluginNotConnected();
|
|
95
95
|
|
|
96
96
|
// analytics
|
|
97
|
-
(_this$analytics2 = this.analytics) === null || _this$analytics2 === void 0 || _this$analytics2.track(ANALYTICS_EVENTS.
|
|
97
|
+
(_this$analytics2 = this.analytics) === null || _this$analytics2 === void 0 || _this$analytics2.track(ANALYTICS_EVENTS.WALLET_FUNDING_CLICKED, {
|
|
98
|
+
is_visible: showFundingParams === null || showFundingParams === void 0 ? void 0 : showFundingParams.show
|
|
99
|
+
});
|
|
100
|
+
return this.wsEmbedInstance.showFunding(showFundingParams);
|
|
101
|
+
}
|
|
102
|
+
async showCheckout(showCheckoutParams) {
|
|
103
|
+
var _this$wsEmbedInstance4, _this$analytics3;
|
|
104
|
+
if (!((_this$wsEmbedInstance4 = this.wsEmbedInstance) !== null && _this$wsEmbedInstance4 !== void 0 && _this$wsEmbedInstance4.isLoggedIn)) throw WalletServicesPluginError.walletPluginNotConnected();
|
|
105
|
+
|
|
106
|
+
// analytics
|
|
107
|
+
(_this$analytics3 = this.analytics) === null || _this$analytics3 === void 0 || _this$analytics3.track(ANALYTICS_EVENTS.WALLET_CHECKOUT_CLICKED, {
|
|
98
108
|
is_visible: showCheckoutParams === null || showCheckoutParams === void 0 ? void 0 : showCheckoutParams.show,
|
|
99
109
|
receive_wallet_address_enabled: !!(showCheckoutParams !== null && showCheckoutParams !== void 0 && showCheckoutParams.receiveWalletAddress),
|
|
110
|
+
// TODO: where is the below?
|
|
111
|
+
// receive_wallet_address: showCheckoutParams?.receiveWalletAddress,
|
|
100
112
|
token_list: showCheckoutParams === null || showCheckoutParams === void 0 ? void 0 : showCheckoutParams.tokenList,
|
|
101
|
-
fiat_list: showCheckoutParams === null || showCheckoutParams === void 0 ? void 0 : showCheckoutParams.fiatList
|
|
113
|
+
fiat_list: showCheckoutParams === null || showCheckoutParams === void 0 ? void 0 : showCheckoutParams.fiatList,
|
|
114
|
+
crypto: showCheckoutParams === null || showCheckoutParams === void 0 ? void 0 : showCheckoutParams.crypto,
|
|
115
|
+
fiat: showCheckoutParams === null || showCheckoutParams === void 0 ? void 0 : showCheckoutParams.fiat,
|
|
116
|
+
fiat_amount: showCheckoutParams === null || showCheckoutParams === void 0 ? void 0 : showCheckoutParams.fiatAmount,
|
|
117
|
+
crypto_amount: showCheckoutParams === null || showCheckoutParams === void 0 ? void 0 : showCheckoutParams.cryptoAmount
|
|
102
118
|
});
|
|
103
119
|
return this.wsEmbedInstance.showCheckout(showCheckoutParams);
|
|
104
120
|
}
|
|
121
|
+
async showReceive(showReceiveParams) {
|
|
122
|
+
var _this$wsEmbedInstance5, _this$analytics4;
|
|
123
|
+
if (!((_this$wsEmbedInstance5 = this.wsEmbedInstance) !== null && _this$wsEmbedInstance5 !== void 0 && _this$wsEmbedInstance5.isLoggedIn)) throw WalletServicesPluginError.walletPluginNotConnected();
|
|
124
|
+
|
|
125
|
+
// analytics
|
|
126
|
+
(_this$analytics4 = this.analytics) === null || _this$analytics4 === void 0 || _this$analytics4.track(ANALYTICS_EVENTS.WALLET_RECEIVE_CLICKED, {
|
|
127
|
+
is_visible: showReceiveParams === null || showReceiveParams === void 0 ? void 0 : showReceiveParams.show
|
|
128
|
+
});
|
|
129
|
+
return this.wsEmbedInstance.showReceive(showReceiveParams);
|
|
130
|
+
}
|
|
105
131
|
async showWalletUi(showWalletUiParams) {
|
|
106
|
-
var _this$
|
|
107
|
-
if (!((_this$
|
|
132
|
+
var _this$wsEmbedInstance6, _this$analytics5;
|
|
133
|
+
if (!((_this$wsEmbedInstance6 = this.wsEmbedInstance) !== null && _this$wsEmbedInstance6 !== void 0 && _this$wsEmbedInstance6.isLoggedIn)) throw WalletServicesPluginError.walletPluginNotConnected();
|
|
108
134
|
|
|
109
135
|
// analytics
|
|
110
|
-
(_this$
|
|
136
|
+
(_this$analytics5 = this.analytics) === null || _this$analytics5 === void 0 || _this$analytics5.track(ANALYTICS_EVENTS.WALLET_UI_CLICKED, {
|
|
111
137
|
is_visible: showWalletUiParams === null || showWalletUiParams === void 0 ? void 0 : showWalletUiParams.show,
|
|
112
138
|
path: showWalletUiParams === null || showWalletUiParams === void 0 ? void 0 : showWalletUiParams.path
|
|
113
139
|
});
|
|
114
140
|
return this.wsEmbedInstance.showWalletUi(showWalletUiParams);
|
|
115
141
|
}
|
|
116
142
|
async showSwap(showSwapParams) {
|
|
117
|
-
var _this$
|
|
118
|
-
if (!((_this$
|
|
143
|
+
var _this$wsEmbedInstance7, _this$analytics6;
|
|
144
|
+
if (!((_this$wsEmbedInstance7 = this.wsEmbedInstance) !== null && _this$wsEmbedInstance7 !== void 0 && _this$wsEmbedInstance7.isLoggedIn)) throw WalletServicesPluginError.walletPluginNotConnected();
|
|
119
145
|
|
|
120
146
|
// analytics
|
|
121
|
-
(_this$
|
|
147
|
+
(_this$analytics6 = this.analytics) === null || _this$analytics6 === void 0 || _this$analytics6.track(ANALYTICS_EVENTS.WALLET_SWAP_CLICKED, {
|
|
122
148
|
is_visible: showSwapParams === null || showSwapParams === void 0 ? void 0 : showSwapParams.show,
|
|
123
149
|
from_token: showSwapParams === null || showSwapParams === void 0 ? void 0 : showSwapParams.fromToken,
|
|
124
150
|
to_token: showSwapParams === null || showSwapParams === void 0 ? void 0 : showSwapParams.toToken,
|
|
@@ -128,13 +154,13 @@ class WalletServicesPlugin extends SafeEventEmitter {
|
|
|
128
154
|
return this.wsEmbedInstance.showSwap(showSwapParams);
|
|
129
155
|
}
|
|
130
156
|
async cleanup() {
|
|
131
|
-
var _this$
|
|
132
|
-
return (_this$
|
|
157
|
+
var _this$wsEmbedInstance8;
|
|
158
|
+
return (_this$wsEmbedInstance8 = this.wsEmbedInstance) === null || _this$wsEmbedInstance8 === void 0 ? void 0 : _this$wsEmbedInstance8.cleanUp();
|
|
133
159
|
}
|
|
134
160
|
async disconnect() {
|
|
135
|
-
var _this$
|
|
161
|
+
var _this$wsEmbedInstance9;
|
|
136
162
|
if (this.status !== PLUGIN_STATUS.CONNECTED) throw WalletServicesPluginError.invalidSession("Wallet Services plugin is not connected");
|
|
137
|
-
if ((_this$
|
|
163
|
+
if ((_this$wsEmbedInstance9 = this.wsEmbedInstance) !== null && _this$wsEmbedInstance9 !== void 0 && _this$wsEmbedInstance9.isLoggedIn) {
|
|
138
164
|
await this.wsEmbedInstance.logout();
|
|
139
165
|
}
|
|
140
166
|
this.emit(PLUGIN_EVENTS.DISCONNECTED);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useState, useCallback } from 'react';
|
|
2
|
+
import { useWalletServicesPlugin } from './useWalletServicesPlugin.js';
|
|
3
|
+
import { WalletServicesPluginError } from '../../base/plugin/errors.js';
|
|
4
|
+
|
|
5
|
+
const useFunding = () => {
|
|
6
|
+
const {
|
|
7
|
+
plugin,
|
|
8
|
+
ready
|
|
9
|
+
} = useWalletServicesPlugin();
|
|
10
|
+
const [loading, setLoading] = useState(false);
|
|
11
|
+
const [error, setError] = useState(null);
|
|
12
|
+
const showFunding = useCallback(async showFundingParams => {
|
|
13
|
+
setLoading(true);
|
|
14
|
+
setError(null);
|
|
15
|
+
try {
|
|
16
|
+
if (!plugin) throw WalletServicesPluginError.notInitialized();
|
|
17
|
+
if (!ready) throw WalletServicesPluginError.walletPluginNotConnected();
|
|
18
|
+
await plugin.showFunding(showFundingParams);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
setError(error);
|
|
21
|
+
} finally {
|
|
22
|
+
setLoading(false);
|
|
23
|
+
}
|
|
24
|
+
}, [plugin, ready]);
|
|
25
|
+
return {
|
|
26
|
+
loading,
|
|
27
|
+
error,
|
|
28
|
+
showFunding
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { useFunding };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useState, useCallback } from 'react';
|
|
2
|
+
import { useWalletServicesPlugin } from './useWalletServicesPlugin.js';
|
|
3
|
+
import { WalletServicesPluginError } from '../../base/plugin/errors.js';
|
|
4
|
+
|
|
5
|
+
const useReceive = () => {
|
|
6
|
+
const {
|
|
7
|
+
plugin,
|
|
8
|
+
ready
|
|
9
|
+
} = useWalletServicesPlugin();
|
|
10
|
+
const [loading, setLoading] = useState(false);
|
|
11
|
+
const [error, setError] = useState(null);
|
|
12
|
+
const showReceive = useCallback(async showReceiveParams => {
|
|
13
|
+
setLoading(true);
|
|
14
|
+
setError(null);
|
|
15
|
+
try {
|
|
16
|
+
if (!plugin) throw WalletServicesPluginError.notInitialized();
|
|
17
|
+
if (!ready) throw WalletServicesPluginError.walletPluginNotConnected();
|
|
18
|
+
await plugin.showReceive(showReceiveParams);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
setError(error);
|
|
21
|
+
} finally {
|
|
22
|
+
setLoading(false);
|
|
23
|
+
}
|
|
24
|
+
}, [plugin, ready]);
|
|
25
|
+
return {
|
|
26
|
+
loading,
|
|
27
|
+
error,
|
|
28
|
+
showReceive
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { useReceive };
|