Skip to content

Commit

Permalink
Fix verified check because of identity time drift (#6306)
Browse files Browse the repository at this point in the history
Co-authored-by: Alec Savvy <alecsavvy@outlook.com>
  • Loading branch information
raymondjacobson and alecsavvy authored Oct 14, 2023
1 parent b2664f1 commit 8346630
Showing 1 changed file with 59 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,71 @@ export default async ({ user_id, blocknumber }) => {
db: dp_db
})

const user_became_verified = current.is_verified !== old.is_verified
const new_user_is_verified = old === undefined && current.is_verified
console.log({ current, old, user_id, blocknumber })

if (user_became_verified || new_user_is_verified) {
if (current === undefined) {
console.warn(
{ user_id, blocknumber },
'user does not have a current record'
)
return
}

const is_new_user = old === undefined
const new_user_is_verified = is_new_user && current.is_verified
const is_existing_user = !is_new_user
const existing_user_previously_unverified =
is_existing_user && old.is_verified === false
const user_currently_verified = current.is_verified === true
const existing_user_became_verified =
user_currently_verified && existing_user_previously_unverified

console.log({
user_id,
existing_user_became_verified,
new_user_is_verified,
is_new_user,
is_existing_user
})

if (existing_user_became_verified || new_user_is_verified) {
const is_verified = current.is_verified
const handle = current.handle

const data = await retry(
async (_) => {
const { data } = await axios
.get(social_handle_url(handle))
.catch(console.error)

if (Object.keys(data).length === 0) {
// wait for identity to load
await new Promise((resolve) => {
setTimeout(resolve, 1000)
})
throw new Error('social handles not in identity yet')
}
let source
try {
const data = await retry(
async (_) => {
const { data } = await axios
.get(social_handle_url(handle))
.catch(console.error)

return data
},
{ retries: 5 }
)
if (Object.keys(data).length === 0) {
// wait for identity to load
await new Promise((resolve) => {
setTimeout(resolve, 5000)
})
throw new Error('social handles not in identity yet')
}

const { twitterVerified, instagramVerified, tikTokVerified } = data
return data
},
{ retries: 100 }
)
const { twitterVerified, instagramVerified, tikTokVerified } = data

let source = 'unknown'
if (twitterVerified) {
source = 'twitter'
}
if (instagramVerified) {
source = 'instagram'
}
if (tikTokVerified) {
source = 'tiktok'
if (twitterVerified) {
source = 'twitter'
}
if (instagramVerified) {
source = 'instagram'
}
if (tikTokVerified) {
source = 'tiktok'
}
} catch (e) {
source = 'could not figure out source!'
console.error(e)
}

const header = `User *${handle}* ${
Expand All @@ -79,7 +107,7 @@ export default async ({ user_id, blocknumber }) => {
source
}

console.log({ to_slack: body }, 'sending to slack')
console.log({ to_slack: body }, 'user verification')
await slack.sendMsg(USERS_SLACK_CHANNEL, header, body).catch(console.error)
}
}

0 comments on commit 8346630

Please sign in to comment.