Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
chore: rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
javiergarciavera committed Jan 30, 2023
1 parent c3a3e5c commit bc5aada
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 280 deletions.
8 changes: 7 additions & 1 deletion e2e/sdk.erc721.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Auth from '../src/lib/Auth/Auth';
import { SDK } from '../src/lib/SDK/sdk';
import { TEMPLATES } from '../src/lib/constants';
import wait, { existingContractAddress } from './utils/utils.ts/utils';
import { MetadataDTO, OwnersDTO } from '../src/lib/SDK/types';
import { CollectionsDTO, MetadataDTO, OwnersDTO } from '../src/lib/SDK/types';

loadEnv();
const ownerAddress = process.env.WALLET_PUBLIC_ADDRESS
Expand Down Expand Up @@ -68,6 +68,12 @@ describe('SDK - contract interaction (deploy, load and mint)', () => {
expect(response2.total).toBeGreaterThan(response.total);
expect(response2.assets[0].metadata).toEqual(undefined);

const responseGetCollectionByWallet: CollectionsDTO = await sdk.api.getCollectionsByWallet({
walletAddress: '0x3bE0Ec232d2D9B3912dE6f1ff941CB499db4eCe7',
});

expect(responseGetCollectionByWallet.collections).not.toBeNull();

await wait(async () => {
const nfts = await sdk.api.getNFTs({ publicAddress: ownerAddress, includeMetadata: true });
const token = await nfts.assets.filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { config as loadEnv } from 'dotenv';
import { SDK } from '../../src/lib/SDK/sdk';
import Auth from '../../src/lib/Auth/Auth';
import { NftDTO } from '../../src/lib/SDK/types';
import { GetCollectionsByWallet } from '../../src/lib/Api/api';
import version from '../../src/_version';

loadEnv();

Expand Down Expand Up @@ -127,4 +129,49 @@ describe('E2E Test: Sdk (read)', () => {
expect(tokenMetadata).toStrictEqual(expectedTokenMetadata);
});
});

describe('As an account I should get list of collections that i have created', () => {
const walletAddress = '0xd8da6bf26964af9d7eed9e03e53415d37aa96045';
it('should get list of collections', async () => {
const result = await sdk.api.getCollectionsByWallet({
walletAddress,
});

expect(result).toMatchObject({
total: expect.any(Number),
pageNumber: 1,
pageSize: expect.any(Number),
network: expect.any(String),
cursor: null,
account: walletAddress,
collections: expect.arrayContaining([
expect.objectContaining({
contract: expect.any(String),
tokenType: expect.any(String),
name: expect.any(String),
symbol: expect.any(String),
}),
]),
});
});

it('should throw when "walletAddress" is not a valid address', async () => {
expect(
async () =>
await sdk.api.getCollectionsByWallet({
walletAddress: 'notAValidAddress',
}),
).rejects.toThrow(
`missing argument: Invalid account address. (location=\"[SDK.getCollectionsByWallet]\", code=MISSING_ARGUMENT, version=${version})`,
);
});

it('should throw when wallet address is not provided', async () => {
expect(
async () => await sdk.api.getCollectionsByWallet({} as GetCollectionsByWallet),
).rejects.toThrow(
`missing argument: Invalid account address. (location=\"[SDK.getCollectionsByWallet]\", code=MISSING_ARGUMENT, version=${version})`,
);
});
});
});
33 changes: 31 additions & 2 deletions src/lib/Api/api.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { utils } from 'ethers';
import { log, Logger } from '../Logger';
import HttpService from '../../services/httpService';

import { MetadataDTO, MetadataInfo, NftDTO, OwnersDTO, TradeDTO, TransfersDTO } from '../SDK/types';
import {
CollectionsDTO,
MetadataDTO,
MetadataInfo,
NftDTO,
TransfersDTO,
TradeDTO,
OwnersDTO,
} from '../SDK/types';
import { isValidPositiveNumber } from '../utils';

type PublicAddressOptions = {
Expand Down Expand Up @@ -67,6 +74,11 @@ export type GetLowestTradePrice = {
tokenAddress: string;
};

export type GetCollectionsByWallet = {
walletAddress: string;
cursor?: string;
};

export default class Api {
private readonly apiPath: string;

Expand Down Expand Up @@ -359,4 +371,21 @@ export default class Api {
const { data } = await this.httpClient.get(apiUrl, { cursor: opts.cursor });
return data;
}

/* Get NFT collections owned by a given wallet address.
* @param {object} opts object containing all parameters
* @returns {Promise<object>} Transfers list
*/
async getCollectionsByWallet(opts: GetCollectionsByWallet): Promise<CollectionsDTO> {
if (!opts.walletAddress || !utils.isAddress(opts.walletAddress)) {
log.throwMissingArgumentError(Logger.message.invalid_account_address, {
location: Logger.location.SDK_GET_COLLECTION_BY_WALLET,
});
}

const apiUrl = `${this.apiPath}/accounts/${opts.walletAddress}/assets/collections`;
const { cursor } = opts;
const { data } = await this.httpClient.get(apiUrl, { cursor });
return data;
}
}
2 changes: 2 additions & 0 deletions src/lib/Logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export enum ErrorLocation {
SDK_GET_TRANSFERS_BY_CONTRACT = '[SDK.getTransfersByContractAddress]',
SDK_GET_OWNERS_BY_TOKEN_ADDRESS = '[SDK.getOwnersByTokenAddress]',
SDK_GET_OWNERS_BY_TOKEN_ADDRESS_AND_TOKEN_ID = '[SDK.getOwnersbyTokenAddressAndTokenId]',
SDK_GET_COLLECTION_BY_WALLET = '[SDK.getCollectionsByWallet]',

SDK_GET_LOWEST_TRADE_PRICE = '[SDK.getLowestTradePrice]',

// Metadata
Expand Down
3 changes: 2 additions & 1 deletion src/lib/SDK/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { DeployERC1155Params } from '../ContractTemplates/ERC1155Mintable';
export type NftDTO = Components['schemas']['NftModel'];
export type MetadataDTO = Components['schemas']['MetadataModel'];
export type TransfersDTO = Components['schemas']['TransfersModel'];
export type TradeDTO = Components['schemas']['TradeModel'];
export type OwnersDTO = Components['schemas']['OwnersModel'];
export type TradeDTO = Components['schemas']['TradePriceModel'];
export type CollectionsDTO = Components['schemas']['CollectionByWalletModel'];

export type MetadataInfo = {
symbol: string;
Expand Down
Loading

0 comments on commit bc5aada

Please sign in to comment.