Skip to content

Commit

Permalink
[Issue-194] Update sdk for rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
saltict committed Dec 19, 2024
1 parent fdfe59e commit d99c9c7
Show file tree
Hide file tree
Showing 2 changed files with 184 additions and 13 deletions.
162 changes: 149 additions & 13 deletions packages/extension-koni-ui/src/connector/booka/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Copyright 2019-2022 @subwallet/extension authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { InGameItem } from '@playnation/game-sdk';
import { GameState } from '@playnation/game-sdk/dist/types';
import { SWStorage } from '@subwallet/extension-base/storage';
import { createPromiseHandler, detectTranslate } from '@subwallet/extension-base/utils';
import { AppMetadata, MetadataHandler } from '@subwallet/extension-koni-ui/connector/booka/metadata';
import { AccountRankType, Achievement, AirdropCampaign, AirdropEligibility, AirdropRaffle, AirdropRewardHistoryLog, BookaAccount, ClaimableAchievement, EnergyConfig, Game, GameEvent, GameInventoryItem, GameItem, GamePlay, LeaderboardPerson, LeaderboardResult, MythicalWallet, NFLRivalCard, RankInfo, ReferralData, Task, TaskCategory } from '@subwallet/extension-koni-ui/connector/booka/types';
import { TelegramConnector } from '@subwallet/extension-koni-ui/connector/telegram';
import { signRaw } from '@subwallet/extension-koni-ui/messaging';
import { populateTemplateString } from '@subwallet/extension-koni-ui/utils';
import { formatDateFully } from '@subwallet/extension-koni-ui/utils/date';
import {InGameItem} from '@playnation/game-sdk';
import {GameState} from '@playnation/game-sdk/dist/types';
import {SWStorage} from '@subwallet/extension-base/storage';
import {createPromiseHandler, detectTranslate} from '@subwallet/extension-base/utils';
import {AppMetadata, MetadataHandler} from '@subwallet/extension-koni-ui/connector/booka/metadata';
import {AccountRankType, Achievement, AirdropCampaign, AirdropEligibility, AirdropRaffle, AirdropRewardHistoryLog, BookaAccount, ClaimableAchievement, EnergyConfig, Game, GameEvent, GameInventoryItem, GameItem, GamePlay, LeaderboardPerson, LeaderboardResult, MythicalWallet, NFLRivalCard, RankInfo, ReferralData, Reward, RewardStatus, RewardType, Task, TaskCategory} from '@subwallet/extension-koni-ui/connector/booka/types';
import {TelegramConnector} from '@subwallet/extension-koni-ui/connector/telegram';
import {signRaw} from '@subwallet/extension-koni-ui/messaging';
import {populateTemplateString} from '@subwallet/extension-koni-ui/utils';
import {formatDateFully} from '@subwallet/extension-koni-ui/utils/date';
import fetch from 'cross-fetch';
import { deflate, inflate } from 'pako';
import { BehaviorSubject } from 'rxjs';
import {deflate, inflate} from 'pako';
import {BehaviorSubject} from 'rxjs';

import { stringToU8a, u8aToString } from '@polkadot/util';
import {stringToU8a, u8aToString} from '@polkadot/util';

export const DEFAULT_INIT_DATA = process.env.DEFAULT_INIT_DATA;
export const GAME_API_HOST = process.env.GAME_API_HOST || 'https://game-api.anhmtv.xyz';
Expand Down Expand Up @@ -95,6 +95,7 @@ export class BookaSdk {
private rankInfoSubject = new BehaviorSubject<Record<AccountRankType, RankInfo> | undefined>(undefined);
private airdropCampaignSubject = new BehaviorSubject<AirdropCampaign[]>([]);
private checkEligibility = new BehaviorSubject<AirdropEligibility[]>([]);
private rewardListSubject = new BehaviorSubject<Reward[]>([]);
private leaderboardConfigSubject = new BehaviorSubject<Record<string, object>>({});
private nflRivalCardListSubject = new BehaviorSubject<NFLRivalCard[]>([]);
private metadataSubject = new BehaviorSubject<AppMetadata | undefined>(undefined);
Expand Down Expand Up @@ -1048,6 +1049,141 @@ export class BookaSdk {
}
}

