Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable floating promises check everywhere (fix issues) #1115

Merged
merged 4 commits into from
Sep 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"prettier": "1.13.5",
"pretty-quick": "^1.11.1",
"solc": "0.5.8",
"tslint": "^5.12.1",
"tslint": "^5.20.0",
"jest": "^24.8.0",
"ts-jest": "^24.0.2",
"typescript-tslint-plugin": "^0.5.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/celotool/src/lib/cloud-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const createBucketIfNotExists = async (
location: string = 'US-CENTRAL1',
storageClass: string = 'COLDLINE'
) => {
if (!checkBucketExists(client, bucketName)) {
if (!(await checkBucketExists(client, bucketName))) {
await createBucket(client, bucketName, location, storageClass)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class CeloPrivateKeysWalletProvider extends PrivateKeyWalletSubprovider {
const shouldPassToSuperClassForHandling =
!signingRequired || this.canSign(payload.params[0].from)
if (shouldPassToSuperClassForHandling) {
super.handleRequest(payload, next, end)
return super.handleRequest(payload, next, end)
} else {
// Pass it to the next handler to sign
next()
Expand Down
2 changes: 1 addition & 1 deletion packages/faucet/src/database-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export class AccountPool {

for (const key of accountKeys) {
const lockPath = accountsSnap.child(key + '/locked')
if (!lockPath.val() && this.trySetLockField(lockPath.ref)) {
if (!lockPath.val() && (await this.trySetLockField(lockPath.ref))) {
return accountsSnap.child(key)
}
}
Expand Down
8 changes: 5 additions & 3 deletions packages/faucet/src/test-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async function populatePool(pool: fbHelper.AccountPool) {
function fakeAction(pool: fbHelper.AccountPool) {
return pool.doWithAccount(async (account) => {
console.log('GOT Accounts', account)
wait(5000)
await wait(5000)
})
}

Expand Down Expand Up @@ -137,8 +137,10 @@ async function main() {
console.error('Failed')
console.error(err)
} finally {
admin.app().delete()
await admin.app().delete()
}
}

main()
main().catch((err) => {
console.log(err)
})
3 changes: 2 additions & 1 deletion packages/mobile/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"rules": {
"no-relative-imports": true,
"max-classes-per-file": [true, 2],
"no-global-arrow-functions": false
"no-global-arrow-functions": false,
"no-floating-promises": { "severity": "warning"}
}
}
4 changes: 2 additions & 2 deletions packages/notification-service/src/exchange/exchangeQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export async function getExchangeRate(makerToken: CURRENCY_ENUM, web3Instance: W
}

let web3: Web3
export function getWeb3Instance(): Web3 {
if (web3 && web3.eth.net.isListening()) {
export async function getWeb3Instance(): Promise<Web3> {
if (web3 && (await web3.eth.net.isListening())) {
// Already connected
return web3
} else {
Expand Down
22 changes: 9 additions & 13 deletions packages/react-components/analytics/CeloAnalytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,13 @@ class CeloAnalytics {
return
}

try {
const props = this.getProps(eventProperties)
if (attachDeviceInfo) {
_.set(props, 'device', getDeviceInfo())
}
Analytics.track(eventName, props)
} catch (err) {
this.Logger.error(TAG, `Failed to tracking event ${eventName}`, err)
const props = this.getProps(eventProperties)
if (attachDeviceInfo) {
_.set(props, 'device', getDeviceInfo())
}
Analytics.track(eventName, props).catch((err) => {
this.Logger.error(TAG, `Failed to tracking event ${eventName}`, err)
})
}

// Used with trackSubEvent and endTracking to track durations for
Expand Down Expand Up @@ -170,12 +168,10 @@ class CeloAnalytics {
return
}

try {
const props = this.getProps(eventProperties)
Analytics.screen(page, props)
} catch (err) {
const props = this.getProps(eventProperties)
Analytics.screen(page, props).catch((err) => {
this.Logger.error(TAG, 'Error tracking page', err)
}
})
}

applyWhitelist(allProps: {}) {
Expand Down
6 changes: 3 additions & 3 deletions packages/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"build-rules": "tsc"
},
"devDependencies": {
"tslint": "^5.12.1",
"tslint": "^5.20.0",
"tslint-config-prettier": "^1.18.0",
"tslint-eslint-rules": "^5.4.0",
"tslint-microsoft-contrib": "^5.1.0",
"tslint-react": "^3.6.0"
"tslint-microsoft-contrib": "^6.2.0",
"tslint-react": "^4.1.0"
}
}
4 changes: 3 additions & 1 deletion packages/typescript/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"no-inner-declarations": [true, "functions"],
"no-for-in": true,
"void-zero": false,
"no-global-arrow-functions": true
"no-global-arrow-functions": true,
"no-floating-promises": true,
"no-promise-as-boolean": true
}
}
4 changes: 3 additions & 1 deletion packages/verifier/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ const WrappedNavigator = connect<NavigatorStateProps, DispatchProps>(

class App extends React.Component<{}, {}> {
componentDidMount() {
initializeFirebase()
initializeFirebase().catch((err) => {
console.error('Failed to initialize firebase', err)
})
}

hideSplashScreen() {
Expand Down
4 changes: 3 additions & 1 deletion packages/verifier/src/components/HomeScreen/Activity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ export class Activity extends React.Component<Props> {
return
}
this.updateStats(data.rewards)
createMessagePhoneMapping()
createMessagePhoneMapping().catch((err) => {
console.error(`createMessagePhoneMapping() error`, err)
})
}

updateStats = (rewards: Array<RewardTransaction | null>) => {
Expand Down
60 changes: 34 additions & 26 deletions packages/verifier/src/components/HomeScreen/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,24 @@ class HomeScreen extends React.Component<Props, State> {
}

async componentDidMount() {
this.getVerifierStatus()
NetInfo.addEventListener('connectionChange', this.handleNetworkStatusChange)
try {
NetInfo.addEventListener('connectionChange', this.handleNetworkStatusChange)
mcortesi marked this conversation as resolved.
Show resolved Hide resolved
if (!this.props.isVerifying && isVerifyingDisabledLongTime(this.props.verifyingOffAt)) {
setTimeout(() => this.showVerifyingOffLongMessage(), 2000)
}

/**
* Note about FCMToken:
* Because we are getting this from our custom VerifierService, there is no way to subscribe to updates
* To ensure we keep it up to date, we will retrieve it every time the home page mounts
* To avoid this, we would need to add the RN Firebase module for messaging and subscribe to its updates
*/
const fcmToken = await VerifierService.getFCMToken()
setFcmToken(fcmToken)
await this.getVerifierStatus()

if (!this.props.isVerifying && isVerifyingDisabledLongTime(this.props.verifyingOffAt)) {
setTimeout(() => this.showVerifyingOffLongMessage(), 2000)
/**
* Note about FCMToken:
* Because we are getting this from our custom VerifierService, there is no way to subscribe to updates
* To ensure we keep it up to date, we will retrieve it every time the home page mounts
* To avoid this, we would need to add the RN Firebase module for messaging and subscribe to its updates
*/
const fcmToken = await VerifierService.getFCMToken()
await setFcmToken(fcmToken)
} catch (err) {
logger.error('HomeScreen/componentDidMount', err)
}
}

Expand All @@ -119,23 +123,27 @@ class HomeScreen extends React.Component<Props, State> {
this.setState({ networkType: reachability.type })
}

toggleVerifyingService = () => {
const isCurrentlyVerifying = this.props.isVerifying
toggleVerifyingService = async () => {
try {
const isCurrentlyVerifying = this.props.isVerifying

// The actual service that receices the verification texts
VerifierService.toggleVerifierService(!isCurrentlyVerifying)
// The firebase which lets everyone know we are open for business
setIsVerifying(!isCurrentlyVerifying)
// The Local redux state
this.props.setVerificationState(!isCurrentlyVerifying)
// The actual service that receices the verification texts
VerifierService.toggleVerifierService(!isCurrentlyVerifying)
// The firebase which lets everyone know we are open for business
await setIsVerifying(!isCurrentlyVerifying)
// The Local redux state
this.props.setVerificationState(!isCurrentlyVerifying)

// when Turning from On to off, and its the first time (verifyingOffAt never set so null) show message
if (isCurrentlyVerifying && !this.props.verifyingOffAt) {
this.showVerifyingOffLongMessage()
} else {
this.props.clearMessage()
// when Turning from On to off, and its the first time (verifyingOffAt never set so null) show message
if (isCurrentlyVerifying && !this.props.verifyingOffAt) {
this.showVerifyingOffLongMessage()
} else {
this.props.clearMessage()
}
trackVerificationState(isCurrentlyVerifying)
} catch (err) {
logger.error('HomeScreen/toggleVerifyingService', err)
}
trackVerificationState(isCurrentlyVerifying)
}

getVerifierStatus = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SetupAccountScreen extends React.Component<Props, State> {
this.props.setName(name)

const fcmToken = await VerifierService.getFCMToken()
setVerifier({
await setVerifier({
name,
phoneNum: e164Number,
fcmToken,
Expand Down
3 changes: 3 additions & 0 deletions packages/verifier/src/services/Apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ const fragmentMatcher = new IntrospectionFragmentMatcher({

const cache = new InMemoryCache({ fragmentMatcher })

// TODO what should happen if this fails???
persistCache({
cache,
storage: AsyncStorage,
}).catch((err) => {
console.error('Apollo.persistCache error', err)
})

export const apolloClient = new ApolloClient<InMemoryCache>({
Expand Down
12 changes: 6 additions & 6 deletions packages/verifier/src/services/FirebaseDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,29 @@ const getUserUID = () => {
return user.uid
}

export const setVerifier = (newVerifier: Verifier) => {
export const setVerifier = async (newVerifier: Verifier) => {
try {
const uid = getUserUID()
const verifierRef = getVerifierRef(uid)
logger.info(tag, 'Updating verifier in Firebase')
verifierRef.set(newVerifier)
await verifierRef.set(newVerifier)
} catch (error) {
logger.error(tag, 'Failed to save verifier data to FirebaseDb', error)
}
}

export const setIsVerifying = (isVerifying: boolean) => {
export const setIsVerifying = async (isVerifying: boolean) => {
if (!verifier) {
return
}
setVerifier({ ...verifier, isVerifying })
await setVerifier({ ...verifier, isVerifying })
}

export const setFcmToken = (fcmToken: string) => {
export const setFcmToken = async (fcmToken: string) => {
if (!verifier) {
return
}
setVerifier({ ...verifier, fcmToken })
await setVerifier({ ...verifier, fcmToken })
}

const getVerifierRef = (uid: string) => {
Expand Down
Loading