11import i18n from 'i18next' ;
22import { logManager } from './LogManager' ;
33
4- export type OnGoingProcessMessages =
4+ export type BaseOnGoingProcessMessages =
55 | 'GENERAL_AWAITING'
66 | 'CREATING_KEY'
77 | 'LOGGING_IN'
@@ -45,12 +45,71 @@ export type OnGoingProcessMessages =
4545 | 'DELETING_PASSKEY'
4646 | 'WAITING_FOR_MAX_AMOUNT' ;
4747
48+ export type ImportProgressMessages =
49+ | 'keyConfig.count'
50+ | 'keyConfig.start'
51+ | 'keyConfig.keyCreated'
52+ | 'keyConfig.noCopayersFound'
53+ | 'chainPermutations.count'
54+ | 'chainPermutations.getKey'
55+ | 'findingCopayers'
56+ | 'foundCopayers'
57+ | 'foundCopayers.count'
58+ | 'creatingCredentials'
59+ | 'gettingStatuses'
60+ | 'gatheringWalletsInfos'
61+ | 'walletInfo.gatheringTokens'
62+ | 'walletInfo.gatheringTokens.error'
63+ | 'walletInfo.importingToken'
64+ | 'walletInfo.gatheringMultisig'
65+ | 'walletInfo.multisig.creatingCredentials'
66+ | 'walletInfo.multisig.importingToken' ;
67+
68+ export type OnGoingProcessMessages =
69+ | BaseOnGoingProcessMessages
70+ | ImportProgressMessages ;
71+
4872export interface OngoingProcessState {
4973 isVisible : boolean ;
5074 message : string | undefined ;
5175}
5276
53- const translations : Record < OnGoingProcessMessages , ( ) => string > = {
77+ export type OngoingProcessObjectData = {
78+ chain ?: string ;
79+ tokenName ?: string ;
80+ walletName ?: string ;
81+ count ?: number ;
82+ iteration ?: number ;
83+ } ;
84+
85+ export type OngoingProcessData = number | OngoingProcessObjectData | undefined ;
86+
87+ const isNumberData = ( data : OngoingProcessData ) : data is number =>
88+ typeof data === 'number' ;
89+
90+ const getChain = ( data ?: OngoingProcessData ) : string | undefined =>
91+ typeof data === 'object' && data !== null ? data . chain : undefined ;
92+
93+ const getTokenName = ( data ?: OngoingProcessData ) : string | undefined =>
94+ typeof data === 'object' && data !== null ? data . tokenName : undefined ;
95+
96+ const getWalletName = ( data ?: OngoingProcessData ) : string | undefined =>
97+ typeof data === 'object' && data !== null ? data . walletName : undefined ;
98+
99+ const getIteration = ( data ?: OngoingProcessData ) : number =>
100+ typeof data === 'object' && data !== null ? data . iteration ?? 1 : 1 ;
101+
102+ const getCount = ( data ?: OngoingProcessData ) : number =>
103+ typeof data === 'object' && data !== null
104+ ? data . count ?? 0
105+ : isNumberData ( data )
106+ ? data
107+ : 0 ;
108+
109+ const translations : Record <
110+ OnGoingProcessMessages ,
111+ ( data ?: OngoingProcessData ) => string
112+ > = {
54113 GENERAL_AWAITING : ( ) =>
55114 i18n . t ( "Just a second, we're setting a few things up" ) ,
56115 CREATING_KEY : ( ) =>
@@ -97,13 +156,114 @@ const translations: Record<OnGoingProcessMessages, () => string> = {
97156 CREATING_PASSKEY : ( ) => i18n . t ( 'Creating Passkey...' ) ,
98157 DELETING_PASSKEY : ( ) => i18n . t ( 'Deleting Passkey...' ) ,
99158 WAITING_FOR_MAX_AMOUNT : ( ) => i18n . t ( 'Calculating maximum amount...' ) ,
159+ 'keyConfig.count' : data =>
160+ i18n . t ( 'Checking {{count}} key configurations...' , {
161+ count : isNumberData ( data ) ? data : 0 ,
162+ } ) ,
163+ 'keyConfig.start' : data =>
164+ i18n . t ( 'Checking key configuration {{index}}...' , {
165+ index : isNumberData ( data ) ? data + 1 : 1 ,
166+ } ) ,
167+ 'keyConfig.keyCreated' : ( ) => i18n . t ( 'Key created, searching for wallets...' ) ,
168+ 'keyConfig.noCopayersFound' : ( ) =>
169+ i18n . t ( 'No wallets found for this configuration, trying next...' ) ,
170+ 'chainPermutations.count' : data =>
171+ i18n . t ( 'Checking {{count}} chain permutations...' , {
172+ count : isNumberData ( data ) ? data : 0 ,
173+ } ) ,
174+ 'chainPermutations.getKey' : data =>
175+ i18n . t ( 'Deriving key for chain permutation {{index}}...' , {
176+ index : isNumberData ( data ) ? data + 1 : 1 ,
177+ } ) ,
178+ findingCopayers : data =>
179+ getIteration ( data ) > 1
180+ ? i18n . t ( 'Checking for additional wallets...' )
181+ : i18n . t ( 'Searching for your wallets...' ) ,
182+ foundCopayers : data => {
183+ const iteration = getIteration ( data ) ;
184+ const count = getCount ( data ) ;
185+ if ( iteration > 1 && count === 0 ) {
186+ return i18n . t ( 'No more wallets found...' ) ;
187+ }
188+ if ( iteration > 1 ) {
189+ return i18n . t ( '{{count}} more wallets found! Loading details...' , {
190+ count,
191+ } ) ;
192+ }
193+ if ( iteration === 1 && count === 0 ) {
194+ return i18n . t ( 'No wallets found...' ) ;
195+ }
196+ return count === 1
197+ ? i18n . t ( 'Found 1 wallet! Loading details...' )
198+ : i18n . t ( 'Found {{count}} wallets! Loading details...' , { count} ) ;
199+ } ,
200+ 'foundCopayers.count' : data => {
201+ const count = getCount ( data ) ;
202+ return count === 1
203+ ? i18n . t ( 'Found 1 wallet! Loading details...' )
204+ : i18n . t ( 'Found {{count}} wallets! Loading details...' , { count} ) ;
205+ } ,
206+ creatingCredentials : ( ) => i18n . t ( 'Almost there...' ) ,
207+ gettingStatuses : ( ) => i18n . t ( 'Getting wallet info...' ) ,
208+ gatheringWalletsInfos : data => {
209+ const count = getCount ( data ) ;
210+ return count === 1
211+ ? i18n . t ( 'Loading 1 wallet...' )
212+ : i18n . t ( 'Loading {{count}} wallets...' , { count} ) ;
213+ } ,
214+ 'walletInfo.gatheringTokens' : data => {
215+ const chain = getChain ( data ) ;
216+ return i18n . t ( 'Loading {{chain}} tokens...' , { chain} ) ;
217+ } ,
218+ 'walletInfo.gatheringTokens.error' : ( ) =>
219+ i18n . t ( 'Some tokens could not be loaded, continuing...' ) ,
220+ 'walletInfo.importingToken' : data => {
221+ const tokenName = getTokenName ( data ) ;
222+ return i18n . t ( 'Adding {{tokenName}}...' , { tokenName} ) ;
223+ } ,
224+ 'walletInfo.gatheringMultisig' : data => {
225+ const chain = getChain ( data ) ;
226+ return i18n . t ( 'Loading {{chain}} shared wallets...' , { chain} ) ;
227+ } ,
228+ 'walletInfo.multisig.creatingCredentials' : data => {
229+ const walletName = getWalletName ( data ) ;
230+ return i18n . t ( 'Setting up {{walletName}}...' , { walletName} ) ;
231+ } ,
232+
233+ 'walletInfo.multisig.importingToken' : data => {
234+ const tokenName = getTokenName ( data ) ;
235+ return i18n . t ( 'Adding {{tokenName}}...' , { tokenName} ) ;
236+ } ,
100237} ;
101238
239+ export const importProgressEvents : ImportProgressMessages [ ] = [
240+ 'keyConfig.count' ,
241+ 'keyConfig.start' ,
242+ 'keyConfig.keyCreated' ,
243+ 'keyConfig.noCopayersFound' ,
244+ 'chainPermutations.count' ,
245+ 'chainPermutations.getKey' ,
246+ 'findingCopayers' ,
247+ 'foundCopayers' ,
248+ 'foundCopayers.count' ,
249+ 'creatingCredentials' ,
250+ 'gettingStatuses' ,
251+ 'gatheringWalletsInfos' ,
252+ 'walletInfo.gatheringTokens' ,
253+ 'walletInfo.gatheringTokens.error' ,
254+ 'walletInfo.importingToken' ,
255+ 'walletInfo.gatheringMultisig' ,
256+ 'walletInfo.multisig.creatingCredentials' ,
257+ 'walletInfo.multisig.importingToken' ,
258+ ] ;
259+
102260const LONG_RUNNING_PROCESSES : OnGoingProcessMessages [ ] = [
103261 'IMPORTING' ,
104262 'IMPORT_SCANNING_FUNDS' ,
105263 'SCANNING_FUNDS_WITH_PASSPHRASE' ,
106264 'CREATING_KEY' ,
265+ 'SYNCING_WALLETS' ,
266+ ...importProgressEvents ,
107267] ;
108268
109269class OngoingProcessManager {
@@ -124,23 +284,21 @@ class OngoingProcessManager {
124284 return OngoingProcessManager . instance ;
125285 }
126286
127- /**
128- * Obtiene el estado actual
129- */
130287 getState ( ) : OngoingProcessState {
131288 return {
132289 isVisible : this . state . isVisible ,
133290 message : this . state . message ,
134291 } ;
135292 }
136293
137- show ( key : OnGoingProcessMessages ) : void {
294+ show ( key : OnGoingProcessMessages , data ?: OngoingProcessData ) : void {
138295 if ( this . timeoutRef ) {
139296 clearTimeout ( this . timeoutRef ) ;
140297 this . timeoutRef = null ;
141298 }
142299
143- const translatedMessage = translations [ key ] ( ) ;
300+ const translatedMessage = translations [ key ] ?.( data ) ?? i18n . t ( 'Loading' ) ;
301+
144302 this . state = {
145303 isVisible : true ,
146304 message : translatedMessage ,
0 commit comments