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

Feature/referral system #183

Open
wants to merge 32 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4028f7f
Create RINBOT_URL constant
bathord Apr 29, 2024
df2265e
Upd fees in instant buy conv
bathord Apr 29, 2024
b9180df
Add fees to sell conversation
bathord Apr 29, 2024
a4a67bc
Add REFERRER_FEE_SHARE_PERCENTAGE to trading config
bathord Apr 29, 2024
cfbb336
Create getSwapFees() method
bathord Apr 29, 2024
006ae7e
Create referral config
bathord Apr 29, 2024
3b6091e
Create referral utils
bathord Apr 29, 2024
6ee23f1
Create redis referral utils
bathord Apr 29, 2024
e7dfb2f
Add referral field to session & create migration
bathord Apr 29, 2024
a4f4e16
Create back to referral menu inline keyboard
bathord Apr 29, 2024
ae7b684
Create change referrer conv
bathord Apr 29, 2024
f5fd03c
Create handleReferralFollow() method
bathord Apr 29, 2024
71f7a61
Create referral menus
bathord Apr 29, 2024
02cd85a
Create referral pages
bathord Apr 29, 2024
b5345b9
Add referral button to settings menu
bathord Apr 29, 2024
e504f97
Upd index
bathord Apr 29, 2024
7b7cddc
Add qr-code-styling-node to deps
bathord Apr 29, 2024
0604904
Add RINBOT_LOGO_URL constant
bathord Apr 29, 2024
aa1a4aa
Create REFERRAL_QR_CODE_CONFIG constant
bathord Apr 29, 2024
82031f0
Create getReferralQrCode() method
bathord Apr 29, 2024
4893f85
Create referral QR-code page
bathord Apr 29, 2024
6a38255
Handle case when user tries to change his referrer to his current ref…
bathord Apr 29, 2024
eb82a75
Add referral QR-code showing
bathord Apr 29, 2024
74e24fe
Move referrer id check out from if
bathord Apr 29, 2024
c1a35a4
Upd message in askForReferrerId()
bathord Apr 29, 2024
f62f880
Add ReferralsTrades to ReferralRedisKeyFirstPart enum
bathord Apr 30, 2024
543253c
Create addReferralTrade() & getReferralsTrades()
bathord Apr 30, 2024
20bfde2
Create type guard for ReferralTradeData type
bathord Apr 30, 2024
573c6c2
Create ReferralTradeData type
bathord Apr 30, 2024
881a55d
Create coin type & coin amount types
bathord Apr 30, 2024
ea5f29d
Add referral trade storing
bathord Apr 30, 2024
63dbb85
Show earned fees to referrer
bathord Apr 30, 2024
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
Prev Previous commit
Next Next commit
Create getReferralQrCode() method
  • Loading branch information
bathord committed Apr 29, 2024
commit 82031f00bdfbffe1bce35b6d14ce481b90bb33ae
17 changes: 15 additions & 2 deletions src/chains/referral/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { QRCodeCanvas } from '@loskir/styled-qr-code-node';
import { InputFile } from 'grammy';
import { BotContext, MyConversation } from '../../types';
import { RINBOT_URL } from '../sui.config';
import { PARAMS_SEPARATOR, REF_PARAM_KEY } from './config';
import { RINBOT_LOGO_URL, RINBOT_URL } from '../sui.config';
import { imageUrlToBase64 } from '../utils';
import { PARAMS_SEPARATOR, REFERRAL_QR_CODE_CONFIG, REF_PARAM_KEY } from './config';
import { getReferrerPublicKey } from './redis/utils';

export function generateReferralId(): string {
Expand All @@ -11,6 +14,16 @@ export function getReferralLink(referralId: string): string {
return `${RINBOT_URL}?start=${REF_PARAM_KEY}=${referralId}`;
}

export async function getReferralQrCode(referralLink: string): Promise<InputFile> {
const rinbotLogoBase64 = await imageUrlToBase64(RINBOT_LOGO_URL);
const qrCode = new QRCodeCanvas({ ...REFERRAL_QR_CODE_CONFIG, data: referralLink, image: rinbotLogoBase64 });

const buffer = await qrCode.toBuffer();
const file = new InputFile(buffer);

return file;
}

export function getReferrerIdByParams(params: string) {
const separatorIndex = params.indexOf(PARAMS_SEPARATOR);

Expand Down