Skip to content

Commit

Permalink
Merge pull request #15 from Apillon/main
Browse files Browse the repository at this point in the history
Fixes for stage
  • Loading branch information
vinkoS993 authored Feb 16, 2024
2 parents 7bb37a5 + d364441 commit b4e28eb
Show file tree
Hide file tree
Showing 20 changed files with 146 additions and 85 deletions.
43 changes: 40 additions & 3 deletions backend/src/cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export class Cron {
${AirdropStatus.EMAIL_SENT},
${AirdropStatus.WALLET_LINKED},
${AirdropStatus.TRANSACTION_CREATED},
${AirdropStatus.AIRDROP_COMPLETED}
${AirdropStatus.AIRDROP_COMPLETED},
${AirdropStatus.IN_WAITING_LINE}
)
AND status = ${SqlModelStatus.ACTIVE}
;
Expand Down Expand Up @@ -164,6 +165,10 @@ export class Cron {
null,
conn
);
console.info(
usersWithExpiredClaim.length +
" users updated to AIRDROP_CLAIM_EXPIRED"
);

//Get users in waiting line and set their airdrop status to PENDING, so that they will recieve email for claim
const usersInWaitingLine = (
Expand All @@ -181,16 +186,48 @@ export class Cron {
)
)[0] as Array<any>;

console.info(
"Num of users in waiting line: " + usersInWaitingLine.length
);

