Skip to content

Commit 0397e77

Browse files
committed
refactored code
1 parent 852ceb0 commit 0397e77

File tree

22 files changed

+588
-382
lines changed

22 files changed

+588
-382
lines changed

demo/vue-app-new/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/modal/src/ui/components/Body/Body.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type SafeEventEmitter } from "@web3auth/auth";
2-
import { ChainNamespaceType, log, WALLET_ADAPTERS, WalletRegistry, WalletRegistryItem } from "@web3auth/no-modal";
2+
import { ChainNamespaceType, WALLET_ADAPTERS, WalletRegistry, WalletRegistryItem } from "@web3auth/no-modal";
33
import Bowser from "bowser";
44
import { createMemo, createSignal, Match, Show, Suspense, Switch, useContext } from "solid-js";
55
import { createStore } from "solid-js/store";
@@ -214,8 +214,6 @@ const Body = (props: BodyProps) => {
214214

215215
canShowMap[adapter] = false;
216216
});
217-
218-
log.debug("adapter visibility map", canShowMap);
219217
return canShowMap;
220218
});
221219

packages/modal/src/ui/components/Body/ConnectWallet.tsx

Lines changed: 47 additions & 254 deletions
Large diffs are not rendered by default.

packages/modal/src/ui/components/Body/Login.tsx

Lines changed: 27 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { SocialLoginsConfig } from "../../interfaces";
66
import { t } from "../../localeImport";
77
import { cn, getIcons } from "../../utils/common";
88
import { validatePhoneNumber } from "../../utils/modal";
9-
import OtpInput from "../Otp/Otp";
9+
import { LoginOtp } from "../LoginOtp";
10+
import { LoginPasswordLess } from "../LoginPasswordLess";
1011
import SocialLoginList from "../SocialLoginList";
1112

