Skip to content

Commit 4323343

Browse files
Use tag for affiliate referral link
1 parent 7f97aa0 commit 4323343

File tree

6 files changed

+37
-331
lines changed

6 files changed

+37
-331
lines changed

packages/app/features/account/rewards/activity/screen.test.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ jest.mock('app/utils/useChainAddresses', () => ({
5858
useChainAddresses: jest.fn().mockReturnValue({ data: { address: '0x123' } }),
5959
}))
6060
jest.mock('wagmi')
61-
jest.mock('@web3modal/wagmi/react', () => ({
62-
useWeb3Modal: jest.fn().mockReturnValue({ open: jest.fn() }),
63-
}))
61+
6462
jest.mock('@my/wagmi', () => ({
6563
__esModule: true,
6664
...jest.requireActual('@my/wagmi'),

packages/app/features/affiliate/screen.tsx

+5-10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
import { useAffiliateReferrals } from './utils/useAffiliateReferrals'
1919
import { Fragment } from 'react'
2020
import { useAffiliateStats } from './utils/useAffiliateStats'
21+
import type { Functions } from '@my/supabase/database.types'
2122

2223
export const AffiliateScreen = () => {
2324
return (
@@ -171,20 +172,14 @@ const ReferralsList = () => {
171172
)
172173
}
173174

174-
const ReferralsListRow = ({ referral }) => {
175+
const ReferralsListRow = ({
176+
referral,
177+
}: { referral: Functions<'get_affiliate_referrals'>[number] }) => {
175178
const date = new Date(referral?.created_at).toLocaleString(undefined, { dateStyle: 'medium' })
176179

177180
return (
178181
<Card bc="$color0" ai="center">
179-
<Link
180-
href={`/profile/${referral.profile?.send_id}`}
181-
f={1}
182-
als="stretch"
183-
px="$5"
184-
py="$3"
185-
w="100%"
186-
h="100%"
187-
>
182+
<Link href={`/${referral.tag}`} f={1} als="stretch" px="$5" py="$3" w="100%" h="100%">
188183
<XStack gap="$5" f={1} ai="center" jc={'space-between'}>
189184
<XStack gap="$3.5" f={1} ai="center">
190185
<Avatar size="$4.5" br="$4" gap="$2">

packages/app/utils/OpenConnectModalWrapper.tsx

-22
This file was deleted.

supabase/database-generated.types.ts

-44
Original file line numberDiff line numberDiff line change
@@ -1115,34 +1115,6 @@ export type Database = {
11151115
}
11161116
Relationships: []
11171117
}
1118-
affiliate_referrals: {
1119-
Row: {
1120-
referral:
1121-
| Database["public"]["CompositeTypes"]["affiliate_referral_type"]
1122-
| null
1123-
}
1124-
Relationships: []
1125-
}
1126-
affiliate_stats_summary: {
1127-
Row: {
1128-
affiliate_send_score: number | null
1129-
created_at: string | null
1130-
id: string | null
1131-
network_plus_minus: number | null
1132-
referral_count: number | null
1133-
send_plus_minus: number | null
1134-
user_id: string | null
1135-
}
1136-
Relationships: [
1137-
{
1138-
foreignKeyName: "affiliate_stats_user_id_fkey"
1139-
columns: ["user_id"]
1140-
isOneToOne: true
1141-
referencedRelation: "profiles"
1142-
referencedColumns: ["id"]
1143-
},
1144-
]
1145-
}
11461118
distribution_verifications_summary: {
11471119
Row: {
11481120
distribution_id: number | null
@@ -1381,22 +1353,6 @@ export type Database = {
13811353
send_id: number
13821354
tags: unknown
13831355
}
1384-
affiliate_referral_type: {
1385-
referred_id: string
1386-
send_plus_minus: number
1387-
avatar_url: string
1388-
tag: string
1389-
created_at: string
1390-
}
1391-
affiliate_stats_summary_type: {
1392-
id: number
1393-
created_at: string
1394-
user_id: string
1395-
send_plus_minus: number
1396-
referral_count: number
1397-
network_plus_minus: number
1398-
affiliate_send_score: number
1399-
}
14001356
multiplier_info: {
14011357
type: string
14021358
value: number
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
DROP FUNCTION IF EXISTS get_affiliate_stats_summary();
2+
3+
CREATE OR REPLACE FUNCTION get_affiliate_stats_summary()
4+
RETURNS TABLE(
5+
id uuid,
6+
created_at timestamptz,
7+
user_id uuid,
8+
referral_count bigint)
9+
LANGUAGE plpgsql
10+
SECURITY DEFINER
11+
SET search_path = public
12+
AS $$
13+
BEGIN
14+
RETURN QUERY
15+
SELECT
16+
a.id,
17+
a.created_at,
18+
a.user_id,
19+
COUNT(DISTINCT r.tag)::bigint AS referral_count,
20+
FROM
21+
affiliate_stats a
22+
LEFT JOIN referrals r ON r.referrer_id = a.user_id
23+
WHERE
24+
a.user_id = auth.uid()
25+
GROUP BY
26+
a.id,
27+
a.created_at,
28+
a.user_id;
29+
END;
30+
$$;
31+

0 commit comments

Comments
 (0)