if (usersInWaitingLine.length) {
await mysql.paramExecute(
await conn.execute(
`UPDATE user
SET airdrop_status = ${AirdropStatus.PENDING}
SET
airdrop_status = ${AirdropStatus.EMAIL_SENT},
email_sent_time = NOW()
WHERE id IN (${usersInWaitingLine.map((x) => x.id).join(",")})
;
`,
null,
conn
);
console.info(
usersInWaitingLine.map((x) => x.id).join(",") +
" should me moved from waiting line. Sending emails...."
);

for (const user of usersInWaitingLine) {
try {
const token = await generateEmailAirdropToken(user.email);
await SmtpSendTemplate(
[user.email],
"Claim your NFT",
"en-airdrop-claim",
{
link: `${env.APP_URL}/claim?token=${token}`,
}
);
} catch (err) {
await conn.execute(
`UPDATE user
SET airdrop_status = ${AirdropStatus.EMAIL_ERROR},
WHERE id = ${user.id})
;
`
);
}
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions backend/src/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { dateParser, integerParser, stringParser } from "@rawmodel/parsers";
import { Context } from "../context";
import { ResourceError, SqlError } from "../lib/errors";
import { getQueryParams, selectAndCountQuery } from "../lib/sql-utils";
import { env } from "../config/env";

export enum AirdropStatus {
PENDING = 1,
Expand Down Expand Up @@ -201,6 +202,7 @@ export class User extends BaseSqlModel {
`
SELECT
count(*) as total,
${env.MAX_SUPPLY} as maxSupply,
SUM(IF(airdrop_status = 1, 1, 0)) as pending,
SUM(IF(airdrop_status in (2,4,5,6,7), 1, 0)) as emailSent,
SUM(IF(airdrop_status in (4,5,6,7), 1, 0)) as walletLinked,
Expand Down
12 changes: 6 additions & 6 deletions frontend/components/parts/ConnectWallet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<Btn
v-if="isConnected && (!admin || userStore.jwt)"
v-bind="$attrs"
class="text-white"
:color="colors.button"
class="text-black"
:color="colors.blue"
:size="size"
:loading="loading || isLoading"
@click="disconnectWallet()"
Expand All @@ -15,8 +15,8 @@
<Btn
v-else-if="isConnected"
v-bind="$attrs"
class="text-white"
:color="colors.button"
class="text-black"
:color="colors.blue"
:size="size"
:loading="loading || isLoading"
@click="login()"
Expand All @@ -26,8 +26,8 @@
<Btn
v-else
v-bind="$attrs"
class="text-white"
:color="colors.button"
class="text-black"
:color="colors.blue"
:size="size"
:loading="loading || isLoading"
@click="modalWalletVisible = true"
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/parts/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</RouterLink>
</div>
<div v-if="!hideLogin" :class="{ 'w-1/3 text-right': logoCenter }">
<ConnectWallet :admin="admin" :color="colors.konference" />
<ConnectWallet :admin="admin" :color="colors.blue" />
</div>
<div v-else-if="logoCenter" class="w-1/3"></div>
</nav>
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/parts/Statistics.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<div v-if="statistics" class="flex gap-8 mb-8">
<div class="px-4 py-3 bg-bg-light rounded-lg min-w-[13em]">
<h2 class="inline-block">{{ statistics.airdropped }}</h2>
<span class="text-body ml-1">/{{ statistics.total || '?' }}</span>
<p class="text-white">airdropped/available NFTs</p>
<span class="ml-1">/{{ statistics.total || '?' }}</span>
<p>airdropped/available NFTs</p>
</div>
<div class="px-4 py-3 bg-bg-light rounded-lg min-w-[13em]">
<h2>{{ statistics.emailSent }}</h2>
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/parts/Table/Ellipsis.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<div v-if="text" class="flex">
<n-ellipsis class="text-body align-bottom" :line-clamp="1">{{ text }}</n-ellipsis>
<n-ellipsis class="align-bottom" :line-clamp="1">{{ text }}</n-ellipsis>
<button class="ml-2" @click="copyToClipboard(text)">
<span class="icon-copy text-body"></span>
<span class="icon-copy"></span>
</button>
</div>
</template>
Expand Down
27 changes: 2 additions & 25 deletions frontend/components/parts/Table/Users.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,6 @@ const createColumns = (): DataTableColumns<UserInterface> => {
}
},
},
{
key: 'email_start_send_time',
title: 'Start time',
minWidth: 100,
render(row: UserInterface, index: number) {
if (isEditable(row, index)) {
return h(NDatePicker, {
value: newUser.value.email_start_send_time,
type: 'datetime',
onUpdateValue(v: string) {
newUser.value.email_start_send_time = v;
},
});
} else {
return dateTimeToDateAndTime(row?.email_start_send_time || '');
}
},
},
{
key: 'wallet',
title: 'Wallet',
Expand Down Expand Up @@ -108,13 +90,13 @@ const createColumns = (): DataTableColumns<UserInterface> => {
if (isEditable(row, index)) {
return h(
'button',
{ class: 'icon-check text-xl text-green', onClick: () => addItem(row) },
{ class: 'icon-check text-xl text-konference', onClick: () => addItem(row) },
''
);
} else if (!row.id) {
return h(
'button',
{ class: 'icon-delete text-xl text-white', onClick: () => removeItem(row) },
{ class: 'icon-delete text-xl text-black', onClick: () => removeItem(row) },
''
);
}
Expand All @@ -129,15 +111,10 @@ function addItem(user: UserInterface) {
if (!validateEmail(newUser.value.email)) {
message.warning('Please enter a valid email address');
return;
} else if (!newUser.value.email_start_send_time) {
message.warning('Please select start time');
return;
}
user.email = newUser.value.email;
user.email_start_send_time = newUser.value.email_start_send_time;
newUser.value.email = '';
newUser.value.email_start_send_time = null;
emit('addUser', newUser.value);
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/parts/TermsAndConditions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
<btn
type="primary"
size="large"
class="text-white"
:color="colors.button"
class="text-black"
:color="colors.blue"
@click="$emit('close', false)"
>
Close
Expand Down
5 changes: 3 additions & 2 deletions frontend/components/parts/form/SighUp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ function onCaptchaVerify(token: string) {
<Btn
type="primary"
size="large"
class="text-white"
:color="colors.button"
class="text-black"
:color="colors.blue"
:loading="loading"
:disabled="!formData.email || !formData.token || !formData.termsAndConditions"
@click="handleSubmit"
Expand All @@ -130,6 +130,7 @@ function onCaptchaVerify(token: string) {

<modal
:show="modalTermsAndConditionsVisible"
@close="() => (modalTermsAndConditionsVisible = false)"
@update:show="modalTermsAndConditionsVisible = false"
>
<TermsAndConditions @close="() => (modalTermsAndConditionsVisible = false)"/>
Expand Down
6 changes: 3 additions & 3 deletions frontend/components/parts/form/Upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
</div>
</div>
<Notification v-if="!hasRequiredColumns" type="error" class="mt-4 text-left">
Invalid file format. Please upload a valid CSV file with columns "email",
"email_start_send_time" and "wallet".
Invalid file format. Please upload a valid CSV file with column "email".
</Notification>
</template>

Expand Down Expand Up @@ -55,7 +54,7 @@ const $papa = vueApp.config.globalProperties.$papa;
const uploadedFile = ref<FileInfo | null>(null);
const fileData = ref<CsvItem[] | null>(null);
const fileColumns = ref<String[]>([]);
const requiredColumns = ['email', 'email_start_send_time'];
const requiredColumns = ['email'];
const hasRequiredColumns = computed<boolean>(() =>
requiredColumns.every(item => fileColumns.value.includes(item))
Expand Down Expand Up @@ -83,6 +82,7 @@ function parseUploadedFile(file?: File | null) {
$papa.parse(file, {
header: true,
delimiter: '\n',
skipEmptyLines: true,
complete: async (results: CsvFileData) => {
if (results.errors && results.errors.length) {
Expand Down
26 changes: 22 additions & 4 deletions frontend/layouts/claim.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
<div ref="headerRef">
<Header logo-center />
</div>
<div class="container h-full pb-8 lg:pb-24 flex flex-col justify-center" :style="containerStyle">
<div
class="container max-w-6xl py-8 flex flex-col justify-center box-border"
:style="containerStyle"
>
<slot />
</div>
<div ref="footerRef" class="justify-center">
Expand All @@ -13,15 +16,30 @@
</template>

<script lang="ts" setup>
const { width } = useWindowSize();
/** Heading height */
const height = ref<number>(0);
const headerRef = ref<HTMLElement>();
const footerRef = ref<HTMLElement>();
const containerStyle = computed(() => {
const hHeight = headerRef.value?.clientHeight || 0;
const fHeight = footerRef.value?.clientHeight || 0;
return {
minHeight: `calc(100dvh - ${hHeight + fHeight}px)`,
minHeight: `calc(100vh - ${height.value}px)`,
};
});
onMounted(() => {
setHeight();
});
watch(
() => width.value,
_ => {
setHeight();
}
);
function setHeight() {
height.value = (headerRef.value?.clientHeight || 0) + (footerRef.value?.clientHeight || 0) + 20;
}
</script>
23 changes: 19 additions & 4 deletions frontend/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Header logo-center hide-login />
</div>
<div
class="container h-full pb-8 lg:pb-24 flex flex-col justify-center"
class="container max-w-6xl py-8 flex flex-col justify-center box-border"
:style="containerStyle"
>
<slot />
Expand All @@ -16,15 +16,30 @@
</template>

<script lang="ts" setup>
const { width } = useWindowSize();
/** Heading height */
const height = ref<number>(0);
const headerRef = ref<HTMLElement>();
const footerRef = ref<HTMLElement>();
const containerStyle = computed(() => {
const hHeight = headerRef.value?.clientHeight || 0;
const fHeight = footerRef.value?.clientHeight || 0;
return {
minHeight: `calc(100dvh - ${hHeight + fHeight}px)`,
minHeight: `calc(100vh - ${height.value}px)`,
};
});
onMounted(() => {
setHeight();
});
watch(
() => width.value,
_ => {
setHeight();
}
);
function setHeight() {
height.value = (headerRef.value?.clientHeight || 0) + (footerRef.value?.clientHeight || 0) + 20;
}
</script>
2 changes: 1 addition & 1 deletion frontend/lib/config/naive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export const NaiveTheme: GlobalThemeOverrides = {
borderColor: colors.bg.lighter,
tdColor: colors.bg.DEFAULT,
tdColorHover: colors.bg.dark,
tdTextColor: colors.body,
tdTextColor: colors.white,
thColor: colors.bg.DEFAULT,
thColorHover: colors.bg.DEFAULT,
thFontWeight: '700',
Expand Down
Loading

0 comments on commit b4e28eb

Please sign in to comment.