Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
CalumW1 committed Oct 10, 2024
1 parent 16c3ab1 commit 29042b2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 104 deletions.
45 changes: 1 addition & 44 deletions src/methods/getPendingTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
X_PLATFORM_APPID,
} from '../constants';
import { Item, PaymentOptions, Transaction, Transactions } from '../interfaces/marketplace';
import { BuildPaymentOptions, BuildTradeItems } from '../utils/helperFunctions';
import { ApiClient } from './apiClient';
import { CheckToken } from './auth';

Expand Down Expand Up @@ -76,47 +77,3 @@ const MapResults = async (data: any): Promise<Transactions> => {

return transactions;
};

const BuildTradeItems = async (tradeItems: any): Promise<Item> => {
const defaultItem: Item = {
id: '',
assetUrl: '',
itemId: '',
name: '',
tags: [],
type: '',
};
if (!tradeItems || tradeItems.length === 0) {
return defaultItem;
}

const { id, itemId, assetUrl, name, tags, type } = tradeItems[0].item;

return {
id,
itemId,
assetUrl,
name,
tags,
type,
};
};

const BuildPaymentOptions = async (options: any): Promise<PaymentOptions> => {
const defualtPaymentOptions: PaymentOptions = {
quantity: 0,
price: 0,
transactionFee: 0,
};

if (!options || options.length === 0) return defualtPaymentOptions;

const { quantity } = options[0].item.viewer.meta;
const { price, transactionFee } = options[0];

return {
quantity,
price,
transactionFee,
};
};
61 changes: 1 addition & 60 deletions src/methods/getTransactionHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Transaction,
Transactions,
} from '../interfaces/marketplace';
import { BuildPayment, BuildPaymentOptions, BuildTradeItems } from '../utils/helperFunctions';
import { ApiClient } from './apiClient';
import { CheckToken } from './auth';

Expand Down Expand Up @@ -81,63 +82,3 @@ const MapResults = async (data: any): Promise<Transactions> => {

return transactions;
};

const BuildTradeItems = async (tradeItems: any): Promise<Item> => {
const defaultItem: Item = {
id: '',
assetUrl: '',
itemId: '',
name: '',
tags: [],
type: '',
};
if (!tradeItems || tradeItems.length === 0) {
return defaultItem;
}

const { id, itemId, assetUrl, name, tags, type } = tradeItems[0].item;

return {
id,
itemId,
assetUrl,
name,
tags,
type,
};
};

const BuildPaymentOptions = async (options: any): Promise<PaymentOptions> => {
const defualtPaymentOptions: PaymentOptions = {
price: 0,
transactionFee: 0,
quantity: 0,
};

if (!options || options.length === 0) return defualtPaymentOptions;

const { quantity } = options[0].item.viewer.meta;
const { price, transactionFee } = options[0];

return {
quantity,
price,
transactionFee,
};
};

const BuildPayment = async (payment: any): Promise<Payment> => {
const defualtPayment: Payment = {
price: 0,
transactionFee: 0,
};

if (!payment || payment.length === 0) return defualtPayment;

const { price, transactionFee } = payment;

return {
price,
transactionFee,
};
};
63 changes: 63 additions & 0 deletions src/utils/helperFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import {
ItemNamesDESC,
ItemNamesASC,
MarkplaceSearchType,
Item,
PaymentOptions,
Payment,
} from '../interfaces/marketplace';

// ============== Marketplace Helper Functions ==============
Expand Down Expand Up @@ -201,4 +204,64 @@ export const ReturnSortBy = async (
}
};

export const BuildTradeItems = async (tradeItems: any): Promise<Item> => {
const defaultItem: Item = {
id: '',
assetUrl: '',
itemId: '',
name: '',
tags: [],
type: '',
};
if (!tradeItems || tradeItems.length === 0) {
return defaultItem;
}

const { id, itemId, assetUrl, name, tags, type } = tradeItems[0].item;

return {
id,
itemId,
assetUrl,
name,
tags,
type,
};
};

export const BuildPaymentOptions = async (options: any): Promise<PaymentOptions> => {
const defualtPaymentOptions: PaymentOptions = {
quantity: 0,
price: 0,
transactionFee: 0,
};

if (!options || options.length === 0) return defualtPaymentOptions;

const { quantity } = options[0].item.viewer.meta;
const { price, transactionFee } = options[0];

return {
quantity,
price,
transactionFee,
};
};

export const BuildPayment = async (payment: any): Promise<Payment> => {
const defualtPayment: Payment = {
price: 0,
transactionFee: 0,
};

if (!payment || payment.length === 0) return defualtPayment;

const { price, transactionFee } = payment;

return {
price,
transactionFee,
};
};

// ==========================================================

0 comments on commit 29042b2

Please sign in to comment.