diff --git a/src/store/actionTypes.ts b/src/store/actionTypes.ts index ff33627..f0e6698 100644 --- a/src/store/actionTypes.ts +++ b/src/store/actionTypes.ts @@ -18,4 +18,3 @@ export const SET_RELAY_MAP_UPDATED = 'SET_RELAY_MAP_UPDATED' export const UPDATE_USER_APP_DATA = 'UPDATE_USER_APP_DATA' export const UPDATE_PROCESSED_GIFT_WRAPS = 'UPDATE_PROCESSED_GIFT_WRAPS' -export const SET_D_TAG_FOR_APP_DATA = 'SET_D_TAG_FOR_APP_DATA' diff --git a/src/store/userAppData/action.ts b/src/store/userAppData/action.ts index 2164aaa..23bf9a1 100644 --- a/src/store/userAppData/action.ts +++ b/src/store/userAppData/action.ts @@ -1,10 +1,6 @@ import { UserAppData } from '../../types' import * as ActionTypes from '../actionTypes' -import { - SetDTagForAppData, - UpdateProcessedGiftWraps, - UpdateUserAppData -} from './types' +import { UpdateProcessedGiftWraps, UpdateUserAppData } from './types' export const updateUserAppData = (payload: UserAppData): UpdateUserAppData => ({ type: ActionTypes.UPDATE_USER_APP_DATA, @@ -17,8 +13,3 @@ export const updateProcessedGiftWraps = ( type: ActionTypes.UPDATE_PROCESSED_GIFT_WRAPS, payload }) - -export const setDTagForAppData = (payload: string): SetDTagForAppData => ({ - type: ActionTypes.SET_D_TAG_FOR_APP_DATA, - payload -}) diff --git a/src/store/userAppData/reducer.ts b/src/store/userAppData/reducer.ts index dacb375..22c7cb0 100644 --- a/src/store/userAppData/reducer.ts +++ b/src/store/userAppData/reducer.ts @@ -24,12 +24,6 @@ const reducer = ( processedGiftWraps: action.payload } - case ActionTypes.SET_D_TAG_FOR_APP_DATA: - return { - ...state, - dTag: action.payload - } - case ActionTypes.RESTORE_STATE: return action.payload.userAppData || null diff --git a/src/store/userAppData/types.ts b/src/store/userAppData/types.ts index c3de135..07c207f 100644 --- a/src/store/userAppData/types.ts +++ b/src/store/userAppData/types.ts @@ -12,13 +12,7 @@ export interface UpdateProcessedGiftWraps { payload: string[] } -export interface SetDTagForAppData { - type: typeof ActionTypes.SET_D_TAG_FOR_APP_DATA - payload: string -} - export type UserAppDataDispatchTypes = | UpdateUserAppData | UpdateProcessedGiftWraps - | SetDTagForAppData | RestoreState diff --git a/src/utils/nostr.ts b/src/utils/nostr.ts index d65561d..eceb8d8 100644 --- a/src/utils/nostr.ts +++ b/src/utils/nostr.ts @@ -24,7 +24,6 @@ import { relayController } from '../controllers' import { - setDTagForAppData, updateProcessedGiftWraps, updateUserAppData as updateUserAppDataAction } from '../store/actions' @@ -35,6 +34,7 @@ import { Meta, SignedEvent, UserAppData } from '../types' import { getDefaultRelayMap } from './relays' import { parseJson, removeLeadingSlash } from './string' import { timeout } from './utils' +import { getHash } from './hash' /** * Generates a `d` tag for userAppData @@ -49,36 +49,7 @@ const getDTagForUserAppData = async (): Promise => { ) } - let dTag = store.getState().userAppData?.dTag - - // if dTag is found in redux store then just return that - if (dTag) return dTag - - // dTag not found is redux store. Generate it. - const unsignedEvent: UnsignedEvent = { - kind: kinds.ShortTextNote, - pubkey: pubkey, - created_at: 0, - tags: [], - content: `938_${pubkey}` - } - - const nostrController = NostrController.getInstance() - const signedEvent = await nostrController - .signEvent(unsignedEvent) - .catch((err) => { - console.error('Failed to sign event for dTag', err) - toast.error(err.message || err) - return null - }) - if (!signedEvent) return null - - dTag = signedEvent.sig - - // save dTag in redux store - store.dispatch(setDTagForAppData(dTag)) - - return dTag + return getHash(`938_${pubkey}`) } /**