Skip to content

Commit

Permalink
Merge branch 'main' into update-twomba-toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
SirSaltyy authored Sep 26, 2024
2 parents e428886 + ca9e2b3 commit 873c6b4
Show file tree
Hide file tree
Showing 26 changed files with 231 additions and 304 deletions.
16 changes: 9 additions & 7 deletions backend/api/src/gidx/callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ export const paymentCallbackGIDX: APIHandler<'payment-callback-gidx'> = async (
limit 1`,
[MerchantTransactionID],
(row) =>
({
userId: row.user_id as string,
amount: row.amount as number,
currency: row.currency as string,
paymentMethodType: row.payment_method_type as string,
paymentAmountType: row.payment_amount_type as string,
} as PaymentCompletedData | null)
row
? ({
userId: row.user_id as string,
amount: row.amount as number,
currency: row.currency as string,
paymentMethodType: row.payment_method_type as string,
paymentAmountType: row.payment_amount_type as string,
} as PaymentCompletedData)
: null
)
log('userId for payment', paymentData)

Expand Down
5 changes: 3 additions & 2 deletions backend/api/src/gidx/complete-checkout-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const completeCheckoutSession: APIHandler<
if (paymentAmount.newUsersOnly) {
if (Date.now() > introductoryTimeWindow(user))
throw new APIError(403, 'New user purchase discount no longer offered.')
if (user.purchasedMana)
if (user.purchasedSweepcash)
throw new APIError(403, 'New user purchase discount only available once.')
}

Expand Down Expand Up @@ -165,7 +165,7 @@ export const completeCheckoutSession: APIHandler<
} else if (PaymentStatusCode === '3') {
return {
status: 'error',
message: 'Payment failed',
message: 'Payment failed, check your card information.',
gidxMessage: PaymentStatusMessage,
}
} else if (PaymentStatusCode === '4') {
Expand Down Expand Up @@ -241,6 +241,7 @@ const sendCoins = async (
}
await updateUser(tx, userId, {
purchasedMana: true,
purchasedSweepcash: isSweepsVerified,
})
})
}
14 changes: 8 additions & 6 deletions backend/api/src/gidx/register.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APIError, APIHandler } from 'api/helpers/endpoint'
import { getUserAndPrivateUserOrThrow, LOCAL_DEV, log } from 'shared/utils'
import { getUser, LOCAL_DEV, log } from 'shared/utils'
import { updateUser } from 'shared/supabase/users'
import { createSupabaseDirectClient } from 'shared/supabase/init'
import {
Expand Down Expand Up @@ -34,8 +34,10 @@ export const register: APIHandler<'register-gidx'> = async (
if (!EmailAddress) {
throw new APIError(400, 'User must have an email address')
}
const pg = createSupabaseDirectClient()
const body = {
EmailAddress,
CountryCode: 'US',
MobilePhoneNumber: ENABLE_FAKE_CUSTOMER
? props.MobilePhoneNumber
: parsePhoneNumber(phoneNumberWithCode)?.nationalNumber ??
Expand All @@ -60,9 +62,10 @@ export const register: APIHandler<'register-gidx'> = async (
if (!res.ok) {
throw new APIError(400, 'GIDX registration failed')
}
const pg = createSupabaseDirectClient()
const userAndPrivateUser = await getUserAndPrivateUserOrThrow(auth.uid, pg)
const { user } = userAndPrivateUser
const user = await getUser(auth.uid)
if (!user) {
throw new APIError(404, 'User not found')
}
const data = (await res.json()) as GIDXRegistrationResponse
log('Registration response:', data)
const {
Expand All @@ -74,7 +77,7 @@ export const register: APIHandler<'register-gidx'> = async (
} = data
throwIfIPNotWhitelisted(ResponseCode, ResponseMessage)
const { status, message, idVerified } = await verifyReasonCodes(
userAndPrivateUser,
{ user, privateUser },
ReasonCodes,
FraudConfidenceScore,
IdentityConfidenceScore
Expand All @@ -89,7 +92,6 @@ export const register: APIHandler<'register-gidx'> = async (
track(auth.uid, 'register user gidx attempt', {
status,
message,
citizenshipCountryCode: body.CitizenshipCountryCode,
idVerified,
})
return {
Expand Down
6 changes: 3 additions & 3 deletions backend/shared/src/gidx/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { APIError } from 'common/api/utils'
import {
FRAUD_THRESHOLD,
GIDXCustomerProfile,
ID_ERROR_MSG,
IDENTITY_THRESHOLD,
} from 'common/gidx/gidx'
import { getPrivateUserSupabase, getUser, isProd, log } from 'shared/utils'
Expand Down Expand Up @@ -238,8 +239,7 @@ export const verifyReasonCodes = async (
}
return {
status: 'error',
message:
'Confidence in identity too low. Double check your information or upload documents to verify your identity.',
message: ID_ERROR_MSG,
idVerified,
}
}
Expand All @@ -249,7 +249,7 @@ export const verifyReasonCodes = async (
FraudConfidenceScore < FRAUD_THRESHOLD
) {
log(
'Registration failed, resulted in low fraud confidence score:',
'Registration activity suspicious, resulted in low fraud confidence score:',
FraudConfidenceScore
)
if (privateUser.sessionFraudScore !== FraudConfidenceScore) {
Expand Down
24 changes: 11 additions & 13 deletions common/src/gidx/gidx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ export const verificationParams = z.object({
LastName: z.string(),
DeviceGPS: GPSProps,
DateOfBirth: z.string(),
CitizenshipCountryCode: z.string(),
// Must supply address or ID info
AddressLine1: z.string().optional(),
// Must supply address atm, but we could also use ID info
AddressLine1: z.string(),
AddressLine2: z.string().optional(),
City: z.string().optional(),
StateCode: z.string().optional(),
PostalCode: z.string().optional(),
CountryCode: z.string().optional(),
City: z.string(),
StateCode: z.string(),
PostalCode: z.string(),
IdentificationTypeCode: z.number().gte(1).lte(4).optional(),
IdentificationNumber: z.string().optional(),
EmailAddress: z.string().optional(),
Expand Down Expand Up @@ -290,10 +288,10 @@ export type CheckoutSessionResponse = {
} & CheckoutSession

export const ID_ERROR_MSG =
'Registration failed, identity error. Check your identifying information.'
'Confidence in identity too low. Double check your information or upload documents to verify your identity.'

export const IDENTITY_THRESHOLD = 80
export const FRAUD_THRESHOLD = 80
export const FRAUD_THRESHOLD = 60
export const ENABLE_FAKE_CUSTOMER = false
export const exampleCustomers = [
{
Expand All @@ -303,7 +301,7 @@ export const exampleCustomers = [
FirstName: 'Adam',
LastName: 'Gibbs',
DateOfBirth: '01/11/1979',
CitizenshipCountryCode: 'GB',
CountryCode: 'GB',
IdentificationTypeCode: 2,
IdentificationNumber: '123456789',
AddressLine1: '133 Hall Road',
Expand All @@ -326,7 +324,7 @@ export const exampleCustomers = [
FirstName: 'Corey',
LastName: 'Chandler',
DateOfBirth: '09/28/1987',
CitizenshipCountryCode: 'US',
CountryCode: 'US',
IdentificationTypeCode: 2,
IdentificationNumber: '123456789',
AddressLine1: '66 Forest Street',
Expand Down Expand Up @@ -359,7 +357,7 @@ export const exampleCustomers = [
FirstName: 'Andrew',
LastName: 'Siegfried',
DateOfBirth: '01/27/1978',
CitizenshipCountryCode: 'US',
CountryCode: 'US',
IdentificationTypeCode: 2,
IdentificationNumber: '123456789',
AddressLine1: '321 Greenwood Lane',
Expand All @@ -382,7 +380,7 @@ export const exampleCustomers = [
FirstName: 'Antron',
LastName: 'Hurt',
DateOfBirth: '11/06/1986',
CitizenshipCountryCode: 'US',
CountryCode: 'US',
IdentificationTypeCode: 2,
IdentificationNumber: '123456789',
AddressLine1: '214 Rosemont Ave',
Expand Down
10 changes: 8 additions & 2 deletions common/src/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { notification_preferences } from './user-notification-preferences'
import { ENV_CONFIG } from './envs/constants'
import { HOUR_MS } from './util/time'
import { DAY_MS, HOUR_MS } from './util/time'

export type User = {
id: string
Expand Down Expand Up @@ -68,6 +68,7 @@ export type User = {
signupBonusPaid?: number
isAdvancedTrader?: boolean
purchasedMana?: boolean
purchasedSweepcash?: boolean
verifiedPhone?: boolean

// KYC related fields:
Expand Down Expand Up @@ -152,5 +153,10 @@ export const isUserLikelySpammer = (
// This grandfathers in older users who have not yet verified their phone
export const humanish = (user: User) => user.verifiedPhone !== false

// expires: sep 26th, ~530pm PT
const LIMITED_TIME_DEAL_END = 1727311753233 + DAY_MS
export const introductoryTimeWindow = (user: User) =>
(user.sweepstakesVerifiedTime ?? user.createdTime) + 8 * HOUR_MS
Math.max(
LIMITED_TIME_DEAL_END,
(user.sweepstakesVerifiedTime ?? user.createdTime) + 8 * HOUR_MS
)
5 changes: 2 additions & 3 deletions web/components/bet/bet-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ export const BuyPanelBody = (props: {
isBinaryMC && multiProps
? multiProps.answerText ?? multiProps.answerToBuy.text
: undefined

const initialBetAmount = marketTier === 'play' ? 5 : 50
const isCashContract = contract.token === 'CASH'
const initialBetAmount = isCashContract ? 1 : marketTier === 'play' ? 5 : 50

const [betAmount, setBetAmount] = useState<number | undefined>(
initialBetAmount
Expand Down Expand Up @@ -369,7 +369,6 @@ export const BuyPanelBody = (props: {
}
}
const [showLocationMonitor, setShowLocationMonitor] = useState(false)
const isCashContract = contract.token === 'CASH'

const { status: verificationStatus, message: verificationMessage } =
user && privateUser
Expand Down
2 changes: 1 addition & 1 deletion web/components/buttons/create-question-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const CreateQuestionButton = (props: {
<Link
href="/create"
className={clsx(
buttonClass(size ?? 'xl', color ?? 'gradient'),
buttonClass(size ?? 'xl', color ?? 'indigo-outline'),
'whitespace-nowrap',
className
)}
Expand Down
19 changes: 6 additions & 13 deletions web/components/contract/twomba-header-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,21 +249,14 @@ export function TwombaHeaderActions(props: {
: []),
]

const sweepsEnabled = !!playContract.siblingContractId

const isNonBetPollOrBountiedQuestion =
playContract.mechanism === 'none' &&
(playContract.outcomeType === 'POLL' ||
playContract.outcomeType === 'BOUNTIED_QUESTION')

return (
// make tooltip children stretch
<Row className="mr-4 shrink-0 items-center [&>*]:flex">
<div className="relative z-50">
{!isNonBetPollOrBountiedQuestion && (
<TwombaToggle sweepsEnabled={sweepsEnabled} />
)}
</div>

{!!currentContract.siblingContractId && (
<div className="relative">
<TwombaToggle />
</div>
)}
{!playContract.coverImageUrl && isCreator && (
<ChangeBannerButton
contract={playContract}
Expand Down
Loading

0 comments on commit 873c6b4

Please sign in to comment.