diff --git a/src/methods/getPendingTransactions.ts b/src/methods/getPendingTransactions.ts index 8d1542a..726027c 100644 --- a/src/methods/getPendingTransactions.ts +++ b/src/methods/getPendingTransactions.ts @@ -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'; @@ -76,47 +77,3 @@ const MapResults = async (data: any): Promise => { return transactions; }; - -const BuildTradeItems = async (tradeItems: any): Promise => { - 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 => { - 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, - }; -}; diff --git a/src/methods/getTransactionHistory.ts b/src/methods/getTransactionHistory.ts index 4cb6ca8..f6f3d51 100644 --- a/src/methods/getTransactionHistory.ts +++ b/src/methods/getTransactionHistory.ts @@ -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'; @@ -81,63 +82,3 @@ const MapResults = async (data: any): Promise => { return transactions; }; - -const BuildTradeItems = async (tradeItems: any): Promise => { - 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 => { - 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 => { - const defualtPayment: Payment = { - price: 0, - transactionFee: 0, - }; - - if (!payment || payment.length === 0) return defualtPayment; - - const { price, transactionFee } = payment; - - return { - price, - transactionFee, - }; -}; diff --git a/src/utils/helperFunctions.ts b/src/utils/helperFunctions.ts index 7b91da3..389780b 100644 --- a/src/utils/helperFunctions.ts +++ b/src/utils/helperFunctions.ts @@ -19,6 +19,9 @@ import { ItemNamesDESC, ItemNamesASC, MarkplaceSearchType, + Item, + PaymentOptions, + Payment, } from '../interfaces/marketplace'; // ============== Marketplace Helper Functions ============== @@ -201,4 +204,64 @@ export const ReturnSortBy = async ( } }; +export const BuildTradeItems = async (tradeItems: any): Promise => { + 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 => { + 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 => { + const defualtPayment: Payment = { + price: 0, + transactionFee: 0, + }; + + if (!payment || payment.length === 0) return defualtPayment; + + const { price, transactionFee } = payment; + + return { + price, + transactionFee, + }; +}; + // ==========================================================