@web3auth/modal 9.7.0 → 10.0.0-alpha.1

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.
Files changed (153) hide show
  1. package/dist/lib.cjs/node_modules/style-inject/dist/style-inject.es.js +28 -0
  2. package/dist/lib.cjs/{config.js → packages/modal/src/config.js} +17 -29
  3. package/dist/lib.cjs/{index.js → packages/modal/src/index.js} +7 -0
  4. package/dist/lib.cjs/packages/modal/src/modalManager.js +376 -0
  5. package/dist/lib.cjs/packages/modal/src/react/Web3AuthProvider.js +15 -0
  6. package/dist/lib.cjs/packages/modal/src/react/context/Web3AuthInnerContext.js +199 -0
  7. package/dist/lib.cjs/packages/modal/src/react/hooks/useWeb3Auth.js +15 -0
  8. package/dist/lib.cjs/packages/modal/src/react/index.js +12 -0
  9. package/dist/lib.cjs/packages/modal/src/ui/assets/arrow-left-dark.svg.js +7 -0
  10. package/dist/lib.cjs/packages/modal/src/ui/assets/arrow-left-light.svg.js +7 -0
  11. package/dist/lib.cjs/packages/modal/src/ui/assets/x-dark.svg.js +7 -0
  12. package/dist/lib.cjs/packages/modal/src/ui/assets/x-light.svg.js +7 -0
  13. package/dist/lib.cjs/packages/modal/src/ui/components/AdapterLoader.js +108 -0
  14. package/dist/lib.cjs/packages/modal/src/ui/components/Button/Button.js +34 -0
  15. package/dist/lib.cjs/packages/modal/src/ui/components/Button/styles.css.js +8 -0
  16. package/dist/lib.cjs/packages/modal/src/ui/components/ExternalWallet/ExternalWalletButton.js +44 -0
  17. package/dist/lib.cjs/packages/modal/src/ui/components/ExternalWallet/ExternalWalletConnect.js +67 -0
  18. package/dist/lib.cjs/packages/modal/src/ui/components/ExternalWallet/ExternalWalletDetails.js +34 -0
  19. package/dist/lib.cjs/packages/modal/src/ui/components/ExternalWallet/ExternalWalletHeader.js +46 -0
  20. package/dist/lib.cjs/packages/modal/src/ui/components/ExternalWallet/ExternalWalletInstall.js +167 -0
  21. package/dist/lib.cjs/packages/modal/src/ui/components/ExternalWallets.js +273 -0
  22. package/dist/lib.cjs/packages/modal/src/ui/components/Footer.js +20 -0
  23. package/dist/lib.cjs/packages/modal/src/ui/components/Header.js +81 -0
  24. package/dist/lib.cjs/packages/modal/src/ui/components/Icon.js +73 -0
  25. package/dist/lib.cjs/packages/modal/src/ui/components/Image.js +51 -0
  26. package/dist/lib.cjs/packages/modal/src/ui/components/Loader.js +59 -0
  27. package/dist/lib.cjs/packages/modal/src/ui/components/Modal.js +244 -0
  28. package/dist/lib.cjs/packages/modal/src/ui/components/SelfCustodyViaWeb3Auth.js +30 -0
  29. package/dist/lib.cjs/packages/modal/src/ui/components/SocialLoginPasswordless.js +141 -0
  30. package/dist/lib.cjs/packages/modal/src/ui/components/SocialLogins.js +148 -0
  31. package/dist/lib.cjs/packages/modal/src/ui/components/WalletConnect.js +84 -0
  32. package/dist/lib.cjs/packages/modal/src/ui/config.js +17 -0
  33. package/dist/lib.cjs/packages/modal/src/ui/context/ThemeContext.js +9 -0
  34. package/dist/lib.cjs/packages/modal/src/ui/css/web3auth.css.js +8 -0
  35. package/dist/lib.cjs/packages/modal/src/ui/i18n/dutch.json.js +84 -0
  36. package/dist/lib.cjs/packages/modal/src/ui/i18n/english.json.js +84 -0
  37. package/dist/lib.cjs/packages/modal/src/ui/i18n/french.json.js +82 -0
  38. package/dist/lib.cjs/packages/modal/src/ui/i18n/german.json.js +84 -0
  39. package/dist/lib.cjs/packages/modal/src/ui/i18n/japanese.json.js +84 -0
  40. package/dist/lib.cjs/packages/modal/src/ui/i18n/korean.json.js +84 -0
  41. package/dist/lib.cjs/packages/modal/src/ui/i18n/mandarin.json.js +84 -0
  42. package/dist/lib.cjs/packages/modal/src/ui/i18n/portuguese.json.js +84 -0
  43. package/dist/lib.cjs/packages/modal/src/ui/i18n/spanish.json.js +84 -0
  44. package/dist/lib.cjs/packages/modal/src/ui/i18n/turkish.json.js +84 -0
  45. package/dist/lib.cjs/packages/modal/src/ui/interfaces.js +26 -0
  46. package/dist/lib.cjs/packages/modal/src/ui/localeImport.js +25 -0
  47. package/dist/lib.cjs/packages/modal/src/ui/loginModal.js +309 -0
  48. package/dist/lib.cjs/packages/modal/src/ui/utils.js +71 -0
  49. package/dist/lib.cjs/packages/modal/src/vue/Web3AuthProvider.js +208 -0
  50. package/dist/lib.cjs/packages/modal/src/vue/composables/useWeb3Auth.js +12 -0
  51. package/dist/lib.cjs/packages/modal/src/vue/index.js +9 -0
  52. package/dist/lib.esm/node_modules/style-inject/dist/style-inject.es.js +26 -0
  53. package/dist/lib.esm/{config.js → packages/modal/src/config.js} +12 -24
  54. package/dist/lib.esm/{index.js → packages/modal/src/index.js} +1 -0
  55. package/dist/lib.esm/packages/modal/src/modalManager.js +374 -0
  56. package/dist/lib.esm/packages/modal/src/react/Web3AuthProvider.js +13 -0
  57. package/dist/lib.esm/packages/modal/src/react/context/Web3AuthInnerContext.js +196 -0
  58. package/dist/lib.esm/packages/modal/src/react/hooks/useWeb3Auth.js +13 -0
  59. package/dist/lib.esm/packages/modal/src/react/index.js +3 -0
  60. package/dist/lib.esm/packages/modal/src/ui/assets/arrow-left-dark.svg.js +5 -0
  61. package/dist/lib.esm/packages/modal/src/ui/assets/arrow-left-light.svg.js +5 -0
  62. package/dist/lib.esm/packages/modal/src/ui/assets/x-dark.svg.js +5 -0
  63. package/dist/lib.esm/packages/modal/src/ui/assets/x-light.svg.js +5 -0
  64. package/dist/lib.esm/packages/modal/src/ui/components/AdapterLoader.js +106 -0
  65. package/dist/lib.esm/packages/modal/src/ui/components/Button/Button.js +32 -0
  66. package/dist/lib.esm/packages/modal/src/ui/components/Button/styles.css.js +6 -0
  67. package/dist/lib.esm/packages/modal/src/ui/components/ExternalWallet/ExternalWalletButton.js +42 -0
  68. package/dist/lib.esm/packages/modal/src/ui/components/ExternalWallet/ExternalWalletConnect.js +65 -0
  69. package/dist/lib.esm/packages/modal/src/ui/components/ExternalWallet/ExternalWalletDetails.js +32 -0
  70. package/dist/lib.esm/packages/modal/src/ui/components/ExternalWallet/ExternalWalletHeader.js +44 -0
  71. package/dist/lib.esm/packages/modal/src/ui/components/ExternalWallet/ExternalWalletInstall.js +165 -0
  72. package/dist/lib.esm/packages/modal/src/ui/components/ExternalWallets.js +271 -0
  73. package/dist/lib.esm/packages/modal/src/ui/components/Footer.js +18 -0
  74. package/dist/lib.esm/packages/modal/src/ui/components/Header.js +79 -0
  75. package/dist/lib.esm/packages/modal/src/ui/components/Icon.js +71 -0
  76. package/dist/lib.esm/packages/modal/src/ui/components/Image.js +49 -0
  77. package/dist/lib.esm/packages/modal/src/ui/components/Loader.js +57 -0
  78. package/dist/lib.esm/packages/modal/src/ui/components/Modal.js +242 -0
  79. package/dist/lib.esm/packages/modal/src/ui/components/SelfCustodyViaWeb3Auth.js +28 -0
  80. package/dist/lib.esm/packages/modal/src/ui/components/SocialLoginPasswordless.js +139 -0
  81. package/dist/lib.esm/packages/modal/src/ui/components/SocialLogins.js +146 -0
  82. package/dist/lib.esm/packages/modal/src/ui/components/WalletConnect.js +82 -0
  83. package/dist/lib.esm/packages/modal/src/ui/config.js +13 -0
  84. package/dist/lib.esm/packages/modal/src/ui/context/ThemeContext.js +7 -0
  85. package/dist/lib.esm/packages/modal/src/ui/css/web3auth.css.js +6 -0
  86. package/dist/lib.esm/packages/modal/src/ui/i18n/dutch.json.js +79 -0
  87. package/dist/lib.esm/packages/modal/src/ui/i18n/english.json.js +79 -0
  88. package/dist/lib.esm/packages/modal/src/ui/i18n/french.json.js +77 -0
  89. package/dist/lib.esm/packages/modal/src/ui/i18n/german.json.js +79 -0
  90. package/dist/lib.esm/packages/modal/src/ui/i18n/japanese.json.js +79 -0
  91. package/dist/lib.esm/packages/modal/src/ui/i18n/korean.json.js +79 -0
  92. package/dist/lib.esm/packages/modal/src/ui/i18n/mandarin.json.js +79 -0
  93. package/dist/lib.esm/packages/modal/src/ui/i18n/portuguese.json.js +79 -0
  94. package/dist/lib.esm/packages/modal/src/ui/i18n/spanish.json.js +79 -0
  95. package/dist/lib.esm/packages/modal/src/ui/i18n/turkish.json.js +79 -0
  96. package/dist/lib.esm/packages/modal/src/ui/interfaces.js +20 -0
  97. package/dist/lib.esm/packages/modal/src/ui/localeImport.js +23 -0
  98. package/dist/lib.esm/packages/modal/src/ui/loginModal.js +307 -0
  99. package/dist/lib.esm/packages/modal/src/ui/utils.js +65 -0
  100. package/dist/lib.esm/packages/modal/src/vue/Web3AuthProvider.js +206 -0
  101. package/dist/lib.esm/packages/modal/src/vue/composables/useWeb3Auth.js +10 -0
  102. package/dist/lib.esm/packages/modal/src/vue/index.js +2 -0
  103. package/dist/modal.cjs.js +5676 -470
  104. package/dist/modal.umd.min.js +1 -1
  105. package/dist/modal.umd.min.js.LICENSE.txt +45 -0
  106. package/dist/types/config.d.ts +6 -6
  107. package/dist/types/index.d.ts +1 -0
  108. package/dist/types/interface.d.ts +5 -5
  109. package/dist/types/modalManager.d.ts +11 -12
  110. package/dist/types/react/Web3AuthProvider.d.ts +3 -0
  111. package/dist/types/react/context/Web3AuthInnerContext.d.ts +4 -0
  112. package/dist/types/react/context/index.d.ts +1 -0
  113. package/dist/types/react/hooks/index.d.ts +1 -0
  114. package/dist/types/react/hooks/useWeb3Auth.d.ts +2 -0
  115. package/dist/types/react/index.d.ts +4 -0
  116. package/dist/types/react/interfaces.d.ts +18 -0
  117. package/dist/types/ui/components/AdapterLoader.d.ts +11 -0
  118. package/dist/types/ui/components/Button/Button.d.ts +16 -0
  119. package/dist/types/ui/components/Button/index.d.ts +1 -0
  120. package/dist/types/ui/components/ExternalWallet/ExternalWalletButton.d.ts +7 -0
  121. package/dist/types/ui/components/ExternalWallet/ExternalWalletConnect.d.ts +9 -0
  122. package/dist/types/ui/components/ExternalWallet/ExternalWalletDetails.d.ts +9 -0
  123. package/dist/types/ui/components/ExternalWallet/ExternalWalletHeader.d.ts +8 -0
  124. package/dist/types/ui/components/ExternalWallet/ExternalWalletInstall.d.ts +8 -0
  125. package/dist/types/ui/components/ExternalWallets.d.ts +17 -0
  126. package/dist/types/ui/components/Footer.d.ts +1 -0
  127. package/dist/types/ui/components/Header.d.ts +8 -0
  128. package/dist/types/ui/components/Icon.d.ts +9 -0
  129. package/dist/types/ui/components/Image.d.ts +12 -0
  130. package/dist/types/ui/components/Loader.d.ts +10 -0
  131. package/dist/types/ui/components/Modal.d.ts +16 -0
  132. package/dist/types/ui/components/SelfCustodyViaWeb3Auth.d.ts +1 -0
  133. package/dist/types/ui/components/SocialLoginPasswordless.d.ts +16 -0
  134. package/dist/types/ui/components/SocialLogins.d.ts +14 -0
  135. package/dist/types/ui/components/WalletConnect.d.ts +8 -0
  136. package/dist/types/ui/config.d.ts +4 -0
  137. package/dist/types/ui/context/ThemeContext.d.ts +3 -0
  138. package/dist/types/ui/helper/countryData.d.ts +7 -0
  139. package/dist/types/ui/i18n/index.d.ts +11 -0
  140. package/dist/types/ui/index.d.ts +4 -0
  141. package/dist/types/ui/interfaces.d.ts +102 -0
  142. package/dist/types/ui/localeImport.d.ts +3 -0
  143. package/dist/types/ui/loginModal.d.ts +27 -0
  144. package/dist/types/ui/utils.d.ts +12 -0
  145. package/dist/types/vue/Web3AuthProvider.d.ts +13 -0
  146. package/dist/types/vue/composables/index.d.ts +1 -0
  147. package/dist/types/vue/composables/useWeb3Auth.d.ts +2 -0
  148. package/dist/types/vue/index.d.ts +3 -0
  149. package/dist/types/vue/interfaces.d.ts +42 -0
  150. package/package.json +100 -43
  151. package/dist/lib.cjs/modalManager.js +0 -441
  152. package/dist/lib.esm/modalManager.js +0 -439
  153. package/dist/modal.esm.js +0 -513
