Skip to content

Commit 623ac6d

Browse files
authored
refactor: rename "popup" transient state to transient state (#1319)
1 parent 491d4be commit 623ac6d

10 files changed

Lines changed: 31 additions & 35 deletions

File tree

src/background/services/background.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class Background {
147147
consentTelemetry,
148148
connected,
149149
publicKey,
150-
transientState: this.storage.getPopupTransientState(),
150+
transientState: this.storage.getTransientState(),
151151
};
152152
}
153153

@@ -459,7 +459,7 @@ export class Background {
459459
void this.tabEvents.updateVisualIndicators(tab);
460460
});
461461

462-
this.events.on('storage.popup_transient_state_update', (state) => {
462+
this.events.on('storage.transient_state_update', (state) => {
463463
this.sendToPopup.send('SET_TRANSIENT_STATE', state);
464464
this.sendToApp.send('SET_TRANSIENT_STATE', state);
465465
});

src/background/services/events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { EventEmitter } from 'node:events';
22
import type {
33
AmountValue,
4-
PopupTransientState,
4+
TransientState,
55
Storage,
66
TabId,
77
} from '@/shared/types';
@@ -16,7 +16,7 @@ interface BackgroundEvents {
1616
state: Storage['state'];
1717
prevState: Storage['state'];
1818
};
19-
'storage.popup_transient_state_update': PopupTransientState;
19+
'storage.transient_state_update': TransientState;
2020
'storage.balance_update': Record<
2121
'recurring' | 'oneTime' | 'total',
2222
AmountValue

src/background/services/keyAutoAdd.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,14 @@ export class KeyAutoAddService {
189189
}
190190

191191
private setConnectState(currentStep: string) {
192-
this.storage.setPopupTransientState('connect', () => ({
192+
this.storage.setTransientState('connect', () => ({
193193
status: 'connecting:key',
194194
currentStep,
195195
}));
196196
}
197197

198198
private setConnectStateError(err: ErrorWithKeyLike | { message: string }) {
199-
this.storage.setPopupTransientState('connect', () => ({
199+
this.storage.setTransientState('connect', () => ({
200200
status: 'error:key',
201201
error: isErrorWithKey(err) ? errorWithKeyToJSON(err) : err.message,
202202
}));

src/background/services/monetization.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ export class MonetizationService {
436436
...dataFromStorage,
437437
balance: balance.total.toString(),
438438
tab: this.tabState.getPopupTabData(tab),
439-
transientState: this.storage.getPopupTransientState(),
439+
transientState: this.storage.getTransientState(),
440440
grants: {
441441
oneTime: oneTimeGrant?.amount,
442442
recurring: recurringGrant?.amount,

src/background/services/storage.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type {
22
AmountValue,
33
ExtensionState,
44
GrantDetails,
5-
PopupTransientState,
5+
TransientState,
66
Storage,
77
StorageKey,
88
WalletAmount,
@@ -48,7 +48,7 @@ export class StorageService {
4848
// used as an optimization/cache
4949
private currentState: Storage['state'] | null = null;
5050

51-
private popupTransientState: PopupTransientState = {};
51+
private transientState: TransientState = {};
5252

5353
constructor({ browser, events }: Cradle) {
5454
Object.assign(this, { browser, events });
@@ -211,19 +211,19 @@ export class StorageService {
211211
this.events.emit('storage.rate_of_pay_update', { rate });
212212
}
213213

214-
setPopupTransientState<T extends keyof PopupTransientState>(
214+
setTransientState<T extends keyof TransientState>(
215215
id: T,
216-
update: (prev?: PopupTransientState[T]) => PopupTransientState[T],
216+
update: (prev?: TransientState[T]) => TransientState[T],
217217
) {
218-
const newState = update(this.popupTransientState[id]);
219-
this.popupTransientState[id] = newState;
218+
const newState = update(this.transientState[id]);
219+
this.transientState[id] = newState;
220220

221-
const state = this.getPopupTransientState();
222-
this.events.emit('storage.popup_transient_state_update', state);
221+
const state = this.getTransientState();
222+
this.events.emit('storage.transient_state_update', state);
223223
}
224224

225-
getPopupTransientState(): PopupTransientState {
226-
return this.popupTransientState;
225+
getTransientState(): TransientState {
226+
return this.transientState;
227227
}
228228
}
229229

src/background/services/wallet.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,18 +529,18 @@ export class WalletService {
529529
}
530530

531531
public resetConnectState() {
532-
this.storage.setPopupTransientState('connect', () => null);
532+
this.storage.setTransientState('connect', () => null);
533533
}
534534

535535
private setConnectState(currentStep: string) {
536-
this.storage.setPopupTransientState('connect', () => ({
536+
this.storage.setTransientState('connect', () => ({
537537
status: 'connecting',
538538
currentStep,
539539
}));
540540
}
541541

542542
private setConnectStateError(err: ErrorWithKeyLike | { message: string }) {
543-
this.storage.setPopupTransientState('connect', (state) => {
543+
this.storage.setTransientState('connect', (state) => {
544544
if (state?.status === 'error:key') {
545545
return state;
546546
}

src/pages/app/lib/store.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
import type {
2-
AppStore,
3-
DeepNonNullable,
4-
PopupTransientState,
5-
} from '@/shared/types';
1+
import type { AppStore, DeepNonNullable, TransientState } from '@/shared/types';
62
import { proxy, useSnapshot } from 'valtio';
73

84
export type AppState = Required<DeepNonNullable<AppStore>>;
95

106
export const store = proxy<AppState>({
11-
transientState: {} as PopupTransientState,
7+
transientState: {} as TransientState,
128
} as AppState);
139

1410
// easier access to the store via this hook
@@ -36,7 +32,7 @@ export const dispatch = ({ type, data }: Actions) => {
3632
};
3733

3834
type Actions =
39-
| { type: 'SET_TRANSIENT_STATE'; data: PopupTransientState }
35+
| { type: 'SET_TRANSIENT_STATE'; data: TransientState }
4036
| {
4137
type: 'SET_CONSENT';
4238
data: {

src/pages/popup/components/ConnectWalletForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import type {
3030
ConnectWalletAddressInfo,
3131
Response,
3232
} from '@/shared/messages';
33-
import type { DeepReadonly, PopupTransientState } from '@/shared/types';
33+
import type { DeepReadonly, TransientState } from '@/shared/types';
3434

3535
interface Inputs {
3636
walletAddressUrl: string;
@@ -39,7 +39,7 @@ interface Inputs {
3939
autoKeyAddConsent: boolean;
4040
}
4141

42-
type ConnectTransientState = DeepReadonly<PopupTransientState['connect']>;
42+
type ConnectTransientState = DeepReadonly<TransientState['connect']>;
4343
type ErrorsParams = 'walletAddressUrl' | 'amount' | 'keyPair' | 'connect';
4444
type Errors = Record<ErrorsParams, ErrorInfo | null>;
4545

src/shared/messages.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
import type { Browser } from 'webextension-polyfill';
66
import type {
77
AmountValue,
8-
PopupTransientState,
8+
TransientState,
99
Storage,
1010
WalletInfo,
1111
} from '@/shared/types';
@@ -334,7 +334,7 @@ export interface BackgroundToPopupMessagesMap {
334334
SET_BALANCE: Record<'recurring' | 'oneTime' | 'total', AmountValue>;
335335
SET_TAB_DATA: PopupState['tab'];
336336
SET_STATE: { state: Storage['state']; prevState: Storage['state'] };
337-
SET_TRANSIENT_STATE: PopupTransientState;
337+
SET_TRANSIENT_STATE: TransientState;
338338
CLOSE_POPUP: undefined;
339339
}
340340

@@ -350,7 +350,7 @@ export type BackgroundToPopupMessage = {
350350
export const BACKGROUND_TO_APP_CONNECTION_NAME = 'app';
351351

352352
export interface BackgroundToAppMessagesMap {
353-
SET_TRANSIENT_STATE: PopupTransientState;
353+
SET_TRANSIENT_STATE: TransientState;
354354
}
355355

356356
export type BackgroundToAppMessage = {

src/shared/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export type PopupTabInfo = {
145145
| never; // just added for code formatting
146146
};
147147

148-
export type PopupTransientState = Partial<{
148+
export type TransientState = Partial<{
149149
connect:
150150
| null
151151
| { status: 'connecting' | 'connecting:key'; currentStep: string }
@@ -163,7 +163,7 @@ export type PopupStore = Omit<
163163
> & {
164164
balance: AmountValue;
165165
tab: PopupTabInfo;
166-
transientState: PopupTransientState;
166+
transientState: TransientState;
167167
grants?: Partial<{
168168
oneTime: OneTimeGrant['amount'];
169169
recurring: RecurringGrant['amount'];
@@ -174,7 +174,7 @@ export type AppStore = Pick<
174174
Storage,
175175
'publicKey' | 'connected' | 'uid' | 'consent' | 'consentTelemetry'
176176
> & {
177-
transientState: PopupTransientState;
177+
transientState: TransientState;
178178
};
179179

180180
export type DeepNonNullable<T> = {

0 commit comments

Comments
 (0)