Skip to content

Commit

Permalink
Rewards page (#48)
Browse files Browse the repository at this point in the history
* Add rewards route

* Display rewards tabs

* Update layout

* Split pages

* Add points block UI

* Display limited events UI

* Display tasks list

* Display history UI

* Update history page

* Add leaderboard UI

* Display active task ID page

* Fix points block

* Add points API

* Update api hooks

* Update balance block

* Display API data

* Add withdraw modal

* Add loading states

* Add missing loading states

* Fire confetti

* Add small UI fixes

* Add rewards store

* Refactor leaderboard

* Refactor history

* Update rewards balance block

* Add rewards about page

* Extract back link

* Add multi-page loading

* Rename withdraw modal

* Update claim modal

* Update leaderboard styles

* Add rewards auth

* Add enter program & program details

* Update history

* Update earn history

* Update components

* Chore code

* Update events loading

* Chore types and imports

* Refactor rewards components

* Update enums

* Fix event actions

* Add credentials

* Fix review issues

* Update packages
  • Loading branch information
ardier16 authored Mar 12, 2024
1 parent 10e4563 commit 907c9f8
Show file tree
Hide file tree
Showing 75 changed files with 2,526 additions and 71 deletions.
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
"rsc": "node scripts/release-sanity-check.mjs"
},
"dependencies": {
"@distributedlab/jac": "^1.0.0-rc.9",
"@distributedlab/tools": "^1.0.0-rc.9",
"@distributedlab/w3p": "^1.0.0-rc.9",
"@distributedlab/jac": "^1.0.0-rc.14",
"@distributedlab/tools": "^1.0.0-rc.14",
"@distributedlab/w3p": "^1.0.0-rc.14",
"@dnd-kit/core": "^6.1.0",
"@dnd-kit/modifiers": "^7.0.0",
"@dnd-kit/sortable": "^8.0.0",
Expand All @@ -45,12 +45,15 @@
"@mui/x-date-pickers": "^6.18.7",
"@rarimo/rarime-connector": "^2.1.0-rc.3",
"@walletconnect/modal": "^2.6.2",
"canvas-confetti": "^1.9.2",
"copy-to-clipboard": "^3.3.3",
"i18next": "^22.4.3",
"jdenticon": "^3.2.0",
"lodash": "^4.17.21",
"loglevel": "^1.8.1",
"markdown-to-jsx": "^7.4.1",
"material-ui-popup-state": "^5.0.10",
"mui-markdown": "^1.1.13",
"notistack": "^3.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand All @@ -65,6 +68,7 @@
"devDependencies": {
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
"@types/canvas-confetti": "^1.6.4",
"@types/lodash": "^4",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
Expand Down
1 change: 1 addition & 0 deletions src/api/clients/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { config } from '@/config'

export const api = new JsonApiClient({
baseUrl: config.API_URL,
credentials: 'include',
})

export let zkpSnap: SnapConnector
Expand Down
10 changes: 5 additions & 5 deletions src/api/modules/auth/helpers/authorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ZKProof } from '@rarimo/rarime-connector'
import { api } from '@/api/clients'
import { AuthTokensGroup, FillRequestDetails, InvitationDetails } from '@/api/modules/auth'
import { OrgUserRoles } from '@/api/modules/orgs'
import { ApiServicePaths } from '@/enums/api'
import { ApiServicePaths } from '@/enums'

export const authorizeUser = async ({
role,
Expand All @@ -12,11 +12,11 @@ export const authorizeUser = async ({
groupId,
zkProof,
}: {
role: OrgUserRoles
userDid: string
orgDid: string
groupId: string
zkProof: ZKProof
role?: OrgUserRoles
orgDid?: string
groupId?: string
zkProof?: ZKProof
}) => {
const { data } = await api.post<AuthTokensGroup>(`${ApiServicePaths.Auth}/v1/authorize`, {
body: {
Expand Down
2 changes: 1 addition & 1 deletion src/api/modules/link/helpers/proofs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { api } from '@/api/clients'
import { type Proof, type ProofLink } from '@/api/modules/link'
import { ApiServicePaths } from '@/enums/api'
import { ApiServicePaths } from '@/enums'

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const DUMMY_PROOFS: Proof[] = [
Expand Down
2 changes: 1 addition & 1 deletion src/api/modules/orgs/helpers/org-groups-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
getTargetProperty,
loadAndParseCredentialSchema,
} from '@/api/modules/zkp'
import { ApiServicePaths } from '@/enums/api'
import { ApiServicePaths } from '@/enums'

const fakeLoadRequestsAll = async (query?: OrgGroupRequestQueryParams) => {
return DUMMY_ORG_GROUP_REQUESTS.filter(req => {
Expand Down
2 changes: 1 addition & 1 deletion src/api/modules/orgs/helpers/org-groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
OrgGroupQueryParams,
OrgGroupRequestStatuses,
} from '@/api/modules/orgs'
import { ApiServicePaths } from '@/enums/api'
import { ApiServicePaths } from '@/enums'

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const DUMMY_ORG_GROUP: OrgGroup[] = [
Expand Down
2 changes: 1 addition & 1 deletion src/api/modules/orgs/helpers/orgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
type OrgUser,
type OrgVerificationCode,
} from '@/api/modules/orgs'
import { ApiServicePaths } from '@/enums/api'
import { ApiServicePaths } from '@/enums'

export const DUMMY_ORGS: Organization[] = [
{
Expand Down
30 changes: 30 additions & 0 deletions src/api/modules/points/enums/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export enum EventsRequestFilters {
Did = 'did',
Status = 'status',
MetaStaticName = 'meta.static.name',
}

export enum EventRequestPageProperties {
Limit = 'limit',
Cursor = 'cursor',
Order = 'order',
}

export enum EventRequestPageOrder {
Asc = 'asc',
Desc = 'desc',
}

export enum EventStatuses {
Open = 'open',
Fulfilled = 'fulfilled',
Claimed = 'claimed',
}

export enum EventMetadataFrequencies {
OneTime = 'one-time',
Daily = 'daily',
Weekly = 'weekly',
Unlimited = 'unlimited',
Custom = 'custom',
}
1 change: 1 addition & 0 deletions src/api/modules/points/enums/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './events'
138 changes: 138 additions & 0 deletions src/api/modules/points/helpers/balance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import { api } from '@/api/clients'
import { ApiServicePaths } from '@/enums'

import { type Balance, type Withdrawal } from '../types'

export const BALANCE_MOCK: Balance = {
id: 'did:iden3:readonly:tTep1wgHSGULyrAgWD1SKDxtg1jAPGzZuXuHNPknH',
type: 'balance',
amount: 175,
created_at: 1628793600,
updated_at: 1628793600,
rank: 291,
}

export const LEADERBOARD_MOCK: Balance[] = [
{
id: 'did:iden3:readonly:mhQHvqmvimneVHCL5EufeZvfzigRt',
amount: 25345,
type: 'balance',
created_at: 1628793600,
updated_at: 1628793600,
rank: 1,
},
{
id: 'did:iden3:readonly:mi1QKgywFcFD7d35QRaHwd6b6Cxy',
amount: 25123,
type: 'balance',
created_at: 1628793600,
updated_at: 1628793600,
rank: 2,
},
{
id: 'did:iden3:readonly:mmaJ5kAjbGLRVcfqwsMPi7kHK1f',
amount: 23402,
type: 'balance',
created_at: 1628793600,
updated_at: 1628793600,
rank: 3,
},
{
id: 'did:iden3:readonly:mhQHvqmvimneVHCL5EufeZvfzigRv',
amount: 21502,
type: 'balance',
created_at: 1628793600,
updated_at: 1628793600,
rank: 4,
},
{
id: 'did:iden3:readonly:mi1QKgywFcFD7d35QRaHwd6b6Cxb',
amount: 20420,
type: 'balance',
created_at: 1628793600,
updated_at: 1628793600,
rank: 5,
},
{
id: 'did:iden3:readonly:mmaJ5kAjbGLRVcfqwsMPi7kHK1a',
amount: 19499,
type: 'balance',
created_at: 1628793600,
updated_at: 1628793600,
rank: 6,
},
{
id: 'did:iden3:readonly:mi1QKgywFcFD7d35QRaHwd6b6Cxe',
amount: 8992,
type: 'balance',
created_at: 1628793600,
updated_at: 1628793600,
rank: 7,
},
{
id: 'did:iden3:readonly:ahQHvqmvimneVHCL5EufeZvfzigRt',
amount: 8150,
type: 'balance',
created_at: 1628793600,
updated_at: 1628793600,
rank: 8,
},
{
id: 'did:iden3:readonly:whQHvqmvimneVHCL5EufeZvfzigRt',
amount: 4520,
type: 'balance',
created_at: 1628793600,
updated_at: 1628793600,
rank: 9,
},
{
id: 'did:iden3:readonly:mhQHvqmvimneVHCL5EufeZvfzigRa',
amount: 1402,
type: 'balance',
created_at: 1628793600,
updated_at: 1628793600,
rank: 10,
},
]

// Balances
export const createPointsBalance = async (did: string, referredBy: string) => {
return api.post<Balance>(`${ApiServicePaths.Points}/v1/public/balances`, {
body: {
data: {
id: did,
type: 'create_balance',
attributes: {
referred_by: referredBy,
},
},
},
})
}

export const getLeaderboard = async () => {
return api.get<Balance[]>(`${ApiServicePaths.Points}/v1/public/balances`)
}

export const getPointsBalance = async (did: string) => {
return api.get<Balance>(`${ApiServicePaths.Points}/v1/public/balances/${did}?rank=true`)
}

// Withdrawals
export const getWithdrawalHistory = async (did: string) => {
return api.get<Withdrawal[]>(`${ApiServicePaths.Points}/v1/public/balances/${did}/withdrawals`)
}

export const withdrawPoints = async (did: string, amount: number, address: string) => {
return api.post<Withdrawal>(`${ApiServicePaths.Points}/v1/public/balances/${did}/withdrawals`, {
body: {
data: {
type: 'withdraw',
attributes: {
amount,
address,
},
},
},
})
}
Loading

0 comments on commit 907c9f8

Please sign in to comment.