forked from OneKeyHQ/app-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/OK-11407, OK-11411 push notification (OneKeyHQ#1333)
* feat: push-notification UI fix: first ask notification permission bug feat: access jpush for ios feat: OK-11407, OK-11411 push notification * fix: desktop build faild * fix: lint * feat: use NotificationProvider for push notification init * feat: add jpush env * feat: use enableTestFiatEndpoint for push notification
- Loading branch information
Showing
29 changed files
with
865 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import axios from 'axios'; | ||
|
||
import { appSelector } from '@onekeyhq/kit/src/store'; | ||
import { SettingsState } from '@onekeyhq/kit/src/store/reducers/settings'; | ||
import { getDefaultLocale } from '@onekeyhq/kit/src/utils/locale'; | ||
import debugLogger from '@onekeyhq/shared/src/logger/debugLogger'; | ||
|
||
import { getFiatEndpoint } from '../endpoint'; | ||
|
||
type PartialNotificationType = Partial<SettingsState['pushNotification']> & { | ||
instanceId?: string; | ||
}; | ||
|
||
async function fetchData<T>( | ||
path: string, | ||
body: Record<string, unknown> = {}, | ||
fallback: T, | ||
): Promise<T> { | ||
const endpoint = getFiatEndpoint(); | ||
const apiUrl = `${endpoint}${path}`; | ||
try { | ||
debugLogger.common.debug(`syncPushNotificationConfig`, { | ||
apiUrl, | ||
body, | ||
}); | ||
const { data } = await axios.put<T>(apiUrl, body); | ||
return data; | ||
} catch (error) { | ||
debugLogger.common.error(`fetch ${apiUrl} error`); | ||
return fallback; | ||
} | ||
} | ||
|
||
export const syncPushNotificationConfig = | ||
async (): Promise<PartialNotificationType> => { | ||
const config: PartialNotificationType = appSelector((state) => ({ | ||
...(state?.settings?.pushNotification || {}), | ||
instanceId: state?.settings?.instanceId, | ||
locale: | ||
state.settings.locale === 'system' | ||
? getDefaultLocale() | ||
: state.settings.locale, | ||
currency: state.settings.selectedFiatMoneySymbol, | ||
})); | ||
if (!config.instanceId || !config.registrationId) { | ||
return {}; | ||
} | ||
return fetchData('/notification/config', config, {}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.