Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send weekly email to claim scout points #4852

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 2 additions & 0 deletions .ebstalk.apps.env/scoutgame.env
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ SCOUTGAME_S3_BUCKET="scoutgame.public"
NFT_ARTWORK_S3_PATH="prd"
REACT_APP_SCOUTGAME_INVITE_CODE="1337"
REACT_APP_BUILDER_NFT_CONTRACT_ADDRESS="{{pull:secretsmanager:/io.cv.app/prd/buildernft:SecretString:builder_smart_contract_address}}"
MAILGUN_DOMAIN="{{pull:secretsmanager:/io.cv.app/prd/mailgun:SecretString:mailgun_domain}}"
MAILGUN_API_KEY="{{pull:secretsmanager:/io.cv.app/prd/mailgun:SecretString:mailgun_api_key}}"
2 changes: 1 addition & 1 deletion apps/scoutgame/app/api/session/claimable-points/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getClaimablePoints } from '@packages/scoutgame/points/getClaimablePoints';
import { NextResponse } from 'next/server';

import { getClaimablePoints } from 'lib/points/getClaimablePoints';
import { getUserFromSession } from 'lib/session/getUserFromSession';

export async function GET() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
result
} = useAction(loginWithFarcasterAction, {
onSuccess: async ({ data }) => {
const nextPage = data?.onboarded ? redirectUrl : '/welcome';
const nextPage = !data?.onboarded ? '/welcome' : inviteCode ? '/welcome/builder' : redirectUrl || '/home';

if (!data?.success) {
return;
Expand All @@ -64,7 +64,7 @@
log.error('There was an error while logging in with Warpcast', { error: err });
}
popupState.close();
}, []);

Check warning on line 67 in apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx

View workflow job for this annotation

GitHub Actions / Test apps

React Hook useCallback has a missing dependency: 'popupState'. Either include it or remove the dependency array

Check warning on line 67 in apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx

View workflow job for this annotation

GitHub Actions / Test apps

React Hook useCallback has a missing dependency: 'popupState'. Either include it or remove the dependency array

Check warning on line 67 in apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx

View workflow job for this annotation

GitHub Actions / Test apps

React Hook useCallback has a missing dependency: 'popupState'. Either include it or remove the dependency array

Check warning on line 67 in apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx

View workflow job for this annotation

GitHub Actions / Test app

React Hook useCallback has a missing dependency: 'popupState'. Either include it or remove the dependency array

Check warning on line 67 in apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx

View workflow job for this annotation

GitHub Actions / Test

React Hook useCallback has a missing dependency: 'popupState'. Either include it or remove the dependency array

Check warning on line 67 in apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx

View workflow job for this annotation

GitHub Actions / Validate code

React Hook useCallback has a missing dependency: 'popupState'. Either include it or remove the dependency array

const onSuccessCallback = useCallback(async (res: StatusAPIResponse) => {
if (res.message && res.signature) {
Expand All @@ -72,11 +72,11 @@
} else {
log.error('Did not receive message or signature from Farcaster', res);
}
}, []);

Check warning on line 75 in apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx

View workflow job for this annotation

GitHub Actions / Test apps

React Hook useCallback has missing dependencies: 'inviteCode' and 'loginUser'. Either include them or remove the dependency array

Check warning on line 75 in apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx

View workflow job for this annotation

GitHub Actions / Test apps

React Hook useCallback has missing dependencies: 'inviteCode' and 'loginUser'. Either include them or remove the dependency array

Check warning on line 75 in apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx

View workflow job for this annotation

GitHub Actions / Test apps

React Hook useCallback has missing dependencies: 'inviteCode' and 'loginUser'. Either include them or remove the dependency array

Check warning on line 75 in apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx

View workflow job for this annotation

GitHub Actions / Test app

React Hook useCallback has missing dependencies: 'inviteCode' and 'loginUser'. Either include them or remove the dependency array

Check warning on line 75 in apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx

View workflow job for this annotation

GitHub Actions / Test

React Hook useCallback has missing dependencies: 'inviteCode' and 'loginUser'. Either include them or remove the dependency array

Check warning on line 75 in apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx

View workflow job for this annotation

GitHub Actions / Validate code

React Hook useCallback has missing dependencies: 'inviteCode' and 'loginUser'. Either include them or remove the dependency array

const onClick = useCallback(() => {
popupState.open();
}, []);

Check warning on line 79 in apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx

View workflow job for this annotation

GitHub Actions / Test apps

React Hook useCallback has a missing dependency: 'popupState'. Either include it or remove the dependency array

Check warning on line 79 in apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx

View workflow job for this annotation

GitHub Actions / Test apps

React Hook useCallback has a missing dependency: 'popupState'. Either include it or remove the dependency array

Check warning on line 79 in apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx

View workflow job for this annotation

GitHub Actions / Test apps

React Hook useCallback has a missing dependency: 'popupState'. Either include it or remove the dependency array

Check warning on line 79 in apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx

View workflow job for this annotation

GitHub Actions / Test app

React Hook useCallback has a missing dependency: 'popupState'. Either include it or remove the dependency array

Check warning on line 79 in apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx

View workflow job for this annotation

GitHub Actions / Test

React Hook useCallback has a missing dependency: 'popupState'. Either include it or remove the dependency array

Check warning on line 79 in apps/scoutgame/components/common/WarpcastLogin/WarpcastLoginButton.tsx

View workflow job for this annotation

GitHub Actions / Validate code

React Hook useCallback has a missing dependency: 'popupState'. Either include it or remove the dependency array

const {
signIn,
Expand Down
2 changes: 1 addition & 1 deletion apps/scoutgame/lib/builders/setupBuilderProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export async function setupBuilderProfile({
});

// mark builder as applied if they haven't been marked as such yet
if (scout.builderStatus === null) {
if (scout.builderStatus === null || inviteCode) {
await prisma.scout.update({
where: {
id: unsealedUserId
Expand Down
131 changes: 100 additions & 31 deletions apps/scoutgame/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"declarationMap": true,
"declaration": true,
"rootDir": "../../",
"lib": ["dom", "dom.iterable", "esnext", "webworker"],
"lib": [
"dom",
"dom.iterable",
"esnext",
"webworker"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
Expand All @@ -21,35 +26,99 @@
}
],
"paths": {
"@connect-shared/*": ["../../@connect-shared/*"],
"apiClient/*": ["./apiClient/*"],
"components/*": ["./components/*"],
"hooks/*": ["./hooks/*"],
"lib/*": ["./lib/*"],
"public/*": ["./public/*"],
"theme/*": ["./theme/*"],
"@root/abis/*": ["../../abis/*"],
"@root/adapters/*": ["../../adapters/*"],
"@root/config/*": ["../../config/*"],
"@root/connectors/*": ["../../connectors/*"],
"@root/lib/*": ["../../lib/*"],
"@root/hooks/*": ["../../hooks/*"],
"@charmverse/core/prisma": ["../../node_modules/@charmverse/core/dist/cjs/prisma"],
"@charmverse/core/prisma-client": ["../../node_modules/@charmverse/core/dist/cjs/prisma-client"],
"@charmverse/core/shared": ["../../node_modules/@charmverse/core/dist/cjs/shared"],
"@charmverse/core/log": ["../../node_modules/@charmverse/core/dist/cjs/lib/log"],
"@charmverse/core/http": ["../../node_modules/@charmverse/core/dist/cjs/http"],
"@charmverse/core/test": ["../../node_modules/@charmverse/core/dist/cjs/test"],
"@charmverse/core/permissions": ["../../node_modules/@charmverse/core/dist/cjs/permissions"],
"@charmverse/core/permissions/flags": ["../../node_modules/@charmverse/core/dist/cjs/permissions-flags"],
"@charmverse/core/pages": ["../../node_modules/@charmverse/core/dist/cjs/pages"],
"@charmverse/core/pages/utilities": ["../../node_modules/@charmverse/core/dist/cjs/pages-utilities"],
"@charmverse/core/proposals": ["../../node_modules/@charmverse/core/dist/cjs/proposals"],
"@charmverse/core/bounties": ["../../node_modules/@charmverse/core/dist/cjs/bounties"],
"@charmverse/core/utilities": ["../../node_modules/@charmverse/core/dist/cjs/utilities"],
"@charmverse/core/errors": ["../../node_modules/@charmverse/core/dist/cjs/errors"]
"@connect-shared/*": [
"../../@connect-shared/*"
],
"apiClient/*": [
"./apiClient/*"
],
"components/*": [
"./components/*"
],
"hooks/*": [
"./hooks/*"
],
"lib/*": [
"./lib/*"
],
"public/*": [
"./public/*"
],
"theme/*": [
"./theme/*"
],
"@root/abis/*": [
"../../abis/*"
],
"@root/adapters/*": [
"../../adapters/*"
],
"@root/config/*": [
"../../config/*"
],
"@root/connectors/*": [
"../../connectors/*"
],
"@root/lib/*": [
"../../lib/*"
],
"@root/hooks/*": [
"../../hooks/*"
],
"@charmverse/core/prisma": [
"../../node_modules/@charmverse/core/dist/cjs/prisma"
],
"@charmverse/core/prisma-client": [
"../../node_modules/@charmverse/core/dist/cjs/prisma-client"
],
"@charmverse/core/shared": [
"../../node_modules/@charmverse/core/dist/cjs/shared"
],
"@charmverse/core/log": [
"../../node_modules/@charmverse/core/dist/cjs/lib/log"
],
"@charmverse/core/http": [
"../../node_modules/@charmverse/core/dist/cjs/http"
],
"@charmverse/core/test": [
"../../node_modules/@charmverse/core/dist/cjs/test"
],
"@charmverse/core/permissions": [
"../../node_modules/@charmverse/core/dist/cjs/permissions"
],
"@charmverse/core/permissions/flags": [
"../../node_modules/@charmverse/core/dist/cjs/permissions-flags"
],
"@charmverse/core/pages": [
"../../node_modules/@charmverse/core/dist/cjs/pages"
],
"@charmverse/core/pages/utilities": [
"../../node_modules/@charmverse/core/dist/cjs/pages-utilities"
],
"@charmverse/core/proposals": [
"../../node_modules/@charmverse/core/dist/cjs/proposals"
],
"@charmverse/core/bounties": [
"../../node_modules/@charmverse/core/dist/cjs/bounties"
],
"@charmverse/core/utilities": [
"../../node_modules/@charmverse/core/dist/cjs/utilities"
],
"@charmverse/core/errors": [
"../../node_modules/@charmverse/core/dist/cjs/errors"
]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["../../node_modules", ".next/", "public/sw.js", "sw.js"]
}
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
],
"exclude": [
"../../node_modules",
".next/",
"public/sw.js",
"sw.js"
]
}
35 changes: 20 additions & 15 deletions apps/scoutgamecron/cron.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
version: 1
cron:
- name: 'process-builder-activity'
url: '/process-builder-activity'
- name: "process-builder-activity"
url: "/process-builder-activity"
# every 20 minutes
schedule: '*/20 * * * *'
schedule: "*/20 * * * *"

- name: 'process-gems-payout'
url: '/process-gems-payout'
- name: "process-gems-payout"
url: "/process-gems-payout"
# Start of every hour
schedule: '0 * * * *'
schedule: "0 * * * *"

- name: 'process-nft-mints'
url: '/process-nft-mints'
- name: "process-nft-mints"
url: "/process-nft-mints"
# Every 5 minutes
schedule: '*/20 * * * *'
schedule: "*/20 * * * *"

- name: 'update-mixpanel-user-profiles'
url: '/update-mixpanel-user-profiles'
- name: "update-mixpanel-user-profiles"
url: "/update-mixpanel-user-profiles"
# Every day at midnight
schedule: '0 0 * * *'
schedule: "0 0 * * *"

- name: 'alert-low-wallet-gas-balance'
url: '/alert-low-wallet-gas-balance'
- name: "alert-low-wallet-gas-balance"
url: "/alert-low-wallet-gas-balance"
# Every 5 minutes
schedule: '*/5 * * * *'
schedule: "*/5 * * * *"

- name: "send-points-claim-emails"
url: "/send-points-claim-emails"
# Every Monday at 00:00
schedule: "0 0 * * 1"
1 change: 1 addition & 0 deletions apps/scoutgamecron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@octokit/plugin-throttling": "^9.3.1",
"@packages/farcaster": "^0.0.0",
"@packages/github": "^0.0.0",
"@packages/mailer": "^0.0.0",
"@packages/mixpanel": "^0.0.0",
"@packages/onchain": "^0.0.0",
"@packages/scoutgame": "^0.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { log } from '@charmverse/core/log';
import { prisma } from '@charmverse/core/prisma-client';
import { sendEmail } from '@packages/mailer/mailer';
import { getClaimablePoints } from '@packages/scoutgame/points/getClaimablePoints';
import { render } from '@react-email/render';

import { ClaimPointsTemplate } from './templates/ClaimPointsTemplate';

export async function sendPointsClaimEmails() {
const scouts = await prisma.scout.findMany({
where: {
email: {
not: null
}
},
select: {
id: true,
username: true,
displayName: true,
email: true
}
});

for (const scout of scouts) {
try {
const pointsToClaim = await getClaimablePoints(scout.id);

if (pointsToClaim.totalClaimablePoints) {
const html = await render(
ClaimPointsTemplate({ points: pointsToClaim.totalClaimablePoints, displayName: scout.displayName })
);
await sendEmail({
to: {
displayName: scout.displayName,
email: scout.email!,
userId: scout.id
},
senderAddress: `The Scout Game <updates@mail.thesunnyawards.fun>`,
subject: 'Congratulations you just earned points in the Scout Game',
html
});
}
} catch (error) {
log.error('Error sending points claim email', { error, scoutId: scout.id });
}
}
}

sendPointsClaimEmails();
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Head } from '@react-email/head';
import { Html } from '@react-email/html';
import { Img } from '@react-email/img';
import { Section } from '@react-email/section';
import React from 'react';

import Button from './components/Button';
import Text from './components/Text';

const lightGreyColor = '#edf2f4';

export function ClaimPointsTemplate({ points, displayName }: { points: number; displayName: string }) {
return (
<Html>
<Head>
<title>Congratulations you just earned points in the Scout Game</title>
</Head>
<Section
style={{
backgroundColor: lightGreyColor
}}
>
<Section
style={{
width: 600,
backgroundColor: '#fff'
}}
>
<Img
src='https://scoutgame.xyz/images/info/info_banner.png'
style={{
maxHeight: '150px',
width: '100%',
objectFit: 'cover'
}}
/>
<Section
style={{
padding: 30
}}
>
<Text>
Congratulations, {displayName} you just earned {points} points this week in the Scout Game.
</Text>
<Button href='https://scoutgame.xyz/profile?tab=win'>Claim</Button>
</Section>
</Section>
</Section>
</Html>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { LinkProps } from '@react-email/link';
import type { ReactNode } from 'react';
import React from 'react';

import Link from './Link';
import Text from './Text';

export default function Button({
children,
href,
style,
...props
}: {
children: ReactNode;
href: string;
} & LinkProps) {
return (
<Link
{...props}
style={{
width: '100%'
}}
href={href}
>
<Text
bold
style={{
textAlign: 'center',
color: '#fff',
padding: '8px 24px',
borderRadius: '3px',
background: '#A06CD5',
...style
}}
>
{children}
</Text>
</Link>
);
}
Loading
Loading