Skip to content

Commit a5dbaa0

Browse files
chore(payment-processor): load hinkal lib asyncronously (#1573)
1 parent bae9bfd commit a5dbaa0

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

packages/payment-processor/src/payment/erc-20-private-payment-hinkal.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import { Contract, ContractTransaction, Signer, BigNumberish, providers, BigNumber } from 'ethers';
1+
import { BigNumber, BigNumberish, Contract, ContractTransaction, providers, Signer } from 'ethers';
22
import { erc20FeeProxyArtifact } from '@requestnetwork/smart-contracts';
33
import {
4+
ERC20__factory,
45
ERC20FeeProxy__factory,
56
ERC20Proxy__factory,
6-
ERC20__factory,
77
} from '@requestnetwork/smart-contracts/types';
88
import { ClientTypes, ExtensionTypes } from '@requestnetwork/types';
99
import { Erc20PaymentNetwork, getPaymentNetworkExtension } from '@requestnetwork/payment-detection';
1010
import { EvmChains } from '@requestnetwork/currency';
1111
import {
1212
getAmountToPay,
1313
getProvider,
14+
getProxyAddress,
1415
getRequestPaymentValues,
1516
getSigner,
16-
validateRequest,
1717
validateErc20FeeProxyRequest,
18-
getProxyAddress,
18+
validateRequest,
1919
} from './utils';
2020
import { IPreparedPrivateTransaction } from './prepared-transaction';
2121

22-
import { emporiumOp, IHinkal, RelayerTransaction } from '@hinkal/common';
22+
import type { IHinkal, RelayerTransaction } from '@hinkal/common';
2323
import { prepareEthersHinkal } from '@hinkal/common/providers/prepareEthersHinkal';
2424

2525
/**
@@ -85,10 +85,8 @@ export async function payErc20ProxyRequestFromHinkalShieldedAddress(
8585
const signer = getSigner(signerOrProvider);
8686
const hinkalObject = await addToHinkalStore(signer);
8787

88-
const { amountToPay, tokenAddress, ops } = prepareErc20ProxyPaymentFromHinkalShieldedAddress(
89-
request,
90-
amount,
91-
);
88+
const { amountToPay, tokenAddress, ops } =
89+
await prepareErc20ProxyPaymentFromHinkalShieldedAddress(request, amount);
9290

9391
return hinkalObject.actionPrivateWallet(
9492
[tokenAddress],
@@ -114,11 +112,8 @@ export async function payErc20FeeProxyRequestFromHinkalShieldedAddress(
114112
const signer = getSigner(signerOrProvider);
115113
const hinkalObject = await addToHinkalStore(signer);
116114

117-
const { amountToPay, tokenAddress, ops } = prepareErc20FeeProxyPaymentFromHinkalShieldedAddress(
118-
request,
119-
amount,
120-
feeAmount,
121-
);
115+
const { amountToPay, tokenAddress, ops } =
116+
await prepareErc20FeeProxyPaymentFromHinkalShieldedAddress(request, amount, feeAmount);
122117

123118
return hinkalObject.actionPrivateWallet(
124119
[tokenAddress],
@@ -133,10 +128,10 @@ export async function payErc20FeeProxyRequestFromHinkalShieldedAddress(
133128
* @param request request to pay
134129
* @param amount optionally, the amount to pay. Defaults to remaining amount of the request.
135130
*/
136-
export function prepareErc20ProxyPaymentFromHinkalShieldedAddress(
131+
export async function prepareErc20ProxyPaymentFromHinkalShieldedAddress(
137132
request: ClientTypes.IRequestData,
138133
amount?: BigNumberish,
139-
): IPreparedPrivateTransaction {
134+
): Promise<IPreparedPrivateTransaction> {
140135
validateRequest(request, ExtensionTypes.PAYMENT_NETWORK_ID.ERC20_PROXY_CONTRACT);
141136

142137
const { value: tokenAddress } = request.currencyInfo;
@@ -150,6 +145,7 @@ export function prepareErc20ProxyPaymentFromHinkalShieldedAddress(
150145

151146
const { paymentReference, paymentAddress } = getRequestPaymentValues(request);
152147
const amountToPay = getAmountToPay(request, amount);
148+
const { emporiumOp } = await import('@hinkal/common');
153149

154150
const ops = [
155151
emporiumOp(tokenContract, 'approve', [proxyContract.address, amountToPay]),
@@ -174,11 +170,11 @@ export function prepareErc20ProxyPaymentFromHinkalShieldedAddress(
174170
* @param amount optionally, the amount to pay. Defaults to remaining amount of the request.
175171
* @param feeAmountOverride optionally, the fee amount to pay. Defaults to the fee amount of the request.
176172
*/
177-
export function prepareErc20FeeProxyPaymentFromHinkalShieldedAddress(
173+
export async function prepareErc20FeeProxyPaymentFromHinkalShieldedAddress(
178174
request: ClientTypes.IRequestData,
179175
amount?: BigNumberish,
180176
feeAmountOverride?: BigNumberish,
181-
): IPreparedPrivateTransaction {
177+
): Promise<IPreparedPrivateTransaction> {
182178
validateErc20FeeProxyRequest(request, amount, feeAmountOverride);
183179

184180
const { value: tokenAddress, network } = request.currencyInfo;
@@ -194,6 +190,7 @@ export function prepareErc20FeeProxyPaymentFromHinkalShieldedAddress(
194190
const amountToPay = getAmountToPay(request, amount);
195191
const feeToPay = String(feeAmountOverride || feeAmount || 0);
196192
const totalAmount = amountToPay.add(BigNumber.from(feeToPay));
193+
const { emporiumOp } = await import('@hinkal/common');
197194

198195
const ops = [
199196
emporiumOp(tokenContract, 'approve', [proxyContract.address, totalAmount]),

0 commit comments

Comments
 (0)