diff --git a/package.json b/package.json index cf7ae91..aaeba6e 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "scripts": { "dev": "vite", "build": "tsc && vite build", - "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 2", + "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "lint:fix": "eslint . --fix --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "lint:staged": "eslint --fix --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "formatter:check": "prettier --check \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"", diff --git a/src/store/actions.ts b/src/store/actions.ts index aee594f..bca5438 100644 --- a/src/store/actions.ts +++ b/src/store/actions.ts @@ -18,6 +18,10 @@ export interface RestoreState { payload: State } +export interface UserLogout { + type: typeof ActionTypes.USER_LOGOUT +} + export const userLogOutAction = () => { return { type: ActionTypes.USER_LOGOUT diff --git a/src/store/auth/types.ts b/src/store/auth/types.ts index 18dafcf..a134a7b 100644 --- a/src/store/auth/types.ts +++ b/src/store/auth/types.ts @@ -1,5 +1,5 @@ import * as ActionTypes from '../actionTypes' -import { RestoreState } from '../actions' +import { RestoreState, UserLogout } from '../actions' export enum LoginMethods { extension = 'extension', @@ -54,3 +54,4 @@ export type AuthDispatchTypes = | UpdateKeyPair | UpdateNsecBunkerPubkey | UpdateNsecBunkerRelays + | UserLogout diff --git a/src/store/rootReducer.ts b/src/store/rootReducer.ts index b37a3cd..61b2837 100644 --- a/src/store/rootReducer.ts +++ b/src/store/rootReducer.ts @@ -3,12 +3,15 @@ import { combineReducers } from 'redux' import { UserAppData } from '../types' import * as ActionTypes from './actionTypes' import authReducer from './auth/reducer' -import { AuthState } from './auth/types' +import { AuthDispatchTypes, AuthState } from './auth/types' import metadataReducer from './metadata/reducer' import relaysReducer from './relays/reducer' -import { RelaysState } from './relays/types' +import { RelaysDispatchTypes, RelaysState } from './relays/types' import UserAppDataReducer from './userAppData/reducer' import userRobotImageReducer from './userRobotImage/reducer' +import { MetadataDispatchTypes } from './metadata/types' +import { UserAppDataDispatchTypes } from './userAppData/types' +import { UserRobotImageDispatchTypes } from './userRobotImage/types' export interface State { auth: AuthState @@ -18,6 +21,13 @@ export interface State { userAppData?: UserAppData } +type AppActions = + | AuthDispatchTypes + | MetadataDispatchTypes + | UserRobotImageDispatchTypes + | RelaysDispatchTypes + | UserAppDataDispatchTypes + export const appReducer = combineReducers({ auth: authReducer, metadata: metadataReducer, @@ -26,8 +36,10 @@ export const appReducer = combineReducers({ userAppData: UserAppDataReducer }) -// FIXME: define types -export default (state: any, action: any) => { +export default ( + state: ReturnType | undefined, + action: AppActions +) => { switch (action.type) { case ActionTypes.USER_LOGOUT: return appReducer(undefined, action) diff --git a/src/store/userRobotImage/reducer.ts b/src/store/userRobotImage/reducer.ts index 4235a48..913c2c5 100644 --- a/src/store/userRobotImage/reducer.ts +++ b/src/store/userRobotImage/reducer.ts @@ -1,11 +1,11 @@ import * as ActionTypes from '../actionTypes' -import { MetadataDispatchTypes } from './types' +import { UserRobotImageDispatchTypes } from './types' const initialState: string | null = null const reducer = ( state = initialState, - action: MetadataDispatchTypes + action: UserRobotImageDispatchTypes ): string | null | undefined => { switch (action.type) { case ActionTypes.SET_USER_ROBOT_IMAGE: diff --git a/src/store/userRobotImage/types.ts b/src/store/userRobotImage/types.ts index 05d1475..2bef640 100644 --- a/src/store/userRobotImage/types.ts +++ b/src/store/userRobotImage/types.ts @@ -6,4 +6,4 @@ export interface SetUserRobotImage { payload: string | null } -export type MetadataDispatchTypes = SetUserRobotImage | RestoreState +export type UserRobotImageDispatchTypes = SetUserRobotImage | RestoreState diff --git a/src/utils/relays.ts b/src/utils/relays.ts index 5b79f3d..bfef7aa 100644 --- a/src/utils/relays.ts +++ b/src/utils/relays.ts @@ -6,6 +6,7 @@ import { localCache } from '../services' import { RelayMap, RelaySet } from '../types' import { DEFAULT_LOOK_UP_RELAY_LIST, + ONE_DAY_IN_MS, ONE_WEEK_IN_MS, SIGIT_RELAY } from './const' @@ -56,7 +57,7 @@ const findRelayListInCache = async (hexKey: string): Promise => { // Check if the cached event is not older than one week if ( cachedRelayListMetadataEvent && - isOlderThanOneWeek(cachedRelayListMetadataEvent.cachedAt) + !isOlderThanOneWeek(cachedRelayListMetadataEvent.cachedAt) ) { return cachedRelayListMetadataEvent.event } @@ -88,11 +89,11 @@ const getDefaultRelayMap = (): RelayMap => ({ }) const isOlderThanOneWeek = (cachedAt: number) => { - return Date.now() - cachedAt < ONE_WEEK_IN_MS + return Date.now() - cachedAt > ONE_WEEK_IN_MS } const isOlderThanOneDay = (cachedAt: number) => { - return Date.now() - cachedAt < ONE_WEEK_IN_MS + return Date.now() - cachedAt > ONE_DAY_IN_MS } const isRelayTag = (tag: string[]): boolean => tag[0] === 'r'