Skip to content

Commit 26b46b9

Browse files
committed
UX upgrades & i18n upgrades
1 parent 8b59f1f commit 26b46b9

File tree

6 files changed

+2924
-833
lines changed

6 files changed

+2924
-833
lines changed

src/components/ConnectButton/Button.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { Signer } from 'ethers'
88
import { useEffect, useMemo, useState } from 'react'
99
import { whenDefined, whenDefinedAll } from '@devprotocol/util-ts'
1010
import { i18nFactory, Signal } from '@devprotocol/clubs-core'
11-
import type { connection as Connection } from '@devprotocol/clubs-core/connection'
11+
import { connection } from '@devprotocol/clubs-core/connection'
1212
import {
1313
DynamicUserProfile,
1414
useDynamicContext,
@@ -33,7 +33,6 @@ export default ({
3333
buttonClassName?: string
3434
}) => {
3535
const dynamic = useDynamicContext()
36-
const [connection, setConnection] = useState<ReturnType<typeof Connection>>()
3736
const [signer, setSigner] = useState<Signer>()
3837
const [walletName, setWalletName] = useState<string>()
3938
const [isWalletNeeded, setIsWalletNeeded] = useState<boolean>(false)
@@ -55,7 +54,7 @@ export default ({
5554

5655
useEffect(() => {
5756
const cryptoWallet = dynamic.user?.verifiedCredentials.find(
58-
(c) => c.format === 'blockchain',
57+
(c) => c.format === 'blockchain' && Boolean(c.embeddedWalletId),
5958
)
6059

6160
if (cryptoWallet) {
@@ -85,7 +84,7 @@ export default ({
8584
setUnexpectedNetwork(
8685
typeof chainId === 'number' && connectedChain !== chainId,
8786
)
88-
whenDefinedAll([connection], ([_connection]) =>
87+
whenDefinedAll([connection()], ([_connection]) =>
8988
_connection.chain.next(Number(dynamic.network)),
9089
)
9190
}, [dynamic.network])
@@ -95,7 +94,7 @@ export default ({
9594
(c) => c.format === 'email',
9695
)
9796
console.log('**', { emailCredential })
98-
whenDefinedAll([connection], ([_connection]) =>
97+
whenDefinedAll([connection()], ([_connection]) =>
9998
_connection.identifiers.next(
10099
whenDefined(emailCredential?.publicIdentifier, (email) => ({
101100
email,
@@ -104,12 +103,6 @@ export default ({
104103
)
105104
}, [dynamic.user])
106105

107-
useEffect(() => {
108-
import('@devprotocol/clubs-core/connection').then((C) => {
109-
setConnection(C.connection())
110-
})
111-
}, [])
112-
113106
useEffect(() => {
114107
const eoa = dynamic?.primaryWallet?.address
115108
if (eoa) {
@@ -122,14 +115,14 @@ export default ({
122115
}, [dynamic?.primaryWallet?.address])
123116

124117
useEffect(() => {
125-
whenDefinedAll([connection], ([_connection]) => {
118+
whenDefinedAll([connection()], ([_connection]) => {
126119
// console.log('Called here', signer)
127120
_connection.signer.next(signer)
128121
})
129-
}, [signer, connection])
122+
}, [signer])
130123

131124
useEffect(() => {
132-
whenDefinedAll([connection], ([_connection]) => {
125+
whenDefinedAll([connection()], ([_connection]) => {
133126
// console.log('$$$ Called here', signer)
134127

135128
// signal
@@ -151,7 +144,7 @@ export default ({
151144
}
152145
})
153146
})
154-
}, [connection])
147+
}, [])
155148

156149
return (
157150
<span className="group/awesome-onboarding relative block">

src/components/ConnectButton/ConnectButton.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,27 @@ import type { LocaleResource } from '@dynamic-labs/sdk-react-core'
1010
import { DynamicContextProvider } from '@dynamic-labs/sdk-react-core'
1111

1212
import Button from './Button'
13-
import { Japanese } from '../../i18n/dynamic'
13+
import { English, Japanese } from '../../i18n/dynamic'
1414
import type { ConnectButtonProps } from '../../types'
15+
import cssOverrides from '../../i18n/cssOverrides'
1516

1617
const langs = ['en', 'ja']
1718

1819
export default ({ chainId, environmentId, ...props }: ConnectButtonProps) => {
19-
const [locale, setLocale] = useState<UndefinedOr<LocaleResource | null>>(null)
20+
const [locale, setLocale] =
21+
useState<UndefinedOr<{ lang: string; dic: LocaleResource } | null>>(null)
2022

2123
useEffect(() => {
2224
// eslint-disable-next-line functional/no-conditional-statements
2325
if (typeof window !== 'undefined') {
2426
const loc = window.navigator.languages.find((l) => langs.includes(l))
25-
setLocale(loc === 'ja' ? Japanese : undefined)
27+
setLocale(
28+
loc === 'ja'
29+
? { lang: 'ja', dic: Japanese }
30+
: { lang: 'en', dic: English },
31+
)
2632
}
27-
})
33+
}, [])
2834

2935
return locale !== null ? (
3036
<DynamicContextProvider
@@ -33,8 +39,9 @@ export default ({ chainId, environmentId, ...props }: ConnectButtonProps) => {
3339
walletConnectPreferredChains: [`eip155:${chainId ?? 137}`],
3440
walletConnectorExtensions: [EthersExtension],
3541
walletConnectors: [EthereumWalletConnectors],
42+
cssOverrides: cssOverrides(locale?.lang),
3643
}}
37-
locale={locale}
44+
locale={locale?.dic}
3845
>
3946
<Button chainId={chainId} {...props} />
4047
</DynamicContextProvider>

src/i18n/cssOverrides.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const one = `.dynamic-widget-modal .popper-content .dots-menu-dropdown__container .dots-menu-dropdown__item:first-child .typography`
2+
const two = `.dynamic-widget-modal .popper-content .dots-menu-dropdown__container .dots-menu-dropdown__item:last-child .typography`
3+
const xxx = `.balance-container > .typography:first-child`
4+
5+
export default (lang?: string) => `
6+
.dynamic-widget-header .dynamic-widget-wallet-header .dynamic-widget-wallet-header__wallet-actions {
7+
display: none;
8+
}
9+
10+
${one} {
11+
visibility: hidden;
12+
width: ${lang === 'ja' ? '18ch' : '12ch'};
13+
overflow: clip;
14+
}
15+
${
16+
lang === 'ja'
17+
? `
18+
${one}::before {
19+
content: 'ユーザーIDをコピー';
20+
visibility: visible;
21+
}
22+
`
23+
: `
24+
${one}::before {
25+
content: 'Copy user ID';
26+
visibility: visible;
27+
}
28+
`
29+
}
30+
31+
${two} {
32+
visibility: hidden;
33+
width: ${lang === 'ja' ? '16ch' : '17ch'};
34+
overflow: clip;
35+
}
36+
${
37+
lang === 'ja'
38+
? `
39+
${two}::before {
40+
content: 'セキュリティ設定';
41+
visibility: visible;
42+
}
43+
`
44+
: `
45+
${two}::before {
46+
content: 'Security settings';
47+
visibility: visible;
48+
}
49+
`
50+
}
51+
52+
${xxx} {
53+
visibility: hidden;
54+
width: ${lang === 'ja' ? '6ch' : '4ch'};
55+
overflow: clip;
56+
text-wrap: nowrap;
57+
}
58+
${
59+
lang === 'ja'
60+
? `
61+
${xxx}::before {
62+
content: 'コイン';
63+
visibility: visible;
64+
}
65+
`
66+
: `
67+
${xxx}::before {
68+
content: 'Coin';
69+
visibility: visible;
70+
}
71+
`
72+
}
73+
`

0 commit comments

Comments
 (0)