From 8793c95e64b4df3fc9cd090a53e78b2b50095070 Mon Sep 17 00:00:00 2001 From: liayoo Date: Thu, 8 Sep 2022 00:33:00 +0900 Subject: [PATCH 1/5] Add getUserCreditBalance(). --- src/asset.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/asset.ts b/src/asset.ts index e2141e1a..f992ccda 100644 --- a/src/asset.ts +++ b/src/asset.ts @@ -27,4 +27,17 @@ export default class Asset { 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) + .catch((e) => { + throw e.response.data; + }); + } } \ No newline at end of file From 36a298b6a1c6ced55e0a9dadb9af68d676c6c20d Mon Sep 17 00:00:00 2001 From: liayoo Date: Thu, 8 Sep 2022 00:33:15 +0900 Subject: [PATCH 2/5] Add getPendingRewards(), reward(). --- src/event.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/event.ts b/src/event.ts index d6c4ccb1..0fcc8593 100644 --- a/src/event.ts +++ b/src/event.ts @@ -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, amount?: number) { + const data: any = { + appId, + userId, + eventId, + timestamp: Date.now(), + }; + if (amount !== undefined) data.amount = amount; + 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; + }); + } + } From 8a8b3abde6ea8c1ded7f962dc66baf7d6c6837b5 Mon Sep 17 00:00:00 2001 From: liayoo Date: Thu, 8 Sep 2022 00:33:25 +0900 Subject: [PATCH 3/5] Add NFT_GAME to TaskTypeCategory. --- src/types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/types.ts b/src/types.ts index 75f555a9..00882888 100644 --- a/src/types.ts +++ b/src/types.ts @@ -13,6 +13,7 @@ export enum RewardDistributeType { export enum TaskTypeCategory { TWITTER_MINING = 'TWITTER_MINING', + NFT_GAME = 'NFT_GAME', } export enum Platforms { From a1805acc9bc9c4d2dcc13fdda82de08ad79d5bf7 Mon Sep 17 00:00:00 2001 From: liayoo Date: Thu, 8 Sep 2022 12:17:01 +0900 Subject: [PATCH 4/5] Update getUserNftList(). --- src/asset.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/asset.ts b/src/asset.ts index f992ccda..bbd193e6 100644 --- a/src/asset.ts +++ b/src/asset.ts @@ -15,11 +15,19 @@ 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) From 660878f0f543f4a33cd2f4c7083ea30b79a8af0a Mon Sep 17 00:00:00 2001 From: liayoo Date: Thu, 8 Sep 2022 12:17:14 +0900 Subject: [PATCH 5/5] Update reward options. --- src/event.ts | 6 +++--- src/types.ts | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/event.ts b/src/event.ts index 0fcc8593..635548bc 100644 --- a/src/event.ts +++ b/src/event.ts @@ -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; @@ -162,14 +162,14 @@ export default class Event { }); } - async reward(appId: string, userId: string, eventId: string, amount?: number) { + async reward(appId: string, userId: string, eventId: string, options?: RewardOptions) { const data: any = { appId, userId, eventId, timestamp: Date.now(), }; - if (amount !== undefined) data.amount = amount; + if (options) data.options = options; const signature = this.ain.wallet.sign(stringify(data)); return axios .post(`${this.baseUrl}/reward`, { data, signature }) diff --git a/src/types.ts b/src/types.ts index 00882888..4314a7ca 100644 --- a/src/types.ts +++ b/src/types.ts @@ -125,4 +125,8 @@ export interface User { ethAddresses?: { [ethAddress: string]: boolean, }, -} \ No newline at end of file +}; + +export interface RewardOptions { + amount?: number; +};