@@ -0,0 +1,309 @@
1
+ 'use strict';
2
+
3
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
+ require('./css/web3auth.css.js');
5
+ var auth = require('@web3auth/auth');
6
+ var noModal = require('@web3auth/no-modal');
7
+ var client = require('react-dom/client');
8
+ var Modal = require('./components/Modal.js');
9
+ var ThemeContext = require('./context/ThemeContext.js');
10
+ var interfaces = require('./interfaces.js');
11
+ var localeImport = require('./localeImport.js');
12
+ var utils = require('./utils.js');
13
+ var jsxRuntime = require('react/jsx-runtime');
14
+
15
+ function createWrapper(parentZIndex) {
16
+ const existingWrapper = document.getElementById("w3a-parent-container");
17
+ if (existingWrapper) existingWrapper.remove();
18
+ const parent = document.createElement("section");
19
+ parent.classList.add("w3a-parent-container");
20
+ parent.setAttribute("id", "w3a-parent-container");
21
+ parent.style.zIndex = parentZIndex;
22
+ parent.style.position = "relative";
23
+ const wrapper = document.createElement("section");
24
+ wrapper.setAttribute("id", "w3a-container");
25
+ parent.appendChild(wrapper);
26
+ document.body.appendChild(parent);
27
+ return wrapper;
28
+ }
29
+ class LoginModal extends auth.SafeEventEmitter {
30
+ constructor(_uiConfig) {
31
+ super();
32
+ _defineProperty(this, "uiConfig", void 0);
33
+ _defineProperty(this, "stateEmitter", void 0);
34
+ _defineProperty(this, "chainNamespace", void 0);
35
+ _defineProperty(this, "walletRegistry", void 0);
36
+ _defineProperty(this, "initModal", async () => {
37
+ const darkState = {
38
+ isDark: this.isDark
39
+ };
40
+ const useLang = this.uiConfig.defaultLanguage || auth.LANGUAGES.en;
41
+
42
+ // Load new language resource
43
+
44
+ if (useLang === auth.LANGUAGES.de) {
45
+ Promise.resolve().then(function () { return require('./i18n/german.json.js'); }).then(messages => {
46
+ localeImport.addResourceBundle(useLang, "translation", messages.default);
47
+ return localeImport.changeLanguage(useLang);
48
+ }).catch(error => {
49
+ noModal.log.error(error);
50
+ });
51
+ } else if (useLang === auth.LANGUAGES.ja) {
52
+ Promise.resolve().then(function () { return require('./i18n/japanese.json.js'); }).then(messages => {
53
+ localeImport.addResourceBundle(useLang, "translation", messages.default);
54
+ return localeImport.changeLanguage(useLang);
55
+ }).catch(error => {
56
+ noModal.log.error(error);
57
+ });
58
+ } else if (useLang === auth.LANGUAGES.ko) {
59
+ Promise.resolve().then(function () { return require('./i18n/korean.json.js'); }).then(messages => {
60
+ localeImport.addResourceBundle(useLang, "translation", messages.default);
61
+ return localeImport.changeLanguage(useLang);
62
+ }).catch(error => {
63
+ noModal.log.error(error);
64
+ });
65
+ } else if (useLang === auth.LANGUAGES.zh) {
66
+ Promise.resolve().then(function () { return require('./i18n/mandarin.json.js'); }).then(messages => {
67
+ localeImport.addResourceBundle(useLang, "translation", messages.default);
68
+ return localeImport.changeLanguage(useLang);
69
+ }).catch(error => {
70
+ noModal.log.error(error);
71
+ });
72
+ } else if (useLang === auth.LANGUAGES.es) {
73
+ Promise.resolve().then(function () { return require('./i18n/spanish.json.js'); }).then(messages => {
74
+ localeImport.addResourceBundle(useLang, "translation", messages.default);
75
+ return localeImport.changeLanguage(useLang);
76
+ }).catch(error => {
77
+ noModal.log.error(error);
78
+ });
79
+ } else if (useLang === auth.LANGUAGES.fr) {
80
+ Promise.resolve().then(function () { return require('./i18n/french.json.js'); }).then(messages => {
81
+ localeImport.addResourceBundle(useLang, "translation", messages.default);
82
+ return localeImport.changeLanguage(useLang);
83
+ }).catch(error => {
84
+ noModal.log.error(error);
85
+ });
86
+ } else if (useLang === auth.LANGUAGES.pt) {
87
+ Promise.resolve().then(function () { return require('./i18n/portuguese.json.js'); }).then(messages => {
88
+ localeImport.addResourceBundle(useLang, "translation", messages.default);
89
+ return localeImport.changeLanguage(useLang);
90
+ }).catch(error => {
91
+ noModal.log.error(error);
92
+ });
93
+ } else if (useLang === auth.LANGUAGES.nl) {
94
+ Promise.resolve().then(function () { return require('./i18n/dutch.json.js'); }).then(messages => {
95
+ localeImport.addResourceBundle(useLang, "translation", messages.default);
96
+ return localeImport.changeLanguage(useLang);
97
+ }).catch(error => {
98
+ noModal.log.error(error);
99
+ });
100
+ } else if (useLang === auth.LANGUAGES.tr) {
101
+ Promise.resolve().then(function () { return require('./i18n/turkish.json.js'); }).then(messages => {
102
+ localeImport.addResourceBundle(useLang, "translation", messages.default);
103
+ return localeImport.changeLanguage(useLang);
104
+ }).catch(error => {
105
+ noModal.log.error(error);
106
+ });
107
+ } else if (useLang === auth.LANGUAGES.en) {
108
+ Promise.resolve().then(function () { return require('./i18n/english.json.js'); }).then(messages => {
109
+ localeImport.addResourceBundle(useLang, "translation", messages.default);
110
+ return localeImport.changeLanguage(useLang);
111
+ }).catch(error => {
112
+ noModal.log.error(error);
113
+ });
114
+ }
115
+ return new Promise(resolve => {
116
+ var _this$uiConfig;
117
+ this.stateEmitter.once("MOUNTED", () => {
118
+ noModal.log.info("rendered");
119
+ this.setState({
120
+ status: interfaces.MODAL_STATUS.INITIALIZED
121
+ });
122
+ return resolve();
123
+ });
124
+ const container = createWrapper(this.uiConfig.modalZIndex);
125
+ if (darkState.isDark) {
126
+ container.classList.add("w3a--dark");
127
+ } else {
128
+ container.classList.remove("w3a--dark");
129
+ }
130
+ const root = client.createRoot(container);
131
+ root.render(/*#__PURE__*/jsxRuntime.jsx(ThemeContext.ThemedContext.Provider, {
132
+ value: darkState,
133
+ children: /*#__PURE__*/jsxRuntime.jsx(Modal, {
134
+ closeModal: this.closeModal,
135
+ stateListener: this.stateEmitter,
136
+ handleShowExternalWallets: this.handleShowExternalWallets,
137
+ handleExternalWalletClick: this.handleExternalWalletClick,
138
+ handleSocialLoginClick: this.handleSocialLoginClick,
139
+ appLogo: darkState.isDark ? this.uiConfig.logoDark : this.uiConfig.logoLight,
140
+ appName: this.uiConfig.appName,
141
+ chainNamespace: this.chainNamespace,
142
+ walletRegistry: this.walletRegistry
143
+ })
144
+ }));
145
+ if ((_this$uiConfig = this.uiConfig) !== null && _this$uiConfig !== void 0 && _this$uiConfig.theme) {
146
+ const rootElement = document.getElementById("w3a-parent-container");
147
+ auth.applyWhiteLabelTheme(rootElement, this.uiConfig.theme);
148
+ }
149
+ });
150
+ });
151
+ _defineProperty(this, "addSocialLogins", (connector, loginMethods, loginMethodsOrder, uiConfig) => {
152
+ this.setState({
153
+ socialLoginsConfig: {
154
+ connector,
155
+ loginMethods,
156
+ loginMethodsOrder,
157
+ uiConfig
158
+ }
159
+ });
160
+ noModal.log.info("addSocialLogins", connector, loginMethods, loginMethodsOrder, uiConfig);
161
+ });
162
+ _defineProperty(this, "addWalletLogins", (externalWalletsConfig, options) => {
163
+ this.setState({
164
+ externalWalletsConfig,
165
+ externalWalletsInitialized: true,
166
+ showExternalWalletsOnly: !!(options !== null && options !== void 0 && options.showExternalWalletsOnly),
167
+ externalWalletsVisibility: true
168
+ });
169
+ });
170
+ _defineProperty(this, "open", () => {
171
+ this.setState({
172
+ modalVisibility: true
173
+ });
174
+ this.emit(interfaces.LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, true);
175
+ });
176
+ _defineProperty(this, "closeModal", () => {
177
+ this.setState({
178
+ modalVisibility: false,
179
+ externalWalletsVisibility: false
180
+ });
181
+ this.emit(interfaces.LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, false);
182
+ });
183
+ _defineProperty(this, "initExternalWalletContainer", () => {
184
+ this.setState({
185
+ hasExternalWallets: true
186
+ });
187
+ });
188
+ _defineProperty(this, "handleShowExternalWallets", status => {
189
+ this.emit(interfaces.LOGIN_MODAL_EVENTS.INIT_EXTERNAL_WALLETS, {
190
+ externalWalletsInitialized: status
191
+ });
192
+ });
193
+ _defineProperty(this, "handleExternalWalletClick", params => {
194
+ noModal.log.info("external wallet clicked", params);
195
+ const {
196
+ connector
197
+ } = params;
198
+ this.emit(interfaces.LOGIN_MODAL_EVENTS.LOGIN, {
199
+ connector
200
+ });
201
+ });
202
+ _defineProperty(this, "handleSocialLoginClick", params => {
203
+ noModal.log.info("social login clicked", params);
204
+ const {
205
+ connector,
206
+ loginParams
207
+ } = params;
208
+ this.emit(interfaces.LOGIN_MODAL_EVENTS.LOGIN, {
209
+ connector,
210
+ loginParams: {
211
+ loginProvider: loginParams.loginProvider,
212
+ login_hint: loginParams.login_hint,
213
+ name: loginParams.name
214
+ }
215
+ });
216
+ });
217
+ _defineProperty(this, "setState", newState => {
218
+ this.stateEmitter.emit("STATE_UPDATED", newState);
219
+ });
220
+ _defineProperty(this, "updateWalletConnect", walletConnectUri => {
221
+ if (!walletConnectUri) return;
222
+ this.setState({
223
+ walletConnectUri
224
+ });
225
+ });
226
+ _defineProperty(this, "handleConnectorData", connectorData => {
227
+ if (connectorData.connectorName === noModal.WALLET_CONNECTORS.WALLET_CONNECT_V2) {
228
+ const walletConnectData = connectorData.data;
229
+ this.updateWalletConnect(walletConnectData.uri);
230
+ }
231
+ });
232
+ _defineProperty(this, "subscribeCoreEvents", listener => {
233
+ listener.on(noModal.CONNECTOR_EVENTS.CONNECTING, data => {
234
+ noModal.log.info("connecting with connector", data);
235
+ // don't show loader in case of wallet connect, because currently it listens for incoming for incoming
236
+ // connections without any user interaction.
237
+ if ((data === null || data === void 0 ? void 0 : data.connector) !== noModal.WALLET_CONNECTORS.WALLET_CONNECT_V2) {
238
+ // const provider = data?.loginProvider || "";
239
+
240
+ this.setState({
241
+ status: interfaces.MODAL_STATUS.CONNECTING
242
+ });
243
+ }
244
+ });
245
+ listener.on(noModal.CONNECTOR_EVENTS.CONNECTED, data => {
246
+ noModal.log.debug("connected with connector", data);
247
+ // only show success if not being reconnected again.
248
+ if (!data.reconnected) {
249
+ this.setState({
250
+ status: interfaces.MODAL_STATUS.CONNECTED,
251
+ modalVisibility: true,
252
+ postLoadingMessage: "modal.post-loading.connected"
253
+ });
254
+ } else {
255
+ this.setState({
256
+ status: interfaces.MODAL_STATUS.CONNECTED
257
+ });
258
+ }
259
+ });
260
+ // TODO: send connector name in error
261
+ listener.on(noModal.CONNECTOR_EVENTS.ERRORED, error => {
262
+ noModal.log.error("error", error, error.message);
263
+ if (error.code === 5000) {
264
+ if (this.uiConfig.displayErrorsOnModal) this.setState({
265
+ modalVisibility: true,
266
+ postLoadingMessage: error.message || "modal.post-loading.something-wrong",
267
+ status: interfaces.MODAL_STATUS.ERRORED
268
+ });else this.setState({
269
+ modalVisibility: false
270
+ });
271
+ } else {
272
+ this.setState({
273
+ modalVisibility: true,
274
+ status: interfaces.MODAL_STATUS.INITIALIZED
275
+ });
276
+ }
277
+ });
278
+ listener.on(noModal.CONNECTOR_EVENTS.DISCONNECTED, () => {
279
+ this.setState({
280
+ status: interfaces.MODAL_STATUS.INITIALIZED,
281
+ externalWalletsVisibility: false
282
+ });
283
+ // this.toggleMessage("");
284
+ });
285
+ listener.on(noModal.CONNECTOR_EVENTS.CONNECTOR_DATA_UPDATED, connectorData => {
286
+ this.handleConnectorData(connectorData);
287
+ });
288
+ });
289
+ this.uiConfig = _uiConfig;
290
+ if (!_uiConfig.logoDark) this.uiConfig.logoDark = interfaces.DEFAULT_LOGO_DARK;
291
+ if (!_uiConfig.logoLight) this.uiConfig.logoLight = interfaces.DEFAULT_LOGO_LIGHT;
292
+ if (!_uiConfig.mode) this.uiConfig.mode = "light";
293
+ if (!_uiConfig.modalZIndex) this.uiConfig.modalZIndex = "99998";
294
+ if (typeof _uiConfig.displayErrorsOnModal === "undefined") this.uiConfig.displayErrorsOnModal = true;
295
+ if (!_uiConfig.appName) this.uiConfig.appName = "Web3Auth";
296
+ if (!_uiConfig.loginGridCol) this.uiConfig.loginGridCol = 3;
297
+ if (!_uiConfig.primaryButton) this.uiConfig.primaryButton = "socialLogin";
298
+ if (!_uiConfig.defaultLanguage) this.uiConfig.defaultLanguage = utils.getUserLanguage(_uiConfig.defaultLanguage);
299
+ this.stateEmitter = new auth.SafeEventEmitter();
300
+ this.chainNamespace = _uiConfig.chainNamespace;
301
+ this.walletRegistry = _uiConfig.walletRegistry;
302
+ this.subscribeCoreEvents(this.uiConfig.connectorListener);
303
+ }
304
+ get isDark() {
305
+ return this.uiConfig.mode === "dark" || this.uiConfig.mode === "auto" && window.matchMedia("(prefers-color-scheme: dark)").matches;
306
+ }
307
+ }
308
+
309
+ exports.LoginModal = LoginModal;
@@ -0,0 +1,71 @@
1
+ 'use strict';
2
+
3
+ var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
+ var httpHelpers = require('@toruslabs/http-helpers');
5
+ var auth = require('@web3auth/auth');
6
+ var noModal = require('@web3auth/no-modal');
7
+ var config = require('./config.js');
8
+
9
+ const getConnectorSocialLogins = (connectorName, loginMethodsConfig = {}) => {
10
+ const finalLoginMethodsConfig = {};
11
+ if (connectorName === noModal.WALLET_CONNECTORS.AUTH) {
12
+ config.AUTH_PROVIDERS.forEach(loginMethod => {
13
+ const currentLoginMethodConfig = loginMethodsConfig[loginMethod] || {
14
+ name: config.AUTH_PROVIDERS_NAMES[loginMethod],
15
+ showOnMobile: true,
16
+ showOnModal: true,
17
+ showOnDesktop: true
18
+ };
19
+ finalLoginMethodsConfig[loginMethod] = _objectSpread({}, currentLoginMethodConfig);
20
+ });
21
+ noModal.log.debug("auth login method ui config", finalLoginMethodsConfig);
22
+ } else {
23
+ throw noModal.WalletInitializationError.invalidParams(`${connectorName} is not a valid connector`);
24
+ }
25
+ return finalLoginMethodsConfig;
26
+ };
27
+ const passwordlessBackendUrl = "https://api-passwordless.web3auth.io";
28
+ const getUserCountry = async () => {
29
+ try {
30
+ const result = await httpHelpers.get(`${passwordlessBackendUrl}/api/v3/user/location`);
31
+ if (result && result.data.country) return {
32
+ country: result.data.country,
33
+ dialCode: result.data.dial_code
34
+ };
35
+ return null;
36
+ } catch (error) {
37
+ noModal.log.error("error getting user country", error);
38
+ return null;
39
+ }
40
+ };
41
+ const validatePhoneNumber = async phoneNumber => {
42
+ try {
43
+ const result = await httpHelpers.post(`${passwordlessBackendUrl}/api/v3/phone_number/validate`, {
44
+ phone_number: phoneNumber
45
+ });
46
+ if (result && result.success) return result.parsed_number;
47
+ return false;
48
+ } catch (error) {
49
+ noModal.log.error("error validating phone number", error);
50
+ if (error.status === 400) {
51
+ return false;
52
+ }
53
+ // sending true because we don't want the user to be stuck on a flow
54
+ // if there is an error with the api or something went wrong.
55
+ return true;
56
+ }
57
+ };
58
+ const getUserLanguage = defaultLanguage => {
59
+ let userLanguage = defaultLanguage;
60
+ if (!userLanguage) {
61
+ const browserLanguage = typeof window !== "undefined" ? window.navigator.userLanguage || window.navigator.language || "en-US" : "en-US";
62
+ userLanguage = browserLanguage.split("-")[0];
63
+ }
64
+ return Object.prototype.hasOwnProperty.call(auth.LANGUAGE_MAP, userLanguage) ? userLanguage : auth.LANGUAGES.en;
65
+ };
66
+
67
+ exports.getConnectorSocialLogins = getConnectorSocialLogins;
68
+ exports.getUserCountry = getUserCountry;
69
+ exports.getUserLanguage = getUserLanguage;
70
+ exports.passwordlessBackendUrl = passwordlessBackendUrl;
71
+ exports.validatePhoneNumber = validatePhoneNumber;
@@ -0,0 +1,208 @@
1
+ 'use strict';
2
+
3
+ var noModal = require('@web3auth/no-modal');
4
+ var vue = require('vue');
5
+ var modalManager = require('../modalManager.js');
6
+
7
+ const Web3AuthProvider = vue.defineComponent({
8
+ name: "Web3AuthProvider",
9
+ props: {
10
+ config: {
11
+ type: Object,
12
+ required: true
13
+ }
14
+ },
15
+ setup(props) {
16
+ const web3Auth = vue.shallowRef(null);
17
+ const provider = vue.ref(null);
18
+ const userInfo = vue.ref(null);
19
+ const isMFAEnabled = vue.ref(false);
20
+ const status = vue.ref(null);
21
+ const isInitializing = vue.ref(false);
22
+ const initError = vue.ref(null);
23
+ const isInitialized = vue.ref(false);
24
+ const isConnecting = vue.ref(false);
25
+ const connectError = vue.ref(null);
26
+ const isConnected = vue.ref(false);
27
+ const getPlugin = name => {
28
+ if (!web3Auth.value) throw noModal.WalletInitializationError.notReady();
29
+ return web3Auth.value.getPlugin(name);
30
+ };
31
+ const enableMFA = async loginParams => {
32
+ if (!web3Auth.value) throw noModal.WalletInitializationError.notReady();
33
+ if (!isConnected.value) throw noModal.WalletLoginError.notConnectedError();
34
+ await web3Auth.value.enableMFA(loginParams);
35
+ const localUserInfo = await web3Auth.value.getUserInfo();
36
+ userInfo.value = localUserInfo;
37
+ isMFAEnabled.value = localUserInfo.isMfaEnabled || false;
38
+ };
39
+ const manageMFA = async loginParams => {
40
+ if (!web3Auth.value) throw noModal.WalletInitializationError.notReady();
41
+ if (!isConnected.value) throw noModal.WalletLoginError.notConnectedError();
42
+ await web3Auth.value.manageMFA(loginParams);
43
+ };
44
+ const logout = async (logoutParams = {
45
+ cleanup: false
46
+ }) => {
47
+ if (!web3Auth.value) throw noModal.WalletInitializationError.notReady();
48
+ if (!isConnected.value) throw noModal.WalletLoginError.notConnectedError();
49
+ await web3Auth.value.logout(logoutParams);
50
+ };
51
+ const connect = async () => {
52
+ if (!web3Auth.value) throw noModal.WalletInitializationError.notReady();
53
+ try {
54
+ connectError.value = null;
55
+ isConnecting.value = true;
56
+ const localProvider = await web3Auth.value.connect();
57
+ return localProvider;
58
+ } catch (error) {
59
+ connectError.value = error;
60
+ return null;
61
+ } finally {
62
+ isConnecting.value = false;
63
+ }
64
+ };
65
+ const authenticateUser = async () => {
66
+ if (!web3Auth.value) throw noModal.WalletInitializationError.notReady();
67
+ return web3Auth.value.authenticateUser();
68
+ };
69
+ const switchChain = chainParams => {
70
+ if (!web3Auth.value) throw noModal.WalletInitializationError.notReady();
71
+ return web3Auth.value.switchChain(chainParams);
72
+ };
73
+ vue.watch(() => props.config, newConfig => {
74
+ const resetHookState = () => {
75
+ provider.value = null;
76
+ userInfo.value = null;
77
+ isMFAEnabled.value = false;
78
+ isConnected.value = false;
79
+ status.value = null;
80
+ };
81
+ resetHookState();
82
+ const {
83
+ web3AuthOptions
84
+ } = newConfig;
85
+ const web3AuthInstance = new modalManager.Web3Auth(web3AuthOptions);
86
+ web3Auth.value = web3AuthInstance;
87
+ }, {
88
+ immediate: true
89
+ });
90
+ vue.watch(web3Auth, async newWeb3Auth => {
91
+ if (newWeb3Auth) {
92
+ try {
93
+ initError.value = null;
94
+ isInitializing.value = true;
95
+ const {
96
+ modalConfig,
97
+ hideWalletDiscovery
98
+ } = props.config;
99
+ if (modalConfig) {
100
+ await newWeb3Auth.initModal({
101
+ modalConfig,
102
+ hideWalletDiscovery
103
+ });
104
+ } else {
105
+ await newWeb3Auth.initModal();
106
+ }
107
+ } catch (error) {
108
+ initError.value = error;
109
+ } finally {
110
+ isInitializing.value = false;
111
+ }
112
+ }
113
+ }, {
114
+ immediate: true
115
+ });
116
+ vue.watch(isConnected, newIsConnected => {
117
+ if (web3Auth.value) {
118
+ const addState = async web3AuthInstance => {
119
+ provider.value = web3AuthInstance.provider;
120
+ const userState = await web3AuthInstance.getUserInfo();
121
+ userInfo.value = userState;
122
+ isMFAEnabled.value = (userState === null || userState === void 0 ? void 0 : userState.isMfaEnabled) || false;
123
+ };
124
+ const resetState = () => {
125
+ provider.value = null;
126
+ userInfo.value = null;
127
+ isMFAEnabled.value = false;
128
+ };
129
+ if (newIsConnected) addState(web3Auth.value);else resetState();
130
+ }
131
+ });
132
+ vue.watch(web3Auth, (newWeb3Auth, prevWeb3Auth) => {
133
+ const notReadyListener = () => {
134
+ status.value = web3Auth.value.status;
135
+ };
136
+ const readyListener = () => {
137
+ status.value = web3Auth.value.status;
138
+ isInitialized.value = true;
139
+ };
140
+ const connectedListener = () => {
141
+ status.value = web3Auth.value.status;
142
+ // we do this because of rehydration issues. status connected is fired first but web3auth sdk is not ready yet.
143
+ if (web3Auth.value.status === noModal.CONNECTOR_STATUS.CONNECTED) {
144
+ isInitialized.value = true;
145
+ isConnected.value = true;
146
+ }
147
+ };
148
+ const disconnectedListener = () => {
149
+ status.value = web3Auth.value.status;
150
+ isConnected.value = false;
151
+ };
152
+ const connectingListener = () => {
153
+ status.value = web3Auth.value.status;
154
+ };
155
+ const errorListener = () => {
156
+ status.value = noModal.CONNECTOR_EVENTS.ERRORED;
157
+ };
158
+
159
+ // unregister previous listeners
160
+ if (prevWeb3Auth && newWeb3Auth !== prevWeb3Auth) {
161
+ prevWeb3Auth.off(noModal.CONNECTOR_EVENTS.NOT_READY, notReadyListener);
162
+ prevWeb3Auth.off(noModal.CONNECTOR_EVENTS.READY, readyListener);
163
+ prevWeb3Auth.off(noModal.CONNECTOR_EVENTS.CONNECTED, connectedListener);
164
+ prevWeb3Auth.off(noModal.CONNECTOR_EVENTS.DISCONNECTED, disconnectedListener);
165
+ prevWeb3Auth.off(noModal.CONNECTOR_EVENTS.CONNECTING, connectingListener);
166
+ prevWeb3Auth.off(noModal.CONNECTOR_EVENTS.ERRORED, errorListener);
167
+ }
168
+ if (newWeb3Auth && newWeb3Auth !== prevWeb3Auth) {
169
+ status.value = newWeb3Auth.status;
170
+ // web3Auth is initialized here.
171
+ newWeb3Auth.on(noModal.CONNECTOR_EVENTS.NOT_READY, notReadyListener);
172
+ newWeb3Auth.on(noModal.CONNECTOR_EVENTS.READY, readyListener);
173
+ newWeb3Auth.on(noModal.CONNECTOR_EVENTS.CONNECTED, connectedListener);
174
+ newWeb3Auth.on(noModal.CONNECTOR_EVENTS.DISCONNECTED, disconnectedListener);
175
+ newWeb3Auth.on(noModal.CONNECTOR_EVENTS.CONNECTING, connectingListener);
176
+ newWeb3Auth.on(noModal.CONNECTOR_EVENTS.ERRORED, errorListener);
177
+ }
178
+ }, {
179
+ immediate: true
180
+ });
181
+ vue.provide(noModal.Web3AuthContextKey, {
182
+ web3Auth,
183
+ isConnected,
184
+ isInitialized,
185
+ provider,
186
+ userInfo,
187
+ isMFAEnabled,
188
+ status,
189
+ getPlugin,
190
+ connect,
191
+ enableMFA,
192
+ manageMFA,
193
+ logout,
194
+ authenticateUser,
195
+ switchChain,
196
+ isInitializing,
197
+ isConnecting,
198
+ initError,
199
+ connectError
200
+ });
201
+ },
202
+ render() {
203
+ var _this$$slots$default;
204
+ return vue.h((_this$$slots$default = this.$slots.default) !== null && _this$$slots$default !== void 0 ? _this$$slots$default : "");
205
+ }
206
+ });
207
+
208
+ exports.Web3AuthProvider = Web3AuthProvider;
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ var noModal = require('@web3auth/no-modal');
4
+ var vue = require('vue');
5
+
6
+ const useWeb3Auth = () => {
7
+ const context = vue.inject(noModal.Web3AuthContextKey);
8
+ if (!context) throw noModal.WalletInitializationError.fromCode(1000, "usage of `useWeb3Auth` not wrapped in `Web3AuthProvider`.");
9
+ return context;
10
+ };
11
+
12
+ exports.useWeb3Auth = useWeb3Auth;
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ var useWeb3Auth = require('./composables/useWeb3Auth.js');
4
+ var Web3AuthProvider = require('./Web3AuthProvider.js');
5
+
6
+
7
+
8
+ exports.useWeb3Auth = useWeb3Auth.useWeb3Auth;
9
+ exports.Web3AuthProvider = Web3AuthProvider.Web3AuthProvider;
@@ -0,0 +1,26 @@
1
+ function styleInject(css, ref) {
2
+ if (ref === void 0) ref = {};
3
+ var insertAt = ref.insertAt;
4
+ if (!css || typeof document === 'undefined') {
5
+ return;
6
+ }
7
+ var head = document.head || document.getElementsByTagName('head')[0];
8
+ var style = document.createElement('style');
9
+ style.type = 'text/css';
10
+ if (insertAt === 'top') {
11
+ if (head.firstChild) {
12
+ head.insertBefore(style, head.firstChild);
13
+ } else {
14
+ head.appendChild(style);
15
+ }
16
+ } else {
17
+ head.appendChild(style);
18
+ }
19
+ if (style.styleSheet) {
20
+ style.styleSheet.cssText = css;
21
+ } else {
22
+ style.appendChild(document.createTextNode(css));
23
+ }
24
+ }
25
+
26
+ export { styleInject as default };