Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
[Reloaded] No more useDispatchWeb, messages C-1089 (#1927)
Browse files Browse the repository at this point in the history
* dispatch

* no more use dispatch web or messages

* fixes

* reorg

Co-authored-by: Nikki Kang <kangaroo233@gmail.com>
  • Loading branch information
nicoback2 and nicoback committed Sep 15, 2022
1 parent 6fc8709 commit 2fd28e4
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 410 deletions.
1 change: 0 additions & 1 deletion packages/common/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './remote-config'
export * from './RandomImage'
export * from './native-mobile-interface'
export * from './audius-api-client'
export * from './audius-backend'
export * from './fingerprint'
Expand Down

This file was deleted.

113 changes: 0 additions & 113 deletions packages/common/src/services/native-mobile-interface/types.ts

This file was deleted.

19 changes: 9 additions & 10 deletions packages/mobile/src/components/oauth/OAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import {
getMessageType
} from 'app/store/oauth/selectors'
import type { Credentials } from 'app/store/oauth/types'

const AUTH_RESPONSE = 'auth-response'
import { AUTH_RESPONSE_MESSAGE_TYPE } from 'app/store/oauth/types'

const IDENTITY_SERVICE = Config.IDENTITY_SERVICE

Expand All @@ -27,7 +26,7 @@ const TWITTER_POLLER = `
const exit = () => {
window.ReactNativeWebView.postMessage(
JSON.stringify({
type: '${AUTH_RESPONSE}'
type: '${AUTH_RESPONSE_MESSAGE_TYPE}'
})
)
}
Expand All @@ -47,7 +46,7 @@ const TWITTER_POLLER = `
window.ReactNativeWebView.postMessage(
JSON.stringify({
type: '${AUTH_RESPONSE}',
type: '${AUTH_RESPONSE_MESSAGE_TYPE}',
oauthToken,
oauthVerifier
})
Expand All @@ -70,7 +69,7 @@ const INSTAGRAM_POLLER = `
const exit = () => {
window.ReactNativeWebView.postMessage(
JSON.stringify({
type: '${AUTH_RESPONSE}'
type: '${AUTH_RESPONSE_MESSAGE_TYPE}'
})
)
}
Expand All @@ -88,7 +87,7 @@ const INSTAGRAM_POLLER = `
window.ReactNativeWebView.postMessage(
JSON.stringify({
type: '${AUTH_RESPONSE}',
type: '${AUTH_RESPONSE_MESSAGE_TYPE}',
instagramCode
})
)
Expand All @@ -110,7 +109,7 @@ const TIKTOK_POLLER = `
const exit = (error) => {
window.ReactNativeWebView.postMessage(
JSON.stringify({
type: '${AUTH_RESPONSE}',
type: '${AUTH_RESPONSE_MESSAGE_TYPE}',
error: error.message
})
)
Expand Down Expand Up @@ -144,7 +143,7 @@ const TIKTOK_POLLER = `
window.ReactNativeWebView.postMessage(
JSON.stringify({
type: '${AUTH_RESPONSE}',
type: '${AUTH_RESPONSE_MESSAGE_TYPE}',
accessToken: access_token,
openId: open_id,
expiresIn: expires_in
Expand Down Expand Up @@ -191,7 +190,7 @@ const OAuth = () => {
if (event.nativeEvent.data) {
const data = JSON.parse(event.nativeEvent.data)

if (data.type === AUTH_RESPONSE) {
if (data.type === AUTH_RESPONSE_MESSAGE_TYPE) {
const payloadByProvider = {
[Provider.TWITTER]: (message: any) =>
message.oauthToken && message.oauthVerifier
Expand All @@ -218,7 +217,7 @@ const OAuth = () => {
}
}

const isNativeOAuth = !messageType && !messageId
const isNativeOAuth = !messageType && !messageId // i.e. if the Oauth flow occured in a native app (e.g. the Tiktok app) instead of a webview
const payload = payloadByProvider[provider as Provider](data)

if (isNativeOAuth) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import {
shareSoundToTiktokModalSelectors
} from '@audius/common'
import { StyleSheet, View } from 'react-native'
import { useSelector } from 'react-redux'
import { useSelector, useDispatch } from 'react-redux'

import IconTikTok from 'app/assets/images/iconTikTok.svg'
import IconTikTokInverted from 'app/assets/images/iconTikTokInverted.svg'
import Button from 'app/components/button'
import { AppDrawer, useDrawerState } from 'app/components/drawer'
import LoadingSpinner from 'app/components/loading-spinner'
import Text from 'app/components/text'
import { useDispatchWeb } from 'app/hooks/useDispatchWeb'
import type { ThemeColors } from 'app/hooks/useThemedStyles'
import { useThemedStyles } from 'app/hooks/useThemedStyles'
import { useTikTokAuth } from 'app/hooks/useTikTokAuth'
Expand Down Expand Up @@ -89,7 +88,7 @@ export const ShareToTikTokDrawer = () => {

const { onClose } = useDrawerState(MODAL_NAME)

const dispatchWeb = useDispatchWeb()
const dispatchWeb = useDispatch()

const track = useSelector(getTrack)
const status = useSelector(getStatus)
Expand Down
11 changes: 0 additions & 11 deletions packages/mobile/src/hooks/useDispatchWeb.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/mobile/src/message/index.ts

This file was deleted.

98 changes: 0 additions & 98 deletions packages/mobile/src/message/types.ts

This file was deleted.

5 changes: 2 additions & 3 deletions packages/mobile/src/store/oauth/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { MessageType } from 'app/message'

import type { OAuthActions } from './actions'
import {
NATIVE_OPEN_POPUP,
Expand All @@ -10,6 +8,7 @@ import {
SET_INSTAGRAM_ERROR,
RESET_OAUTH_STATE
} from './actions'
import type { AUTH_RESPONSE_MESSAGE_TYPE } from './types'

type TwitterInfo = {
uuid: any
Expand All @@ -32,7 +31,7 @@ export type OAuthState = {
isOpen: boolean
// Incoming message id to reply back to with OAuth results
messageId: string | null
messageType: MessageType | null
messageType: typeof AUTH_RESPONSE_MESSAGE_TYPE | null
url: string | null
provider: Provider | null
twitterInfo: TwitterInfo | null
Expand Down
2 changes: 2 additions & 0 deletions packages/mobile/src/store/oauth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ export type Credentials = (
) & {
error?: string
}

export const AUTH_RESPONSE_MESSAGE_TYPE = 'auth-response' as const

0 comments on commit 2fd28e4

Please sign in to comment.