99 Group ,
1010 LoadingOverlay ,
1111} from "@mantine/core" ;
12+ import { Trans } from "react-i18next" ;
1213
1314const currencyMap = {
1415 USD : "$" ,
@@ -19,7 +20,10 @@ function formatBalance(balance: number) {
1920 return Math . round ( balance * 1000 ) / 1000 ;
2021}
2122
22- function formatCurrency ( balance : number , currency : string ) {
23+ function formatCurrency ( balance : number | null , currency : string ) {
24+ if ( balance === null || balance === undefined ) {
25+ return "" ;
26+ }
2327 return `${ currencyMap [ currency ] || currency } ${ balance } ` ;
2428}
2529
@@ -34,13 +38,13 @@ const envMap = {
3438 } ,
3539} ;
3640
37- // eslint-disable-next-line @typescript-eslint/naming-convention
3841export default function WechatTip ( ) {
3942 const [ bindWechat , setBindWechat ] = useState ( false ) ;
4043 const [ balance , setBalance ] = useState < null | number > ( null ) ;
4144 const [ currency , setCurrency ] = useState ( "USD" ) ;
4245 const [ accessKey , setAccessKey ] = useState ( "" ) ;
4346 const [ env , setEnv ] = useState ( "prod" ) ;
47+
4448 const [ loading , setLoading ] = useState ( false ) ;
4549 const platform = process . env . platform ;
4650
@@ -82,7 +86,7 @@ export default function WechatTip() {
8286 useEffect ( ( ) => {
8387 getSettings ( ) ;
8488 messageUtil . registerHandler (
85- "getUserAccessKey " ,
89+ "getUserSetting " ,
8690 ( message : { endPoint : string ; accessKey : string ; keyType : string } ) => {
8791 if ( message . keyType === "DevChat" && message . accessKey ) {
8892 if ( message . endPoint . includes ( "api-test.devchat.ai" ) ) {
@@ -105,6 +109,8 @@ export default function WechatTip() {
105109 } ) ;
106110 } ;
107111
112+ const formatedCurrency = formatCurrency ( balance , currency ) ;
113+
108114 if ( balance === null || balance === undefined ) {
109115 return null ;
110116 }
@@ -138,18 +144,19 @@ export default function WechatTip() {
138144 >
139145 < Group style = { { width : "90%" } } >
140146 < Text size = "sm" >
141- Your remaining credit is { formatCurrency ( balance , currency ) } . Sign
142- in to{ " " }
143- { platform === "idea" ? (
144- < Text td = "underline" c = "blue" onClick = { ( e ) => openLink ( e ) } >
145- web.devchat.ai{ " " }
146- </ Text >
147- ) : (
148- < a href = { envMap [ env ] . link } target = "_blank" >
149- web.devchat.ai{ " " }
150- </ a >
151- ) }
152- to { bindWechat ? "purchase more tokens." : "earn additional ¥8" }
147+ < Trans i18nKey = "balance" formatedCurrency = { formatedCurrency } >
148+ Your remaining credit is { { formatedCurrency } } . Sign in to{ " " }
149+ { platform === "idea" ? (
150+ < Text td = "underline" c = "blue" onClick = { ( e ) => openLink ( e ) } >
151+ web.devchat.ai{ " " }
152+ </ Text >
153+ ) : (
154+ < a href = { envMap [ env ] . link } target = "_blank" >
155+ web.devchat.ai{ " " }
156+ </ a >
157+ ) }
158+ to purchase more tokens.
159+ </ Trans >
153160 </ Text >
154161 < LoadingOverlay visible = { loading } />
155162 </ Group >
0 commit comments