Skip to content

Commit

Permalink
Merge pull request #892 from 0xsend/use_tag_for_affiliate_referral_link
Browse files Browse the repository at this point in the history
Use tag for affiliate referral link
  • Loading branch information
youngkidwarrior authored Nov 23, 2024
2 parents 7f97aa0 + 81d15c9 commit d385f2e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 331 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ jest.mock('app/utils/useChainAddresses', () => ({
useChainAddresses: jest.fn().mockReturnValue({ data: { address: '0x123' } }),
}))
jest.mock('wagmi')
jest.mock('@web3modal/wagmi/react', () => ({
useWeb3Modal: jest.fn().mockReturnValue({ open: jest.fn() }),
}))

jest.mock('@my/wagmi', () => ({
__esModule: true,
...jest.requireActual('@my/wagmi'),
Expand Down
15 changes: 5 additions & 10 deletions packages/app/features/affiliate/screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { useAffiliateReferrals } from './utils/useAffiliateReferrals'
import { Fragment } from 'react'
import { useAffiliateStats } from './utils/useAffiliateStats'
import type { Functions } from '@my/supabase/database.types'

export const AffiliateScreen = () => {
return (
Expand Down Expand Up @@ -171,20 +172,14 @@ const ReferralsList = () => {
)
}

const ReferralsListRow = ({ referral }) => {
const ReferralsListRow = ({
referral,
}: { referral: Functions<'get_affiliate_referrals'>[number] }) => {
const date = new Date(referral?.created_at).toLocaleString(undefined, { dateStyle: 'medium' })

return (
<Card bc="$color0" ai="center">
<Link
href={`/profile/${referral.profile?.send_id}`}
f={1}
als="stretch"
px="$5"
py="$3"
w="100%"
h="100%"
>
<Link href={`/${referral.tag}`} f={1} als="stretch" px="$5" py="$3" w="100%" h="100%">
<XStack gap="$5" f={1} ai="center" jc={'space-between'}>
<XStack gap="$3.5" f={1} ai="center">
<Avatar size="$4.5" br="$4" gap="$2">
Expand Down
22 changes: 0 additions & 22 deletions packages/app/utils/OpenConnectModalWrapper.tsx

This file was deleted.

44 changes: 0 additions & 44 deletions supabase/database-generated.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1115,34 +1115,6 @@ export type Database = {
}
Relationships: []
}
affiliate_referrals: {
Row: {
referral:
| Database["public"]["CompositeTypes"]["affiliate_referral_type"]
| null
}
Relationships: []
}
affiliate_stats_summary: {
Row: {
affiliate_send_score: number | null
created_at: string | null
id: string | null
network_plus_minus: number | null
referral_count: number | null
send_plus_minus: number | null
user_id: string | null
}
Relationships: [
{
foreignKeyName: "affiliate_stats_user_id_fkey"
columns: ["user_id"]
isOneToOne: true
referencedRelation: "profiles"
referencedColumns: ["id"]
},
]
}
distribution_verifications_summary: {
Row: {
distribution_id: number | null
Expand Down Expand Up @@ -1381,22 +1353,6 @@ export type Database = {
send_id: number
tags: unknown
}
affiliate_referral_type: {
referred_id: string
send_plus_minus: number
avatar_url: string
tag: string
created_at: string
}
affiliate_stats_summary_type: {
id: number
created_at: string
user_id: string
send_plus_minus: number
referral_count: number
network_plus_minus: number
affiliate_send_score: number
}
multiplier_info: {
type: string
value: number
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
DROP FUNCTION IF EXISTS get_affiliate_stats_summary();

CREATE OR REPLACE FUNCTION get_affiliate_stats_summary()
RETURNS TABLE(
id uuid,
created_at timestamptz,
user_id uuid,
referral_count bigint)
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = public
AS $$
BEGIN
RETURN QUERY
SELECT
a.id,
a.created_at,
a.user_id,
COUNT(DISTINCT r.tag)::bigint AS referral_count
FROM
affiliate_stats a
LEFT JOIN referrals r ON r.referrer_id = a.user_id
WHERE
a.user_id = auth.uid()
GROUP BY
a.id,
a.created_at,
a.user_id;
END;
$$;

Loading

0 comments on commit d385f2e

Please sign in to comment.