async fetchRewardList (): Promise<Reward[]> {
await new Promise((resolve) => setTimeout(resolve, 1000));

const result = [
{
airdrop_log_id: 1,
airdrop_record_id: 1,
type: RewardType.TOKEN,
campaign_id: 1,
campaign_method: 'raffle',
campaign_name: 'Weekly Leaderboard (W45)',
eligibility_name: 'Top 10 Weekly Leaderboard (W45)',
eligibility_end: 1,
expiryDate: 1735116370,
status: RewardStatus.EXPIRED,
account_id: 1,
eligibility_id: 1,
address: '',
point: 0,
network: 'mythos',
token_slug: 'mythos-NATIVE-MYTH',
decimal: 18,
token: 10
},
{
airdrop_log_id: 2,
airdrop_record_id: 2,
type: RewardType.TOKEN,
campaign_id: 2,
campaign_method: 'raffle',
campaign_name: 'Weekly Leaderboard (W46)',
eligibility_name: 'Top 10 Weekly Leaderboard (W46)',
eligibility_end: 2,
expiryDate: 1735116370,
status: RewardStatus.SUCCESS,
account_id: 2,
eligibility_id: 2,
address: '',
point: 0,
network: 'mythos',
token_slug: 'mythos-NATIVE-MYTH',
decimal: 18,
token: 15
},
{
airdrop_log_id: 3,
airdrop_record_id: 3,
type: RewardType.TOKEN,
campaign_id: 3,
campaign_method: 'raffle',
campaign_name: 'Weekly Leaderboard (W47)',
eligibility_name: 'Top 10 Weekly Leaderboard (W47)',
eligibility_end: 3,
expiryDate: 1735116370,
status: RewardStatus.PROCESSING,
account_id: 3,
eligibility_id: 3,
address: '',
point: 0,
network: 'mythos',
token_slug: 'mythos-NATIVE-MYTH',
decimal: 18,
token: 18
},
{
airdrop_log_id: 4,
airdrop_record_id: 4,
type: RewardType.TOKEN,
campaign_id: 4,
campaign_method: 'raffle',
campaign_name: 'Weekly Leaderboard (W48)',
eligibility_name: 'Top 10 Weekly Leaderboard (W48)',
eligibility_end: 4,
expiryDate: 1735116370,
status: RewardStatus.FAILED,
account_id: 4,
eligibility_id: 4,
address: '',
point: 0,
network: 'mythos',
token_slug: 'mythos-NATIVE-MYTH',
decimal: 18,
token: 14
},
{
airdrop_log_id: 6,
airdrop_record_id: 6,
type: RewardType.TOKEN,
campaign_id: 6,
campaign_method: 'raffle',
campaign_name: 'Weekly Leaderboard (W49)',
eligibility_name: 'Top 10 Weekly Leaderboard (W49)',
eligibility_end: 6,
expiryDate: 1735116370,
status: RewardStatus.PENDING,
account_id: 6,
eligibility_id: 6,
address: '',
point: 0,
network: 'mythos',
token_slug: 'mythos-NATIVE-MYTH',
decimal: 18,
token: 12
},
{
airdrop_log_id: 7,
airdrop_record_id: 7,
type: RewardType.TOKEN,
campaign_id: 7,
campaign_method: 'raffle',
campaign_name: 'Weekly Leaderboard (50)',
eligibility_name: 'Top 10 Weekly Leaderboard (50)',
eligibility_end: 7,
expiryDate: 1735116370,
status: RewardStatus.IN_REVIEW,
account_id: 7,
eligibility_id: 7,
address: '',
point: 0,
network: 'mythos',
token_slug: 'mythos-NATIVE-MYTH',
decimal: 18,
token: 11
}
]

this.rewardListSubject.next(result);

return result;
}

subscribeRewardList () {
return this.rewardListSubject;
}

async claimRaffle (airdropLogId: number) {
try {
const claim = await this.postRequest(`${GAME_API_HOST}/api/airdrop/claim`, { airdrop_log_id: airdropLogId });
Expand Down
35 changes: 35 additions & 0 deletions packages/extension-koni-ui/src/connector/booka/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,41 @@ export interface AirdropEligibility {
eligibilityIds?: number[];
}

export enum RewardStatus {
IN_REVIEW = 'IN_REVIEW',
PENDING = 'PENDING',
PROCESSING = 'PROCESSING',
FAILED = 'FAILED',
EXPIRED = 'EXPIRED',
SUCCESS = 'SUCCESS',
}

export enum RewardType {
NPS = 'NPS',
TOKEN = 'TOKEN',
}

export interface Reward {
airdrop_log_id: number
airdrop_record_id: number
type: RewardType
campaign_id: number
campaign_method: string
campaign_name: string
eligibility_name?: string
eligibility_end?: number
expiryDate: number
status: RewardStatus
account_id: number
eligibility_id: number
address?: string
point: number
network: string
token: number
token_slug?: string
decimal: number
}

export interface AirdropRaffle {
airdropRecordLogId: number,
rewardAmount: number,
Expand Down

0 comments on commit d99c9c7

Please sign in to comment.