1213
export interface LoginProps {
@@ -55,16 +56,15 @@ const Login = (props: LoginProps) => {
5556
const [canShowMore, setCanShowMore] = createSignal(false);
5657
const [visibleRow, setVisibleRow] = createSignal<rowType[]>([]);
5758
const [otherRow, setOtherRow] = createSignal<rowType[]>([]);
58-
const [isPasswordlessCtaClicked, setIsPasswordlessCtaClicked] = createSignal(false);
59-
const [isInputFocused, setIsInputFocused] = createSignal(false);
59+
const [isPasswordLessCtaClicked, setIsPasswordLessCtaClicked] = createSignal(false);
6060
const [showOtpFlow, setShowOtpFlow] = createSignal(false);
6161
const [otpLoading, setOtpLoading] = createSignal(true);
6262
const [isMobileOtp, setIsMobileOtp] = createSignal(false);
6363
const [otpSuccess, setOtpSuccess] = createSignal(false);
6464

6565
const handleExpand = () => {
6666
setExpand((prev) => !prev);
67-
setIsPasswordlessCtaClicked(false);
67+
setIsPasswordLessCtaClicked(false);
6868
props.handleSocialLoginHeight();
6969
};
7070

@@ -120,7 +120,6 @@ const Login = (props: LoginProps) => {
120120

121121
const handleFormSubmit = async (e: Event) => {
122122
e.preventDefault();
123-
124123
// setShowOtpFlow(true);
125124
// setTimeout(() => {
126125
// setOtpLoading(false);
@@ -154,8 +153,9 @@ const Login = (props: LoginProps) => {
154153
return undefined;
155154
};
156155

157-
const handleInputChange = (e: { target: { value: string } }) => {
158-
setFieldValue(e.target.value);
156+
const handleInputChange = (e: InputEvent) => {
157+
const target = e.target as HTMLInputElement;
158+
setFieldValue(target.value);
159159
if (isValidInput() === false) setIsValidInput(true);
160160
};
161161

@@ -178,7 +178,7 @@ const Login = (props: LoginProps) => {
178178
});
179179

180180
const handleConnectWallet = (e: MouseEvent) => {
181-
setIsPasswordlessCtaClicked(false);
181+
setIsPasswordLessCtaClicked(false);
182182
e.preventDefault();
183183
if (mergedProps.handleExternalWalletBtnClick) mergedProps.handleExternalWalletBtnClick(true);
184184
};
@@ -199,63 +199,13 @@ const Login = (props: LoginProps) => {
199199
<Suspense>
200200
<Switch>
201201
<Match when={showOtpFlow()}>
202-
<div class="w3a--flex w3a--flex-col w3a--items-center w3a--justify-center w3a--gap-y-4 w3a--w-full w3a--h-full w3a--flex-1">
203-
<Show
204-
when={!otpLoading()}
205-
fallback={
206-
<div class="w3a--flex w3a--items-center w3a--justify-center w3a--gap-y-4 w3a--w-full w3a--h-full w3a--flex-1 w3a--gap-x-2">
207-
<div class="w3a--w-3 w3a--h-3 w3a--rounded-full w3a--bg-app-primary-600 dark:w3a--bg-app-primary-500 w3a--animate-pulse" />
208-
<div class="w3a--w-3 w3a--h-3 w3a--rounded-full w3a--bg-app-primary-500 dark:w3a--bg-app-primary-400 w3a--animate-pulse" />
209-
<div class="w3a--w-3 w3a--h-3 w3a--rounded-full w3a--bg-app-primary-400 dark:w3a--bg-app-primary-300 w3a--animate-pulse" />
210-
</div>
211-
}
212-
>
213-
<Show
214-
when={!otpSuccess()}
215-
fallback={
216-
<div class="w3a--flex w3a--flex-col w3a--items-center w3a--justify-center w3a--gap-y-4 w3a--w-full w3a--h-full w3a--flex-1">
217-
<img src={getIcons("success-light")} alt="success" class="w3a--w-auto w3a--h-auto" />
218-
<p class="w3a--text-base w3a--font-medium w3a--text-app-gray-900 dark:w3a--text-app-white w3a--w-[80%] w3a--mx-auto w3a--text-center">
219-
You are connected to your account!
220-
</p>
221-
</div>
222-
}
223-
>
224-
<div class="w3a--flex w3a--items-start w3a--justify-start w3a--mr-auto w3a--w-full">
225-
<button
226-
class="w3a--w-5 w3a--h-5 w3a--rounded-full w3a--cursor-pointer w3a--flex w3a--items-center w3a--justify-center w3a--z-20"
227-
onClick={() => setShowOtpFlow(false)}
228-
>
229-
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20" class="w3a--text-app-gray-900 dark:w3a--text-app-white">
230-
<path
231-
fill="currentColor"
232-
fill-rule="evenodd"
233-
d="M9.707 16.707a1 1 0 0 1-1.414 0l-6-6a1 1 0 0 1 0-1.414l6-6a1 1 0 0 1 1.414 1.414L5.414 9H17a1 1 0 1 1 0 2H5.414l4.293 4.293a1 1 0 0 1 0 1.414"
234-
clip-rule="evenodd"
235-
/>
236-
</svg>
237-
</button>
238-
</div>
239-
<div class="w3a--flex w3a--flex-col w3a--items-center w3a--justify-center w3a--gap-y-4 w3a--w-full w3a--h-full w3a--flex-1">
240-
<img src={getIcons(isMobileOtp() ? "sms-otp-light" : "email-otp-light")} alt="otp" class="w3a--w-auto w3a--h-auto" />
241-
<div class="w3a--flex w3a--flex-col w3a--items-center w3a--justify-center w3a--gap-y-2">
242-
<p class="w3a--text-lg w3a--font-bold w3a--text-app-gray-900 dark:w3a--text-app-white">
243-
{isMobileOtp() ? "OTP verification" : "Email verification"}
244-
</p>
245-
<div class="w3a--flex w3a--flex-col w3a--items-center w3a--justify-center w3a--gap-y-1">
246-
<p class="w3a--text-sm w3a--font-normal w3a--text-app-gray-900 dark:w3a--text-app-white">
247-
{isMobileOtp() ? "Enter the OTP sent to" : "Please enter the 6-digit verification code "}
248-
</p>
249-
<p class="w3a--text-sm w3a--font-normal w3a--text-app-gray-900 dark:w3a--text-app-white">
250-
{isMobileOtp() ? "🇸🇬+91 ****0999" : "that was sent to your email ja****@email.com"}
251-
</p>
252-
</div>
253-
</div>
254-
<OtpInput length={6} onComplete={handleOtpComplete} />
255-
</div>
256-
</Show>
257-
</Show>
258-
</div>
202+
<LoginOtp
203+
otpLoading={otpLoading()}
204+
otpSuccess={otpSuccess()}
205+
setShowOtpFlow={setShowOtpFlow}
206+
isMobileOtp={isMobileOtp()}
207+
handleOtpComplete={handleOtpComplete}
208+
/>
259209
</Match>
260210
<Match when={!showOtpFlow()}>
261211
<div class="w3a--flex w3a--flex-col w3a--items-center w3a--gap-y-4 w3a--p-4">
@@ -292,43 +242,18 @@ const Login = (props: LoginProps) => {
292242
/>
293243
</Show>
294244
<Show when={mergedProps.showPasswordLessInput}>
295-
<Show
296-
when={isPasswordlessCtaClicked()}
297-
fallback={
298-
<button class={cn("w3a--btn !w3a--justify-between")} onClick={() => setIsPasswordlessCtaClicked(true)}>
299-
<p class="w3a--text-app-gray-900 dark:w3a--text-app-white">Continue with {title()}</p>
300-
</button>
301-
}
302-
>
303-
<div class={cn("w3a--input", isInputFocused() && "!w3a--border-app-primary-600")}>
304-
<input
305-
onInput={handleInputChange}
306-
value={fieldValue()}
307-
placeholder={placeholder()}
308-
onFocus={(e) => {
309-
e.target.placeholder = "";
310-
setIsInputFocused(true);
311-
}}
312-
onBlur={(e) => {
313-
e.target.placeholder = `${placeholder()}`;
314-
setIsInputFocused(false);
315-
}}
316-
type="text"
317-
autofocus
318-
class="w-full w3a--appearance-none w3a--outline-none active:w3a--outline-none focus:w3a--outline-none w3a--bg-transparent placeholder:w3a--text-xs placeholder:w3a--text-app-gray-400 dark:placeholder:w3a--text-app-gray-500 w3a--text-app-gray-900 dark:w3a--text-app-white"
319-
/>
320-
<Show when={fieldValue() && isValidInput() && isInputFocused()}>
321-
<button class="w3a--appearance-none w3a--icon-animation" onClick={handleFormSubmit}>
322-
<img src={getIcons(props.isDark ? "chevron-right-dark" : "chevron-right-light")} alt="arrow" />
323-
</button>
324-
</Show>
325-
</div>
326-
<Show when={!isValidInput() && isPasswordlessCtaClicked()}>
327-
<p class="w3a--text-xs w3a--font-normal w3a--text-app-red-500 dark:w3a--text-app-red-400 w3a--text-start -w3a--mt-2 w3a--w-full w3a--pl-6">
328-
{invalidInputErrorMessage()}
329-
</p>
330-
</Show>
331-
</Show>
245+
<LoginPasswordLess
246+
isPasswordLessCtaClicked={isPasswordLessCtaClicked()}
247+
setIsPasswordLessCtaClicked={setIsPasswordLessCtaClicked}
248+
title={title()}
249+
fieldValue={fieldValue()}
250+
handleInputChange={handleInputChange}
251+
placeholder={placeholder()}
252+
handleFormSubmit={handleFormSubmit}
253+
invalidInputErrorMessage={invalidInputErrorMessage()}
254+
isValidInput={isValidInput()}
255+
isDark={props.isDark}
256+
/>
332257
</Show>
333258
<Show when={mergedProps.showExternalWalletButton && mergedProps.showPasswordLessInput}>
334259
<div class="w3a--flex w3a--items-center w3a--gap-x-2 w3a--w-full">
@@ -354,7 +279,6 @@ const Login = (props: LoginProps) => {
354279
/>
355280
</button>
356281
</Show>
357-
{/* <OtpInput length={6} onComplete={() => {}} /> */}
358282
</Show>
359283
</div>
360284
</Match>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { For, Show } from "solid-js";
2+
3+
import { cn, getIcons } from "../../utils/common";
4+
5+
export interface Chain {
6+
id: string;
7+
name: string;
8+
icon?: string;
9+
}
10+
11+
export interface ChainFiltersProps {
12+
isDark: boolean;
13+
isLoading: boolean;
14+
selectedChain: string;
15+
setSelectedChain: (chain: string) => void;
16+
chains: Chain[];
17+
}
18+
19+
const ChainFilters = (props: ChainFiltersProps) => {
20+
return (
21+
<Show
22+
when={!props.isLoading}
23+
fallback={
24+
<div class="w3a--flex w3a--items-center w3a--justify-between w3a--gap-x-2">
25+
<For each={Array(props.chains.length).fill(0)}>
26+
{(_) => <div class="w3a--w-[100px] w3a--h-12 w3a--rounded-2xl w3a--bg-app-gray-200 dark:w3a--bg-app-gray-700 w3a--animate-pulse" />}
27+
</For>
28+
</div>
29+
}
30+
>
31+
<div class="w3a--flex w3a--items-center w3a--justify-between w3a--gap-x-2">
32+
<For each={props.chains}>
33+
{(chain) => (
34+
<button
35+
class={cn(
36+
"w3a--text-sm w3a--font-medium w3a--px-4 w3a--py-3 w3a--text-app-gray-900 dark:w3a--text-app-white w3a--rounded-2xl w3a--h-12",
37+
{
38+
"w3a--bg-app-gray-50 dark:w3a--bg-app-gray-800": props.selectedChain === chain.id,
39+
}
40+
)}
41+
onClick={() => props.setSelectedChain(chain.id)}
42+
>
43+
<Show when={chain.icon} fallback={chain.name}>
44+
<img src={getIcons(props.isDark ? `${chain.icon}-dark` : `${chain.icon}-light`)} alt={chain.name} />
45+
</Show>
46+
</button>
47+
)}
48+
</For>
49+
</div>
50+
</Show>
51+
);
52+
};
53+
54+
export default ChainFilters;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as ChainFilters } from "./ChainFilters";
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { createSignal, Show } from "solid-js";
2+
3+
import { t } from "../../localeImport";
4+
import { cn } from "../../utils/common";
5+
6+
export interface ConnectSearchWalletsProps {
7+
totalExternalWallets: number;
8+
isLoading: boolean;
9+
walletSearch: string;
10+
handleWalletSearch: (e: InputEvent) => void;
11+
}
12+
13+
const ConnectSearchWallets = (props: ConnectSearchWalletsProps) => {
14+
const [isInputFocused, setIsInputFocused] = createSignal(false);
15+
16+
const handleWalletSearch = (e: InputEvent) => {
17+
props.handleWalletSearch(e);
18+
setIsInputFocused(true);
19+
};
20+
21+
return (
22+
<Show
23+
when={props.totalExternalWallets > 15 && !props.isLoading}
24+
fallback={<div class="w3a--w-full w3a--h-[50px] w3a--animate-pulse w3a--rounded-full w3a--bg-app-gray-200 dark:w3a--bg-app-gray-700" />}
25+
>
26+
<input
27+
type="text"
28+
value={props.walletSearch}
29+
onInput={handleWalletSearch}
30+
onFocus={(e) => {
31+
e.target.placeholder = "";
32+
setIsInputFocused(true);
33+
}}
34+
onBlur={(e) => {
35+
e.target.placeholder = t("modal.external.search-wallet", { count: `${props.totalExternalWallets}` });
36+
setIsInputFocused(false);
37+
}}
38+
placeholder={
39+
props.isLoading ? t("modal.external.search-wallet-loading") : t("modal.external.search-wallet", { count: `${props.totalExternalWallets}` })
40+
}
41+
disabled={props.isLoading}
42+
class={cn(
43+
"w3a--input w3a--appearance-none w3a--outline-none active:w3a--outline-none focus:w3a--outline-none w3a--bg-transparent placeholder:w3a--text-app-gray-400 dark:placeholder:w3a--text-app-gray-500 w3a--text-app-gray-900 dark:w3a--text-app-white",
44+
isInputFocused() && "!w3a--border-app-primary-600"
45+
)}
46+
/>
47+
</Show>
48+
);
49+
};
50+
51+
export default ConnectSearchWallets;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as ConnectSearchWallets } from "./ConnectSearchWallets";
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { CONNECT_WALLET_PAGES } from "../../constants";
2+
import { ExternalButton } from "../../interfaces";
3+
4+
export interface ConnectWalletHeaderProps {
5+
onBackClick: () => void;
6+
currentPage: string;
7+
selectedButton: ExternalButton;
8+
}
9+
10+
const ConnectWalletHeader = (props: ConnectWalletHeaderProps) => {
11+
const handleBack = () => {
12+
props.onBackClick();
13+
};
14+
15+
return (
16+
<div class="w3a--flex w3a--items-center w3a--justify-between">
17+
<button
18+
class="w3a--w-5 w3a--h-5 w3a--rounded-full w3a--cursor-pointer w3a--flex w3a--items-center w3a--justify-center w3a--z-20"
19+
onClick={handleBack}
20+
>
21+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20" class="w3a--text-app-gray-900 dark:w3a--text-app-white">
22+
<path
23+
fill="currentColor"
24+
fill-rule="evenodd"
25+
d="M9.707 16.707a1 1 0 0 1-1.414 0l-6-6a1 1 0 0 1 0-1.414l6-6a1 1 0 0 1 1.414 1.414L5.414 9H17a1 1 0 1 1 0 2H5.414l4.293 4.293a1 1 0 0 1 0 1.414"
26+
clip-rule="evenodd"
27+
/>
28+
</svg>
29+
</button>
30+
<p class="w3a--text-base w3a--font-medium w3a--text-app-gray-900">
31+
{props.currentPage === CONNECT_WALLET_PAGES.SELECTED_WALLET ? props.selectedButton?.displayName : props.currentPage}
32+
</p>
33+
<div class="w3a--w-5 w3a--h-5 w3a--z-[-1]" />
34+
</div>
35+
);
36+
};
37+
38+
export default ConnectWalletHeader;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as ConnectWalletHeader } from "./ConnectWalletHeader";

0 commit comments

Comments
 (0)