Skip to content

Commit

Permalink
Merge pull request #17 from ainft-team/feature/liayoo/rewards
Browse files Browse the repository at this point in the history
Feature/liayoo/rewards
  • Loading branch information
liayoo authored Sep 8, 2022
2 parents 1364d49 + 660878f commit ea10e48
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
25 changes: 23 additions & 2 deletions src/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,32 @@ export default class Asset {
this.baseUrl = `${baseUrl}/asset`;
}

async getUserNftList(appId: string, ethAddress: string) {
async getUserNftList(
appId: string,
chainId: string,
ethAddress: string,
contractAddress?: string,
) {
const data = { appId, timestamp: Date.now() };
const signature = this.ain.wallet.sign(stringify(data));
const url = contractAddress
? `${this.baseUrl}/nft/${chainId}/${ethAddress}/${contractAddress}`
: `${this.baseUrl}/nft/${chainId}/${ethAddress}`
return axios
.get(`${this.baseUrl}/nft-list/${ethAddress}`, {
.get(url, {
data: { data, signature },
})
.then((res) => res.data.data)
.catch((e) => {
throw e.response.data;
});
}

async getUserCreditBalance(appId: string, symbol: string, userId: string) {
const data = { appId, timestamp: Date.now() };
const signature = this.ain.wallet.sign(stringify(data));
return axios
.get(`${this.baseUrl}/credit/${appId}/${symbol}/${userId}`, {
data: { data, signature },
})
.then((res) => res.data.data)
Expand Down
33 changes: 32 additions & 1 deletion src/event.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ain from '@ainblockchain/ain-js';
import axios from 'axios';
import stringify = require('fast-json-stable-stringify');
import { AddEventActivityParams, CreateEventParams } from './types';
import { AddEventActivityParams, CreateEventParams, RewardOptions } from './types';

export default class Event {
private baseUrl: string;
Expand Down Expand Up @@ -148,4 +148,35 @@ export default class Event {
throw e.response.data;
});
}

async getPendingRewards(appId: string, userId: string, eventId: string) {
const data = { appId, userId, eventId, timestamp: Date.now() };
const signature = this.ain.wallet.sign(stringify(data));
return axios
.get(`${this.baseUrl}/pending-rewards`, {
data: { data, signature },
})
.then((res) => res.data.data)
.catch((e) => {
throw e.response.data;
});
}

async reward(appId: string, userId: string, eventId: string, options?: RewardOptions) {
const data: any = {
appId,
userId,
eventId,
timestamp: Date.now(),
};
if (options) data.options = options;
const signature = this.ain.wallet.sign(stringify(data));
return axios
.post(`${this.baseUrl}/reward`, { data, signature })
.then((res) => res.data.data)
.catch((e) => {
throw e.response.data;
});
}

}
7 changes: 6 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export enum RewardDistributeType {

export enum TaskTypeCategory {
TWITTER_MINING = 'TWITTER_MINING',
NFT_GAME = 'NFT_GAME',
}

export enum Platforms {
Expand Down Expand Up @@ -124,4 +125,8 @@ export interface User {
ethAddresses?: {
[ethAddress: string]: boolean,
},
}
};

export interface RewardOptions {
amount?: number;
};

0 comments on commit ea10e48

Please sign in to comment.