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

Commit

Permalink
Apply 2.0 prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
i1skn committed Apr 25, 2020
1 parent f70091a commit 0ca1ac6
Show file tree
Hide file tree
Showing 40 changed files with 717 additions and 301 deletions.
2 changes: 0 additions & 2 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ module.exports = {
singleQuote: true,
trailingComma: 'all',
semi: false,
printWidth: 100,
arrowParens: 'avoid',
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"react-native-share": "3.2.0",
"react-native-svg": "^12.1.0",
"react-native-swipe-list-view": "^2.3.0",
"react-native-torch": "^1.1.5",
"react-native-touch-id": "^4.4.1",
"react-native-vector-icons": "^6.4.2",
"react-redux": "^7.2.0",
Expand Down
12 changes: 12 additions & 0 deletions sign-with-local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#/bin/sh

if [ -z $1 ]; then
echo "Please provide tx_slate_id"
exit
fi

SLATE_PATH=slates/$1.grinslate

adb pull /data/user/0/app.ironbelly/files/$SLATE_PATH $SLATE_PATH
grin-wallet --floonet -p 1 receive -i $SLATE_PATH
adb push $SLATE_PATH.response /sdcard/Download/
60 changes: 44 additions & 16 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ import TxPostConfirmationModal from 'src/components/TxPostConfirmationModal'
import colors from 'src/common/colors'
import { RootStack, navigationRef } from 'src/modules/navigation'
import { isAndroid } from 'src/common'
import { MAINNET_CHAIN, MAINNET_API_SECRET, FLOONET_API_SECRET } from 'src/modules/settings'
import {
MAINNET_CHAIN,
MAINNET_API_SECRET,
FLOONET_API_SECRET,
} from 'src/modules/settings'
import { State as ToasterState } from 'src/modules/toaster'
import { State as CurrencyRatesState } from 'src/modules/currency-rates'
const { GrinBridge } = NativeModules // Filesystem
Expand Down Expand Up @@ -115,21 +119,23 @@ class RealApp extends React.Component<Props, State> {
})
} else {
Linking.getInitialURL()
.then(url => {
.then((url) => {
if (url) {
this._handleOpenURL({
url,
})
}
})
.catch(err => console.error('An error occurred', err))
.catch((err) => console.error('An error occurred', err))
}

Linking.addEventListener('url', this._handleOpenURL)
AppState.addEventListener('change', this._handleAppStateChange)
checkApiSecret(() => {
this.props.setApiSecret(
this.props.chain === MAINNET_CHAIN ? MAINNET_API_SECRET : FLOONET_API_SECRET,
this.props.chain === MAINNET_CHAIN
? MAINNET_API_SECRET
: FLOONET_API_SECRET,
)
})
// this.backHandler = BackHandler.addEventListener('hardwareBackPress', this._handleBackPress)
Expand All @@ -155,7 +161,7 @@ class RealApp extends React.Component<Props, State> {

_handleOpenURL = (event: { url: string }) => {
// const { setFromLink } = this.props
isWalletInitialized().then(async exists => {
isWalletInitialized().then(async (exists) => {
if (exists) {
if (isAndroid) {
try {
Expand Down Expand Up @@ -187,13 +193,20 @@ class RealApp extends React.Component<Props, State> {
// setFromLink(amount, message, destination)
// }
// }
} else if (link.protocol && ['file:'].indexOf(link.protocol) !== -1 && link.path) {
} else if (
link.protocol &&
['file:'].indexOf(link.protocol) !== -1 &&
link.path
) {
const path = isAndroid ? decodeURIComponent(link.path) : link.path
store.dispatch({
type: 'SLATE_LOAD_REQUEST',
slatePath: path,
})
} else if (link.protocol && ['content:'].indexOf(link.protocol) !== -1) {
} else if (
link.protocol &&
['content:'].indexOf(link.protocol) !== -1
) {
// Copy the file, because we can not operate on content://
// from inside rust code
const url = event.url
Expand All @@ -213,7 +226,7 @@ class RealApp extends React.Component<Props, State> {
const { sharingInProgress } = this.props

if (nextAppState === 'background' && !sharingInProgress) {
isWalletInitialized().then(async exists => {
isWalletInitialized().then(async (exists) => {
if (exists) {
store.dispatch({
type: 'CLEAR_PASSWORD',
Expand All @@ -233,9 +246,13 @@ class RealApp extends React.Component<Props, State> {
// @ts-ignore
this.refs.toast.timer && clearTimeout(this.refs.toast.timer)
// @ts-ignore
this.refs.toast.show(this.props.toastMessage.text, this.props.toastMessage.duration, () => {
this.props.clearToast()
})
this.refs.toast.show(
this.props.toastMessage.text,
this.props.toastMessage.duration,
() => {
this.props.clearToast()
},
)
} else {
// @ts-ignore
if (this.refs.toast.state.isShow) {
Expand All @@ -247,7 +264,8 @@ class RealApp extends React.Component<Props, State> {
}
}

const sinceLastCurrencyRatesUpdate = Date.now() - this.props.currencyRates.lastUpdated
const sinceLastCurrencyRatesUpdate =
Date.now() - this.props.currencyRates.lastUpdated

if (
sinceLastCurrencyRatesUpdate > 5 * 60 * 1000 &&
Expand All @@ -259,13 +277,20 @@ class RealApp extends React.Component<Props, State> {
}

render() {
const { walletCreated, scanInProgress, closeTxPostModal, isPasswordValid } = this.props
const {
walletCreated,
scanInProgress,
closeTxPostModal,
isPasswordValid,
} = this.props
if (walletCreated === null) {
return null
}
return (
<React.Fragment>
<Modal isVisible={this.props.showTxConfirmationModal} onBackdropPress={closeTxPostModal}>
<Modal
isVisible={this.props.showTxConfirmationModal}
onBackdropPress={closeTxPostModal}>
<TxPostConfirmationModal />
</Modal>
<NavigationContainer ref={navigationRef} theme={appTheme}>
Expand Down Expand Up @@ -302,7 +327,7 @@ const mapStateToProps = (state: GlobalState): StateProps => {

const RealAppConnected = connect<StateProps, DispatchProps, {}, GlobalState>(
mapStateToProps,
dispatch => ({
(dispatch) => ({
requestWalletExists: () =>
dispatch({
type: 'WALLET_EXISTS_REQUEST',
Expand Down Expand Up @@ -347,7 +372,10 @@ export default class App extends Component<
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<RealAppConnected slateUrl={this.props.url} dispatch={store.dispatch} />
<RealAppConnected
slateUrl={this.props.url}
dispatch={store.dispatch}
/>
</PersistGate>
</Provider>
)
Expand Down
28 changes: 19 additions & 9 deletions src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ export const hrFiat = (amount: number, currency: Currency): string => {
minimumFractionDigits: currency.fractionDigits,
}).format(amount)
}
export const convertToFiat = (amount: number, currency: Currency, rates: object): number => {
export const convertToFiat = (
amount: number,
currency: Currency,
rates: object,
): number => {
const multiplier = rates[currency.code.toLowerCase()]
return (amount / 1000000000) * (multiplier || 0)
}
Expand Down Expand Up @@ -85,7 +89,9 @@ export const mapRustBalance = (rB: RustBalance): Balance => {
total: parseInt(rB.total, 10),
}
}
export const mapRustOutputStrategy = (oS: RustOutputStrategy): OutputStrategy => {
export const mapRustOutputStrategy = (
oS: RustOutputStrategy,
): OutputStrategy => {
return {
total: oS.total,
fee: oS.fee,
Expand Down Expand Up @@ -113,9 +119,10 @@ export const SLATES_DIRECTORY = RNFS.DocumentDirectoryPath + '/slates'
export const APPLICATION_SUPPORT_DIRECTORY = isAndroid
? RNFS.DocumentDirectoryPath
: RNFS.LibraryDirectoryPath + '/Application Support'
export const WALLET_DATA_DIRECTORY = APPLICATION_SUPPORT_DIRECTORY + '/wallet_data'
export const WALLET_DATA_DIRECTORY =
APPLICATION_SUPPORT_DIRECTORY + '/wallet_data'
export const checkSlatesDirectory = () => {
RNFS.exists(SLATES_DIRECTORY).then(exists => {
RNFS.exists(SLATES_DIRECTORY).then((exists) => {
if (!exists) {
RNFS.mkdir(SLATES_DIRECTORY, {
NSURLIsExcludedFromBackupKey: true,
Expand All @@ -128,7 +135,7 @@ export const checkSlatesDirectory = () => {
export const FILE_TRANSPORT_METHOD = 'file'
export const HTTP_TRANSPORT_METHOD = 'http'
export const checkApplicationSupportDirectory = () => {
RNFS.exists(APPLICATION_SUPPORT_DIRECTORY).then(exists => {
RNFS.exists(APPLICATION_SUPPORT_DIRECTORY).then((exists) => {
if (!exists) {
RNFS.mkdir(APPLICATION_SUPPORT_DIRECTORY, {
NSURLIsExcludedFromBackupKey: true,
Expand All @@ -139,7 +146,7 @@ export const checkApplicationSupportDirectory = () => {
})
}
export const checkWalletDataDirectory = () => {
return RNFS.exists(WALLET_DATA_DIRECTORY).then(exists => {
return RNFS.exists(WALLET_DATA_DIRECTORY).then((exists) => {
if (!exists) {
return RNFS.mkdir(WALLET_DATA_DIRECTORY, {
NSURLIsExcludedFromBackupKey: true,
Expand All @@ -153,7 +160,7 @@ export const checkWalletDataDirectory = () => {
}
export const checkApiSecret = (cb: () => void) => {
const apiSecretFilePath = APPLICATION_SUPPORT_DIRECTORY + '/.api_secret'
RNFS.exists(apiSecretFilePath).then(exists => {
RNFS.exists(apiSecretFilePath).then((exists) => {
if (!exists) {
cb()
}
Expand All @@ -175,7 +182,9 @@ export const isResponseSlate = async (slate: any) => {
}
}
export const getSlatePath = (slateId: string, isResponse: boolean) => {
return `${SLATES_DIRECTORY}/${slateId}.grinslate${isResponse ? '.response' : ''}`
return `${SLATES_DIRECTORY}/${slateId}.grinslate${
isResponse ? '.response' : ''
}`
}
export const TextareaTitle = styled.Text`
font-size: 20;
Expand Down Expand Up @@ -253,7 +262,8 @@ export const parseSendLink = (query: UrlQuery) => {
}
}
export const formatDate = (date: moment) => date.format('DD MMMM YYYY')
export const formatTime = (time: moment) => time.format('dddd, DD MMMM YYYY, HH:mm')
export const formatTime = (time: moment) =>
time.format('dddd, DD MMMM YYYY, HH:mm')
export const currencyList = [
{
code: 'btc',
Expand Down
5 changes: 4 additions & 1 deletion src/common/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { store } from 'src/common/redux'
export const log = (e: Error | { message: string }, showToUser: boolean = false) => {
export const log = (
e: Error | { message: string },
showToUser: boolean = false,
) => {
if (!(e instanceof Error) && e.message) {
e = new Error(e.message)
}
Expand Down
3 changes: 2 additions & 1 deletion src/common/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export const migrations = {
settings: {
...state.settings,
checkNodeApiHttpAddr:
state.settings.checkNodeApiHttpAddr === 'http://grinnode.cycle42.com:23413'
state.settings.checkNodeApiHttpAddr ===
'http://grinnode.cycle42.com:23413'
? MAINNET_DEFAULT_NODE
: state.settings.checkNodeApiHttpAddr,
},
Expand Down
49 changes: 39 additions & 10 deletions src/common/redux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,26 @@ import { Epic, combineEpics, createEpicMiddleware } from 'redux-observable'
import { appEpic, appReducer } from 'src/modules/app'
import { catchError } from 'rxjs/operators'
import { reducer as balanceReducer } from 'src/modules/balance'
import { reducer as txReducer, sideEffects as txSideEffects } from 'src/modules/tx'
import { reducer as settingsReducer, sideEffects as settingsEffects } from 'src/modules/settings'
import {
reducer as txReducer,
sideEffects as txSideEffects,
} from 'src/modules/tx'
import {
reducer as settingsReducer,
sideEffects as settingsEffects,
} from 'src/modules/settings'
import {
reducer as currencyRates,
sideEffects as currencyRatesEffects,
} from 'src/modules/currency-rates'
import { reducer as toasterReducer, sideEffects as toasterEffects } from 'src/modules/toaster'
import { reducer as walletReducer, sideEffects as walletEffects } from 'src/modules/wallet'
import {
reducer as toasterReducer,
sideEffects as toasterEffects,
} from 'src/modules/toaster'
import {
reducer as walletReducer,
sideEffects as walletEffects,
} from 'src/modules/wallet'
import { State, Action } from 'src/common/types'
import { createStore, applyMiddleware } from 'redux'
import { createMigrate, persistStore, persistReducer } from 'redux-persist'
Expand Down Expand Up @@ -55,16 +67,26 @@ const currencyRatesConfig = {
}

export const rootReducer = combineReducers<State, Action>({
balance: persistReducer(balanceConfig, balanceReducer) as typeof balanceReducer,
balance: persistReducer(
balanceConfig,
balanceReducer,
) as typeof balanceReducer,
app: persistReducer(appConfig, appReducer) as typeof appReducer,
tx: txReducer,
currencyRates: persistReducer(currencyRatesConfig, currencyRates) as typeof currencyRates,
currencyRates: persistReducer(
currencyRatesConfig,
currencyRates,
) as typeof currencyRates,
settings: settingsReducer,
toaster: toasterReducer,
wallet: walletReducer,
}) as () => State

export const rootEpic: Epic<Action, Action, State> = (action$, store$, dependencies) =>
export const rootEpic: Epic<Action, Action, State> = (
action$,
store$,
dependencies,
) =>
combineEpics(appEpic)(action$, store$, dependencies).pipe(
catchError((error, source) => {
console.error(error)
Expand Down Expand Up @@ -96,10 +118,17 @@ const persistConfig = {

const enhancers = [applyMiddleware(sideEffectsMiddleware, epicMiddleware)]

const composeEnhancers = (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
const composeEnhancers =
(window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose

const persistedReducer = persistReducer<State, Action>(persistConfig, rootReducer)
export const store = createStore(persistedReducer, composeEnhancers(...enhancers))
const persistedReducer = persistReducer<State, Action>(
persistConfig,
rootReducer,
)
export const store = createStore(
persistedReducer,
composeEnhancers(...enhancers),
)
export const persistor = persistStore(store)

epicMiddleware.run(rootEpic)
8 changes: 4 additions & 4 deletions src/common/sideEffects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const isAction = (o: any): boolean => {
return !!o?.type
}

export const createMiddleware = (effects: Effects) => (store: Store) => (next: any) => (
action: Action,
) => {
export const createMiddleware = (effects: Effects) => (store: Store) => (
next: any,
) => (action: Action) => {
const initAction = next(action)
const effect = effects[action.type]

Expand All @@ -34,7 +34,7 @@ export const createMiddleware = (effects: Effects) => (store: Store) => (next: a
if (isAction(result)) {
store.dispatch(result)
} else if (result instanceof Promise) {
result.then(res => isAction(res) && store.dispatch(res))
result.then((res) => isAction(res) && store.dispatch(res))
}
}

Expand Down
Loading

0 comments on commit 0ca1ac6

Please sign in to comment.