Skip to content

Commit

Permalink
feat(TypeScript): move types to data/types
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip London committed Jan 24, 2020
1 parent 353435d commit f32261c
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as AT from './actionTypes'
import { RemoteData } from 'blockchain-wallet-v4/src/remote/types'
import { RemoteDataType } from 'data/types'

export type EmailSmsStepType = 'edit' | 'verify'

Expand Down Expand Up @@ -51,13 +51,13 @@ export type CountryType = {
export interface IdentityVerificationState {
addressRefetchVisible: boolean
emailStep: EmailSmsStepType
flowConfig: RemoteData<string, any>
preIdvData: RemoteData<string, PreIdvDataType>
smsStep: RemoteData<string, EmailSmsStepType>
states: RemoteData<string, StateType>
steps: RemoteData<string, Array<StepsType>>
supportedCountries: RemoteData<string, Array<CountryType>>
supportedDocuments: RemoteData<string, Array<DocumentType>>
flowConfig: RemoteDataType<string, any>
preIdvData: RemoteDataType<string, PreIdvDataType>
smsStep: RemoteDataType<string, EmailSmsStepType>
states: RemoteDataType<string, StateType>
steps: RemoteDataType<string, Array<StepsType>>
supportedCountries: RemoteDataType<string, Array<CountryType>>
supportedDocuments: RemoteDataType<string, Array<DocumentType>>
verificationStep: StepsType | null
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as AT from './actionTypes'
import { NabuApiErrorType } from 'blockchain-wallet-v4/src/network/types'
import { NabuApiErrorType } from 'data/types'
import { ProfileActionTypes } from './types'

export const clearSession = () => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as AT from './actionTypes'
import { AxiosError } from 'axios'
import { CampaignsType } from 'data/components/types'
import { NabuApiErrorType } from 'blockchain-wallet-v4/src/network/types'
import { RemoteData } from 'blockchain-wallet-v4/src/remote/types'
import { CampaignsType, NabuApiErrorType, RemoteDataType } from 'data/types'

// Types

Expand Down Expand Up @@ -134,20 +132,20 @@ export type UserTiersType = Array<UserTierType>

// State
export interface ProfileState {
apiToken: RemoteData<string, string>
apiToken: RemoteDataType<string, string>
campaign: {}
exchangeOnboarding: {
linkFromExchangeAccountStatus: RemoteData<
linkFromExchangeAccountStatus: RemoteDataType<
AxiosError<LinkFromExchangeAccountFailureType>,
string
>
linkToExchangeAccountDeeplink: string | null
linkToExchangeAccountStatus: RemoteData<string, string>
shareWalletAddressesWithExchange: RemoteData<string, string>
linkToExchangeAccountStatus: RemoteDataType<string, string>
shareWalletAddressesWithExchange: RemoteDataType<string, string>
}
userCampaigns: RemoteData<NabuApiErrorType, UserCampaignsType>
userData: RemoteData<NabuApiErrorType, UserDataType>
userTiers: RemoteData<string, UserTiersType>
userCampaigns: RemoteDataType<NabuApiErrorType, UserCampaignsType>
userData: RemoteDataType<NabuApiErrorType, UserDataType>
userTiers: RemoteDataType<string, UserTiersType>
}

// Actions
Expand Down
2 changes: 1 addition & 1 deletion packages/blockchain-wallet-v4-frontend/src/data/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export type AppActionTypes = ComponentsActionTypes | ModuleActionTypes

export * from './components/types'
export * from './modules/types'
export * from 'blockchain-wallet-v4/src/network/types'
export * from 'blockchain-wallet-v4/src'
// Import via `import { AppActionTypes } from 'data/types'`
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { actions, selectors } from 'data'
import { bindActionCreators, compose, Dispatch } from 'redux'
import { connect } from 'react-redux'
import { RemoteData } from 'blockchain-wallet-v4/src/remote/types'
import { UserTiersType } from 'data/types'
import { RemoteDataType, UserTiersType } from 'data/types'
import LinkFromExchangeAccount from './template'
import modalEnhancer from 'providers/ModalEnhancer'
import React from 'react'
Expand All @@ -16,7 +15,7 @@ export type LinkStatePropsType = {
email: string,
emailVerified: boolean,
linkFromExchangeAccountStatus: any,
userTiers: RemoteData<any, UserTiersType>
userTiers: RemoteDataType<any, UserTiersType>
}

export type LinkDispatchPropsType = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { actions, selectors } from 'data'
import { AppActionTypes, NabuApiErrorType, UserCampaignsType, UserDataType } from 'data/types'
import { AppActionTypes, NabuApiErrorType, RemoteDataType, UserCampaignsType, UserDataType } from 'data/types'
import { bindActionCreators, Dispatch } from 'redux'
import { connect } from 'react-redux'
import { FormattedMessage } from 'react-intl'
import { lift } from 'ramda'
import { RemoteData } from 'blockchain-wallet-v4/src/remote/types'
import { RootState } from 'data/rootReducer'
import { Text } from 'blockchain-info-components'
import EmailRequired from 'components/EmailRequired'
Expand Down Expand Up @@ -32,9 +31,9 @@ export const MainTitle = styled(Text)`
`

type LinkStatePropsType = {
data: RemoteData<NabuApiErrorType, UserDataType & UserCampaignsType>,
data: RemoteDataType<NabuApiErrorType, UserDataType & UserCampaignsType>,
hasEmail: boolean,
userData: RemoteData<NabuApiErrorType, UserDataType>
userData: RemoteDataType<NabuApiErrorType, UserDataType>
}

export type LinkDispatchPropsType = {
Expand All @@ -52,7 +51,7 @@ class Airdrops extends React.PureComponent<Props> {
render () {
const { data, hasEmail } = this.props

const AirdropCards = data.cata<NabuApiErrorType, UserDataType & UserCampaignsType>({
const AirdropCards = data.cata({
Success: val => <Success {...val} {...this.props} />,
Loading: () => <Loading />,
NotAsked: () => <Loading />,
Expand All @@ -63,7 +62,7 @@ class Airdrops extends React.PureComponent<Props> {
</Text>
)
})
const PastAirdrops = data.cata<NabuApiErrorType, UserDataType & UserCampaignsType>({
const PastAirdrops = data.cata({
Success: val => <PastAirdropsSuccess {...val} />,
Loading: () => <Text weight={500}>Loading...</Text>,
NotAsked: () => <Text weight={500}>Loading...</Text>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as coreReducers from './redux/reducers'
import * as coreSelectors from './redux/selectors'
import * as crypto from './walletCrypto'
import * as Exchange from './exchange'
import * as Network from './network/index.ts'
import * as Network from './network'
import * as pairing from './pairing'
import * as paths from './redux/paths'
import * as transactions from './transactions'
Expand Down Expand Up @@ -35,3 +35,6 @@ export {
Remote,
utils
}

export * from './network/types'
export * from './remote/types'
6 changes: 3 additions & 3 deletions packages/blockchain-wallet-v4/src/remote/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const cata = function<E, A> (
this: RemoteData<E, A>,
this: RemoteDataType<E, A>,
obj: {
Failure: (error: E) => E | React.ReactNode
Loading: () => React.ReactNode
Expand All @@ -24,7 +24,7 @@ const cata = function<E, A> (
}

const getOrElse = function<A, DV> (
this: RemoteData<any, A>,
this: RemoteDataType<any, A>,
defaultValue: DV
): DV | A {
switch (this['@@tag']) {
Expand Down Expand Up @@ -70,7 +70,7 @@ export type RemoteSuccess<A> = RemoteType & {
readonly data: A
}

export type RemoteData<E, A> =
export type RemoteDataType<E, A> =
| RemoteNotAsked
| RemoteLoading
| RemoteFailure<E>
Expand Down

0 comments on commit f32261c

Please sign in to comment.