b5-api-client 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CreateOrderRequest, CreateUserRequest, GetOrdersParams, Order, OrderResponse, TakeOrderRequest, TestEventParams, UpdateOrderRequest } from './types';
|
|
1
|
+
import { CreateOrderRequest, CreateUserRequest, GetOrdersParams, Order, OrderResponse, TakeOrderRequest, TestEventParams, UpdateOrderRequest, TransactionStatusResponse } from './types';
|
|
2
2
|
declare class P2PMarketplaceAPIClient {
|
|
3
3
|
private readonly client;
|
|
4
4
|
private readonly defaultHeaders;
|
|
@@ -15,5 +15,7 @@ declare class P2PMarketplaceAPIClient {
|
|
|
15
15
|
updateOrder(updateRequest: UpdateOrderRequest, headers?: Record<string, string>): Promise<Order>;
|
|
16
16
|
testLockFunds(order: Order, testParams?: TestEventParams, headers?: Record<string, string>): Promise<void>;
|
|
17
17
|
testReleaseFunds(order: Order, testParams?: TestEventParams, headers?: Record<string, string>): Promise<void>;
|
|
18
|
+
releaseFunds(order: Order, testParams?: TestEventParams, headers?: Record<string, string>): Promise<string>;
|
|
19
|
+
getTransactionStatus(txHash: string, headers?: Record<string, string>): Promise<TransactionStatusResponse>;
|
|
18
20
|
}
|
|
19
21
|
export default P2PMarketplaceAPIClient;
|
|
@@ -174,6 +174,29 @@ class P2PMarketplaceAPIClient {
|
|
|
174
174
|
}
|
|
175
175
|
});
|
|
176
176
|
}
|
|
177
|
+
releaseFunds(order, testParams, headers) {
|
|
178
|
+
var _a;
|
|
179
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
const body = {
|
|
181
|
+
orderId: (_a = order.id) !== null && _a !== void 0 ? _a : "",
|
|
182
|
+
isAdmin: true
|
|
183
|
+
};
|
|
184
|
+
const url = "api/orders/release";
|
|
185
|
+
try {
|
|
186
|
+
return yield this.post(url, body, headers);
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
console.error("Error releasing funds:", error);
|
|
190
|
+
throw new Error("Failed to release funds");
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
getTransactionStatus(txHash, headers) {
|
|
195
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
196
|
+
const url = `/api/blockchain/transactions/${txHash}`;
|
|
197
|
+
return this.get(url, headers);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
177
200
|
}
|
|
178
201
|
function toSnakeCase(obj) {
|
|
179
202
|
if (Array.isArray(obj)) {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
export type OrderType = 'SELL' | 'BUY';
|
|
2
|
-
export type OrderStatus = '
|
|
2
|
+
export type OrderStatus = 'WAITING_PAYMENT' | 'WAITING_BUYER_ADDRESS' | 'PENDING' | 'ACTIVE' | 'FIAT_SENT' | 'RELEASED' | 'CLOSED' | 'DISPUTE' | 'CANCELED' | 'SUCCESS' | 'PAID_HOLD_INVOICE' | 'CANCELED_BY_ADMIN' | 'EXPIRED' | 'COMPLETED_BY_ADMIN';
|
|
3
3
|
export interface PaymentMethod {
|
|
4
4
|
type: string;
|
|
5
5
|
username: string;
|
|
6
6
|
}
|
|
7
|
+
export interface TransactionStatusResponse {
|
|
8
|
+
hash: string;
|
|
9
|
+
block_number: number | null;
|
|
10
|
+
status: 'PENDING' | 'SUCCESSFULL' | 'FAILED';
|
|
11
|
+
}
|
|
7
12
|
export interface Order {
|
|
8
13
|
type: OrderType;
|
|
9
14
|
id?: string;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
-
import { CreateOrderRequest, CreateUserRequest, GetOrdersParams, Order, OrderLockedEvent, OrderResponse, ReleaseOrderEvent as OrderReleasedEvent, TakeOrderRequest, TestEventParams, UpdateOrderRequest } from './types';
|
|
2
|
+
import { CreateOrderRequest, CreateUserRequest, GetOrdersParams, Order, OrderLockedEvent, OrderResponse, ReleaseOrderEvent as OrderReleasedEvent, TakeOrderRequest, TestEventParams, UpdateOrderRequest, TransactionStatusResponse } from './types';
|
|
3
3
|
import { isPlainObject, camelCase, snakeCase, transform } from 'lodash';
|
|
4
4
|
|
|
5
5
|
class P2PMarketplaceAPIClient {
|
|
@@ -157,6 +157,26 @@ class P2PMarketplaceAPIClient {
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
+
public async releaseFunds(order: Order, testParams?: TestEventParams, headers?: Record<string, string>): Promise<string> {
|
|
161
|
+
const body = {
|
|
162
|
+
orderId: order.id ?? "",
|
|
163
|
+
isAdmin: true
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const url = "api/orders/release"
|
|
167
|
+
try {
|
|
168
|
+
return await this.post<string>(url, body, headers);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
console.error("Error releasing funds:", error);
|
|
171
|
+
throw new Error("Failed to release funds");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
public async getTransactionStatus(txHash: string, headers?: Record<string, string>): Promise<TransactionStatusResponse> {
|
|
176
|
+
const url = `/api/blockchain/transactions/${txHash}`;
|
|
177
|
+
return this.get<TransactionStatusResponse>(url, headers);
|
|
178
|
+
}
|
|
179
|
+
|
|
160
180
|
}
|
|
161
181
|
|
|
162
182
|
function toSnakeCase(obj: any): any {
|
package/src/types.ts
CHANGED
|
@@ -22,6 +22,12 @@ export interface PaymentMethod {
|
|
|
22
22
|
username: string;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
export interface TransactionStatusResponse {
|
|
26
|
+
hash: string;
|
|
27
|
+
block_number: number | null;
|
|
28
|
+
status: 'PENDING' | 'SUCCESSFULL' | 'FAILED';
|
|
29
|
+
}
|
|
30
|
+
|
|
25
31
|
export interface Order {
|
|
26
32
|
type: OrderType;
|
|
27
33
|
id?: string;
|