fab9f839d0
* Move init time logging to a fn, add guard * Fix email confirmation dialog on startup
37 lines
991 B
TypeScript
37 lines
991 B
TypeScript
import * as persisted from '#/state/persisted'
|
|
import {toHashCode} from 'lib/strings/helpers'
|
|
import {isOnboardingActive} from './onboarding'
|
|
import {SessionAccount} from '../session'
|
|
|
|
export function shouldRequestEmailConfirmation(account: SessionAccount) {
|
|
if (!account) {
|
|
return false
|
|
}
|
|
if (account.emailConfirmed) {
|
|
return false
|
|
}
|
|
if (isOnboardingActive()) {
|
|
return false
|
|
}
|
|
// only prompt once
|
|
if (persisted.get('reminders').lastEmailConfirm) {
|
|
return false
|
|
}
|
|
const today = new Date()
|
|
// shard the users into 2 day of the week buckets
|
|
// (this is to avoid a sudden influx of email updates when
|
|
// this feature rolls out)
|
|
const code = toHashCode(account.did) % 7
|
|
if (code !== today.getDay() && code !== (today.getDay() + 1) % 7) {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
export function setEmailConfirmationRequested() {
|
|
persisted.write('reminders', {
|
|
...persisted.get('reminders'),
|
|
lastEmailConfirm: new Date().toISOString(),
|
|
})
|
|
}
|