@imtbl/checkout-widgets 2.4.7 → 2.4.8
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.
- package/.eslintrc.cjs +1 -1
- package/dist/browser/{AddTokensWidget-DUK0xSaH.js → AddTokensWidget-CjsKM-T9.js} +3 -3
- package/dist/browser/{BridgeWidget-QR1xBfOF.js → BridgeWidget-DVD0vbXw.js} +79 -204
- package/dist/browser/{CommerceWidget-DbkApbhd.js → CommerceWidget-6Bk4VqFB.js} +13 -13
- package/dist/browser/{FeesBreakdown-C9jaHA04.js → FeesBreakdown-DJ8ernNZ.js} +1 -1
- package/dist/browser/{OnRampWidget-BFnyKHnm.js → OnRampWidget-70zEixzs.js} +3 -3
- package/dist/browser/{SaleWidget-Dkz59HGP.js → SaleWidget-POpNJFz2.js} +11 -10
- package/dist/browser/{SpendingCapHero-wnemhkzF.js → SpendingCapHero-C1OAzZ0n.js} +1 -1
- package/dist/browser/{SwapWidget-D4v53qed.js → SwapWidget-BhBc76QL.js} +6 -6
- package/dist/browser/{TokenImage-y9yHy5FI.js → TokenImage-9_8xOVNs.js} +1 -1
- package/dist/browser/{TopUpView-Cw5fRr6J.js → TopUpView-DpVUPPQE.js} +1 -1
- package/dist/browser/{WalletApproveHero-CqkvX4i7.js → WalletApproveHero-BHSPmZJh.js} +2 -2
- package/dist/browser/{WalletWidget-Dj-DhyiY.js → WalletWidget-JvUIuAdq.js} +3 -3
- package/dist/browser/{auto-track-BiAYJzx-.js → auto-track-Qz7LJ7YA.js} +1 -1
- package/dist/browser/{index-DAskMD3i.js → index-B8U0yV6w.js} +1 -1
- package/dist/browser/{index-OuEh4lB4.js → index-BFdJZ7kd.js} +1 -1
- package/dist/browser/{index-BBEStEr8.js → index-BLySvWQF.js} +2 -2
- package/dist/browser/{index-mwYRhIMX.js → index-DDEez-8b.js} +21 -28
- package/dist/browser/{index-YqoOzflx.js → index-JULMMCb5.js} +1 -1
- package/dist/browser/{index-CsCOnnNv.js → index-OzMQ0nH8.js} +1 -1
- package/dist/browser/{index-C2r0JBIr.js → index-nyzac6M7.js} +1 -1
- package/dist/browser/{index-D5YHQOIu.js → index-o1Wg1vKu.js} +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/browser/{index.umd-DryKZ_qj.js → index.umd-DdybBYbs.js} +1 -1
- package/dist/browser/{useInterval-D69Yoe3f.js → useInterval-CKXa8zia.js} +1 -1
- package/dist/types/components/Transactions/noTransactionStyles.d.ts +1 -0
- package/dist/types/components/Transactions/transactionItemStyles.d.ts +0 -12
- package/dist/types/lib/clients/checkoutApiType.d.ts +1 -8
- package/dist/types/lib/clients/index.d.ts +0 -1
- package/package.json +9 -9
- package/src/components/Transactions/NoTransactions.tsx +6 -0
- package/src/components/Transactions/TransactionItemWithdrawPending.tsx +3 -3
- package/src/components/Transactions/TransactionList.tsx +3 -40
- package/src/components/Transactions/Transactions.tsx +50 -28
- package/src/components/Transactions/noTransactionStyles.ts +1 -0
- package/src/components/Transactions/transactionItemStyles.ts +0 -13
- package/src/lib/clients/checkoutApiType.ts +1 -10
- package/src/lib/clients/index.ts +0 -1
- package/src/widgets/purchase/components/WithCard.tsx +1 -0
- package/src/widgets/sale/components/WithCard.tsx +1 -0
- package/dist/types/components/Transactions/TransactionItem.d.ts +0 -18
- package/dist/types/lib/clients/checkoutApi.d.ts +0 -39
- package/dist/types/lib/clients/checkoutApi.test.d.ts +0 -1
- package/src/components/Transactions/TransactionItem.tsx +0 -137
- package/src/lib/clients/checkoutApi.test.ts +0 -169
- package/src/lib/clients/checkoutApi.ts +0 -102
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/naming-convention: off */
|
|
2
|
-
import axios, { AxiosError, HttpStatusCode } from 'axios';
|
|
3
|
-
import { Environment } from '@imtbl/config';
|
|
4
|
-
import { TransactionType } from './checkoutApiType';
|
|
5
|
-
import { CheckoutApi } from './checkoutApi';
|
|
6
|
-
|
|
7
|
-
jest.mock('axios');
|
|
8
|
-
const mockedAxios = axios as jest.Mocked<typeof axios>;
|
|
9
|
-
|
|
10
|
-
describe('CheckoutApi', () => {
|
|
11
|
-
afterEach(() => {
|
|
12
|
-
jest.clearAllMocks();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
describe('getTransactions', () => {
|
|
16
|
-
it('success', async () => {
|
|
17
|
-
const mockResponse = {
|
|
18
|
-
status: 200,
|
|
19
|
-
data:
|
|
20
|
-
{
|
|
21
|
-
result: [
|
|
22
|
-
{
|
|
23
|
-
type: 'bridge',
|
|
24
|
-
details: {
|
|
25
|
-
from_address: '0x1234567890',
|
|
26
|
-
from_chain: 'imtbl-zkevm-testnet',
|
|
27
|
-
amount: '100000000000000000',
|
|
28
|
-
from_token_address: 'native',
|
|
29
|
-
to_address: '0x1e8dc77bed0da06621e819fa0afb59d50f76cfdf',
|
|
30
|
-
to_chain: 'sepolia',
|
|
31
|
-
to_token_address: '0x60466acb9e525ae1e9978fd14197c8c419ba65e6',
|
|
32
|
-
current_status: {
|
|
33
|
-
status: 'in_progress',
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
blockchain_metadata: {
|
|
37
|
-
transaction_hash: '0x68d9eac5e3b3c3580404989a4030c948a78e1b07b2b5ea5688d8c38a6c61c93e',
|
|
38
|
-
},
|
|
39
|
-
updated_at: '2022-08-16T17:43:26.991388Z',
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
mockedAxios.get.mockResolvedValueOnce(mockResponse);
|
|
45
|
-
|
|
46
|
-
const txType = TransactionType.BRIDGE;
|
|
47
|
-
const fromAddress = '0x1234567890';
|
|
48
|
-
const client = new CheckoutApi({ env: Environment.SANDBOX });
|
|
49
|
-
const resp = await client.getTransactions({ fromAddress, txType });
|
|
50
|
-
|
|
51
|
-
// should not contain native token data
|
|
52
|
-
expect(resp.result.length).toEqual(1);
|
|
53
|
-
expect(
|
|
54
|
-
resp.result[0].blockchain_metadata.transaction_hash,
|
|
55
|
-
).toEqual('0x68d9eac5e3b3c3580404989a4030c948a78e1b07b2b5ea5688d8c38a6c61c93e');
|
|
56
|
-
expect(resp.result[0].details.from_address).toEqual('0x1234567890');
|
|
57
|
-
expect(resp.result[0].details.from_chain).toEqual('imtbl-zkevm-testnet');
|
|
58
|
-
expect(resp.result[0].details.current_status.status).toEqual('in_progress');
|
|
59
|
-
|
|
60
|
-
expect(mockedAxios.get).toHaveBeenNthCalledWith(
|
|
61
|
-
1,
|
|
62
|
-
`${client.url}/v1/transactions?from_address=${fromAddress}&tx_type=${txType}`,
|
|
63
|
-
);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('success cached', async () => {
|
|
67
|
-
const mockResponse = {
|
|
68
|
-
status: 200,
|
|
69
|
-
data:
|
|
70
|
-
{
|
|
71
|
-
result: [],
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
mockedAxios.get.mockResolvedValue(mockResponse);
|
|
75
|
-
|
|
76
|
-
const txType = TransactionType.BRIDGE;
|
|
77
|
-
const fromAddress = '0x1234567890';
|
|
78
|
-
const client = new CheckoutApi({ env: Environment.SANDBOX });
|
|
79
|
-
const precache = await client.getTransactions({ fromAddress, txType });
|
|
80
|
-
const cached = await client.getTransactions({ fromAddress, txType });
|
|
81
|
-
|
|
82
|
-
expect(cached).toEqual(precache);
|
|
83
|
-
|
|
84
|
-
expect(mockedAxios.get).toHaveBeenNthCalledWith(
|
|
85
|
-
1,
|
|
86
|
-
`${client.url}/v1/transactions?from_address=${fromAddress}&tx_type=${txType}`,
|
|
87
|
-
);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('success zero TTL', async () => {
|
|
91
|
-
const mockResponse = {
|
|
92
|
-
status: 200,
|
|
93
|
-
data:
|
|
94
|
-
{
|
|
95
|
-
result: [],
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
mockedAxios.get.mockResolvedValue(mockResponse);
|
|
99
|
-
|
|
100
|
-
const txType = TransactionType.BRIDGE;
|
|
101
|
-
const fromAddress = '0x1234567890';
|
|
102
|
-
const client = new CheckoutApi({ env: Environment.SANDBOX, ttl: 0 });
|
|
103
|
-
const precache = await client.getTransactions({ fromAddress, txType });
|
|
104
|
-
const cached = await client.getTransactions({ fromAddress, txType });
|
|
105
|
-
|
|
106
|
-
expect(cached).toEqual(precache);
|
|
107
|
-
|
|
108
|
-
expect(mockedAxios.get).toHaveBeenNthCalledWith(
|
|
109
|
-
2,
|
|
110
|
-
`${client.url}/v1/transactions?from_address=${fromAddress}&tx_type=${txType}`,
|
|
111
|
-
);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('fails 400', async () => {
|
|
115
|
-
const mockResponse = {
|
|
116
|
-
status: HttpStatusCode.BadRequest,
|
|
117
|
-
statusText: 'error',
|
|
118
|
-
data: {},
|
|
119
|
-
};
|
|
120
|
-
mockedAxios.get.mockResolvedValueOnce(mockResponse);
|
|
121
|
-
|
|
122
|
-
const txType = TransactionType.BRIDGE;
|
|
123
|
-
const fromAddress = '0x1234567890';
|
|
124
|
-
const client = new CheckoutApi({ env: Environment.SANDBOX });
|
|
125
|
-
try {
|
|
126
|
-
await client.getTransactions({ fromAddress, txType });
|
|
127
|
-
} catch (error: any) {
|
|
128
|
-
expect(CheckoutApi.isHttpError(error)).toBe(true);
|
|
129
|
-
expect((error as AxiosError).code).toEqual(HttpStatusCode.BadRequest);
|
|
130
|
-
expect((error as AxiosError).message).toEqual('error');
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('fails 500', async () => {
|
|
135
|
-
const mockResponse = {
|
|
136
|
-
status: HttpStatusCode.InternalServerError,
|
|
137
|
-
statusText: 'error',
|
|
138
|
-
data: {},
|
|
139
|
-
};
|
|
140
|
-
mockedAxios.get.mockResolvedValueOnce(mockResponse);
|
|
141
|
-
|
|
142
|
-
const txType = TransactionType.BRIDGE;
|
|
143
|
-
const fromAddress = '0x1234567890';
|
|
144
|
-
const client = new CheckoutApi({ env: Environment.SANDBOX });
|
|
145
|
-
try {
|
|
146
|
-
await client.getTransactions({ fromAddress, txType });
|
|
147
|
-
} catch (error: any) {
|
|
148
|
-
expect(CheckoutApi.isHttpError(error)).toBe(true);
|
|
149
|
-
expect((error as AxiosError).code).toEqual(HttpStatusCode.InternalServerError);
|
|
150
|
-
expect((error as AxiosError).message).toEqual('error');
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('throws', async () => {
|
|
155
|
-
mockedAxios.get.mockRejectedValueOnce('error');
|
|
156
|
-
|
|
157
|
-
const txType = TransactionType.BRIDGE;
|
|
158
|
-
const fromAddress = '0x1234567890';
|
|
159
|
-
const client = new CheckoutApi({ env: Environment.SANDBOX });
|
|
160
|
-
try {
|
|
161
|
-
await client.getTransactions({ fromAddress, txType });
|
|
162
|
-
} catch (error: any) {
|
|
163
|
-
expect(CheckoutApi.isHttpError(error)).toBe(true);
|
|
164
|
-
expect((error as AxiosError).code).toEqual(HttpStatusCode.InternalServerError);
|
|
165
|
-
expect((error as AxiosError).message).toEqual('InternalServerError');
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
});
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import axios, { AxiosError, HttpStatusCode } from 'axios';
|
|
2
|
-
import { Environment } from '@imtbl/config';
|
|
3
|
-
import { IMMUTABLE_API_BASE_URL } from '@imtbl/checkout-sdk';
|
|
4
|
-
import { ENV_DEVELOPMENT } from '../constants';
|
|
5
|
-
import { TransactionType, Transactions } from './checkoutApiType';
|
|
6
|
-
|
|
7
|
-
type CacheData = {
|
|
8
|
-
data: any,
|
|
9
|
-
ttl: number
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
type GetTransactions = {
|
|
13
|
-
txType: TransactionType,
|
|
14
|
-
fromAddress: string,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const CACHE_DATA_TTL = 60; // seconds
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Checkout API class provides a client abstraction for the Checkout API.
|
|
21
|
-
*/
|
|
22
|
-
export class CheckoutApi {
|
|
23
|
-
readonly url: string;
|
|
24
|
-
|
|
25
|
-
readonly ttl: number;
|
|
26
|
-
|
|
27
|
-
readonly env: Environment;
|
|
28
|
-
|
|
29
|
-
private cacheMap: { [key: string]: CacheData };
|
|
30
|
-
|
|
31
|
-
private setCache(key: string, data: any) {
|
|
32
|
-
this.cacheMap[key] = { data, ttl: new Date().getTime() + this.ttl * 1000 };
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
private getCache(key: string): any {
|
|
36
|
-
const d = this.cacheMap[key];
|
|
37
|
-
if (!d || d.ttl <= new Date().getTime()) return null;
|
|
38
|
-
return d.data;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Checkout API constructor
|
|
43
|
-
* @param env target chain
|
|
44
|
-
* @param ttl cache TTL
|
|
45
|
-
*/
|
|
46
|
-
constructor(params: {
|
|
47
|
-
env: Environment | typeof ENV_DEVELOPMENT;
|
|
48
|
-
ttl?: number
|
|
49
|
-
}) {
|
|
50
|
-
this.env = params.env;
|
|
51
|
-
this.url = `${IMMUTABLE_API_BASE_URL[this.env]}/checkout`;
|
|
52
|
-
|
|
53
|
-
this.cacheMap = {};
|
|
54
|
-
this.ttl = params.ttl !== undefined ? params.ttl : CACHE_DATA_TTL;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* isHttpError verifies if the error is a HTTP error
|
|
59
|
-
* @param err error to evaluate
|
|
60
|
-
*/
|
|
61
|
-
public static isHttpError = (err: any): boolean => 'code' in err;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* getTransactions fetches a list of blockchain transactions.
|
|
65
|
-
* @param txType transaction type
|
|
66
|
-
* @param fromAddress transactions executed from address
|
|
67
|
-
*/
|
|
68
|
-
public async getTransactions(params: GetTransactions): Promise<Transactions> {
|
|
69
|
-
const { txType, fromAddress } = params;
|
|
70
|
-
|
|
71
|
-
try {
|
|
72
|
-
const url = `${this.url}/v1/transactions?from_address=${fromAddress}&tx_type=${txType}`;
|
|
73
|
-
|
|
74
|
-
// Cache response data to prevent unnecessary requests
|
|
75
|
-
const cached = this.getCache(url);
|
|
76
|
-
if (cached) return Promise.resolve(cached);
|
|
77
|
-
|
|
78
|
-
const response = await axios.get(url);
|
|
79
|
-
if (response.status >= 400) {
|
|
80
|
-
return Promise.reject({
|
|
81
|
-
code: response.status,
|
|
82
|
-
message: response.statusText,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const { data } = response;
|
|
87
|
-
|
|
88
|
-
this.setCache(url, data);
|
|
89
|
-
return Promise.resolve(data);
|
|
90
|
-
} catch (err: any) {
|
|
91
|
-
let code: number = HttpStatusCode.InternalServerError;
|
|
92
|
-
let message = 'InternalServerError';
|
|
93
|
-
|
|
94
|
-
if (axios.isAxiosError(err)) {
|
|
95
|
-
code = (err as AxiosError).response?.status || code;
|
|
96
|
-
message = (err as AxiosError).message;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return Promise.reject({ code, message });
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|