Skip to content

Commit

Permalink
Merge branch 'main' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
PBillingsby authored Dec 19, 2024
2 parents b07b00d + 8546eb2 commit 472a5e5
Show file tree
Hide file tree
Showing 47 changed files with 2,826 additions and 8,548 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/devdeploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy to Cloudflare Pages
name: Deploy Dev

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/devnet.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy to Cloudflare Pages
name: Deploy Devnet

on:
push:
Expand Down
64 changes: 64 additions & 0 deletions .github/workflows/rewards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Rewards Site

on:
push:
branches:
- main
workflow_dispatch:

jobs:
build-and-deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Authenticate with Google Cloud
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}

- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v1
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}

- name: Install bun
uses: oven-sh/setup-bun@v1

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "22"

- name: Install pnpm
run: npm install -g pnpm

- name: Install Doppler CLI
run: |
(curl -Ls --tlsv1.2 --proto "=https" --retry 3 https://cli.doppler.com/install.sh || wget -t 3 -qO- https://cli.doppler.com/install.sh) | sudo sh
- name: Set up Doppler
run: doppler configure set token ${{ secrets.DEVDEPLOY_DOPPLER_TOKEN }}

- name: Fetch secrets from Doppler and boot
run: doppler run -- npm run boot
env:
DOPPLER_TOKEN: ${{ secrets.DEVDEPLOY_DOPPLER_TOKEN }}

- name: Build Next.js app
working-directory: ./apps/rewards-dashboard
run: pnpm run build
env:
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}

# Step 11: Upload build output to GCS
- name: Upload build output to GCS
run: |
gsutil -m rsync -r -x "^\..*|README.md|gha-creds-.*\.json" ./apps/rewards-dashboard/out gs://${{ secrets.GCS_BUCKET_NAME }}
# Step 12: Set public read access to files
- name: Set public read access to files
run: |
gsutil iam ch allUsers:objectViewer gs://${{ secrets.GCS_BUCKET_NAME }}
52 changes: 52 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Website Staging Deploy

on:
push:
branches:
- staging # or the branch you want to deploy from
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
environment: website

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install bun
uses: oven-sh/setup-bun@v1

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "20" # Use the Node.js version compatible with your project

- name: Install pnpm
run: npm install -g pnpm

- name: Install Doppler CLI
run: |
(curl -Ls --tlsv1.2 --proto "=https" --retry 3 https://cli.doppler.com/install.sh || wget -t 3 -qO- https://cli.doppler.com/install.sh) | sudo sh
- name: Set up Doppler
run: doppler configure set token ${{ secrets.WEB_DOPPLER_TOKEN }}

- name: Fetch secrets from Doppler and boot
run: doppler run -- npm run boot
env:
DOPPLER_TOKEN: ${{ secrets.WEB_DOPPLER_TOKEN }}

- name: Clean up build output
working-directory: ./apps/website/.next
run: |
rm -rf cache
- name: Deploy to Cloudflare Pages
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.WEB_CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.WEB_CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_PROJECT_NAME: ${{ secrets.WEB_CLOUDFLARE_PROJECT_NAME }}
run: |
npx wrangler pages deploy ./apps/website/out --project-name=$CLOUDFLARE_PROJECT_NAME --branch=main
3 changes: 2 additions & 1 deletion .github/workflows/testnet.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: Deploy to Cloudflare Pages
name: Deploy Testnet

on:
push:
branches:
- main # or the branch you want to deploy from
workflow_dispatch:

jobs:
build:
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Lilypad web uis

This repo contains the Lilypad UIs reachable via a browser or node based.
Each UI is seperated into it's own pnpm workspace, see details in `## Project structure` below.

## Prerequisites

- [pnpm](https://pnpm.io/installation)
Expand All @@ -21,8 +21,9 @@ Each UI is seperated into it's own pnpm workspace, see details in `## Project st
**Apps**

- `/apps/info-dashboard`: The Lilypad network metrics UI hosted at https://info.lilypad.tech
- `/apps/website`: The Lilypad marketing site
- `/apps/website`: The Lilypad main site
- `/apps/website-cms`: (WIP!) Payload CMS that will potentially power the info-dashboard and website
- `/apps/rewards-dashboard`: Community Rewards and Recognition site hosted at https://oss.lilypad.tech

**Packages**

Expand Down
22 changes: 2 additions & 20 deletions apps/info-dashboard/src/app/leaderboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,6 @@ export default function Leaderboard() {
title={m.leaderboard_node_count_card_title()}
>
<div className="flex space-x-uui-5xl">
<div className="flex-col flex space-y-uui-xs">
<span className="uui-text-sm font-medium text-uui-text-tertiary-600">
{m.leaderboard_node_count_total_title()}
</span>
<span className="text-uui-text-primary-900 uui-display-sm font-semibold">
{nodesIsLoading ? (
<RandomHexSpan
length={4}
></RandomHexSpan>
) : nodesIsError ? (
<span>!err</span>
) : (
<span>{nodesData?.length}</span>
)}
</span>
</div>
<div className="flex-col flex space-y-uui-xs">
<span className="uui-text-sm font-medium text-uui-text-tertiary-600">
{m.leaderboard_node_count_online_title()}
Expand Down Expand Up @@ -180,12 +164,10 @@ export default function Leaderboard() {
leaderboardData
? leaderboardData.reduce(
(total, node) =>
+node.Points +
total,
0
+node.Points +total, 0
)
: 0
)}
).toLocaleString()}
</span>
</div>
{/* Todo add api week total Lilybit_rewards earned */}
Expand Down
2 changes: 1 addition & 1 deletion apps/info-dashboard/src/lib/fetchers/leaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function toTableData({
} as const);
return result;
})(),
"Reward Points": Math.round(+Points * 100) / 100,
"Reward Points": (Math.round(+Points * 100) / 100).toLocaleString(),

