Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
34 changes: 29 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/app/(mobile-ui)/points/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import TransactionAvatarBadge from '@/components/TransactionDetails/TransactionA
import { VerifiedUserLabel } from '@/components/UserHeader'
import { useAuth } from '@/context/authContext'
import { invitesApi } from '@/services/invites'
import { Invite } from '@/services/services.types'
import { generateInvitesShareText } from '@/utils'
import type { Invite } from '@/services/services.types'
import { generateInviteCodeLink, generateInvitesShareText } from '@/utils'
import { useQuery } from '@tanstack/react-query'
import { useRouter } from 'next/navigation'
import { useEffect } from 'react'
Expand All @@ -27,8 +27,7 @@ const PointsPage = () => {
})

const username = user?.user.username
const inviteCode = username ? `${username.toUpperCase()}INVITESYOU` : ''
const inviteLink = `${process.env.NEXT_PUBLIC_BASE_URL}/invite?code=${inviteCode}`
const { inviteCode, inviteLink } = generateInviteCodeLink(username ?? '')

useEffect(() => {
// Re-fetch user to get the latest invitees list for showing heart Icon
Expand Down
18 changes: 16 additions & 2 deletions src/utils/general.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1330,11 +1330,25 @@ export function slugify(text: string): string {
}

export const generateInvitesShareText = (inviteLink: string) => {
return `I’m using Peanut, an invite-only app for easy payments. With it you can pay friends, use merchants, and move money in and out of your bank, even cross-border. Here’s my invite: ${inviteLink}`
return `I'm using Peanut, an invite-only app for easy payments. With it you can pay friends, use merchants, and move money in and out of your bank, even cross-border. Here's my invite: ${inviteLink}`
}

/**
* Generate a deterministic 3-digit suffix from username
* This is purely cosmetic and derived from a hash of the username
*/
export const generateInviteCodeSuffix = (username: string): string => {
const lowerUsername = username.toLowerCase()
// Create a simple hash from the username
const hash = lowerUsername.split('').reduce((acc, char) => acc + char.charCodeAt(0), 0)
// Generate 3 digits between 100-999
const threeDigits = 100 + (hash % 900)
return threeDigits.toString()
}

export const generateInviteCodeLink = (username: string) => {
const inviteCode = `${username.toUpperCase()}INVITESYOU`
const suffix = generateInviteCodeSuffix(username)
const inviteCode = `${username.toUpperCase()}INVITESYOU${suffix}`
const inviteLink = `${consts.BASE_URL}/invite?code=${inviteCode}`
return { inviteLink, inviteCode }
}
Expand Down
Loading