Status: (() => {
const online = nodesData.find(
Expand Down
1 change: 1 addition & 0 deletions apps/rewards-dashboard/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DISCORD_TOKEN=
3 changes: 3 additions & 0 deletions apps/rewards-dashboard/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions apps/rewards-dashboard/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
40 changes: 40 additions & 0 deletions apps/rewards-dashboard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Deployment

The site is set up to automatically deploy to a bucket in GCP via a Github action found within this repository, to the rewards site project. Within the configuration is a cloud storage bucket called oss-contrib which is referenced by a load balancer named oss-contributions which has a GCP issued SSL cert.

This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.js`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
91 changes: 91 additions & 0 deletions apps/rewards-dashboard/app/api/ambassador/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { promises as fs } from 'fs';
import path from 'path';

const DISCORD_TOKEN = process.env.DISCORD_TOKEN;

async function fetchDiscordUser(discordUserId) {
const discordAPIBase = 'https://discord.com/api/v10';

try {
const response = await fetch(`${discordAPIBase}/users/${discordUserId}`, {
headers: {
Authorization: `Bot ${DISCORD_TOKEN}`,
},
});

if (!response.ok) {
const errorBody = await response.text();
throw new Error(`Failed to fetch Discord user with ID: ${discordUserId}. Status: ${response.status}. Body: ${errorBody}`);
}

const data = await response.json();
return {
username: data?.global_name ?? data?.username,
avatar: data.avatar ? `https://cdn.discordapp.com/avatars/${data.id}/${data.avatar}.png` : null,
};
} catch (error) {
console.error(`Error fetching Discord user with ID ${discordUserId}:`, error);
return null;
}
}

async function parseCSVFile(filePath) {
try {
const data = await fs.readFile(filePath, 'utf8');
const lines = data.trim().split('\n');
const headers = lines[0].split(',');
return lines.slice(1).map(line => {
const values = line.split(',');
return headers.reduce((obj, header, index) => {
obj[header.trim()] = values[index] ? values[index].trim() : null;
return obj;
}, {});
});
} catch (error) {
console.error('Error reading or parsing CSV file:', error);
throw error;
}
}

export async function GET(req) {
const csvFilePath = path.join(process.cwd(), 'public', 'ambassador_rewards.csv');

if (!DISCORD_TOKEN) {
console.error('Bot token not set in environment variables');
return new Response('Server configuration error: Bot token not set', { status: 500 });
}

try {
const ambassadors = await parseCSVFile(csvFilePath);

const enrichedAmbassadors = await Promise.all(
ambassadors.map(async (ambassador) => {
if (ambassador.id) {
const discordUser = await fetchDiscordUser(ambassador.id);
return {
id: ambassador.id,
username: discordUser?.username ?? 'Unknown',
avatar: discordUser?.avatar ?? null,
wallet_address: ambassador.wallet_address,
rewards: ambassador?.rewards,
contributions: null
};
} else {
console.warn(`Ambassador ${ambassador.username} has no ID`);
return null;
}
})
);

return new Response(JSON.stringify(enrichedAmbassadors), {
status: 200,
headers: { 'Content-Type': 'application/json' }
});
} catch (error) {
console.error('Error processing ambassadors:', error);
return new Response(JSON.stringify({ error: 'Error processing ambassadors', details: error.message }), {
status: 500,
headers: { 'Content-Type': 'application/json' }
});
}
}
Loading

0 comments on commit 472a5e5

Please sign in to comment.