coinley-checkout 0.4.4 → 0.4.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.
@@ -2236,7 +2236,7 @@ const names = [
|
|
2236
2236
|
"finney",
|
2237
2237
|
"ether"
|
2238
2238
|
];
|
2239
|
-
function parseUnits$
|
2239
|
+
function parseUnits$2(value, unit) {
|
2240
2240
|
assertArgument(typeof value === "string", "value must be a string", "value", value);
|
2241
2241
|
let decimals = 18;
|
2242
2242
|
if (typeof unit === "string") {
|
@@ -2248,8 +2248,8 @@ function parseUnits$1(value, unit) {
|
|
2248
2248
|
}
|
2249
2249
|
return FixedNumber.fromString(value, { decimals, width: 512 }).value;
|
2250
2250
|
}
|
2251
|
-
function parseEther(ether) {
|
2252
|
-
return parseUnits$
|
2251
|
+
function parseEther$1(ether) {
|
2252
|
+
return parseUnits$2(ether, 18);
|
2253
2253
|
}
|
2254
2254
|
const WordSize = 32;
|
2255
2255
|
const Padding = new Uint8Array(WordSize);
|
@@ -15107,7 +15107,7 @@ _name = new WeakMap();
|
|
15107
15107
|
_chainId2 = new WeakMap();
|
15108
15108
|
_plugins = new WeakMap();
|
15109
15109
|
let Network = _Network;
|
15110
|
-
function parseUnits(_value2, decimals) {
|
15110
|
+
function parseUnits$1(_value2, decimals) {
|
15111
15111
|
const value = String(_value2);
|
15112
15112
|
if (!value.match(/^[0-9.]+$/)) {
|
15113
15113
|
throw new Error(`invalid gwei value: ${_value2}`);
|
@@ -15144,8 +15144,8 @@ function getGasStationPlugin(url) {
|
|
15144
15144
|
const payload = response.bodyJson.standard;
|
15145
15145
|
const feeData = {
|
15146
15146
|
gasPrice: _feeData.gasPrice,
|
15147
|
-
maxFeePerGas: parseUnits(payload.maxFee, 9),
|
15148
|
-
maxPriorityFeePerGas: parseUnits(payload.maxPriorityFee, 9)
|
15147
|
+
maxFeePerGas: parseUnits$1(payload.maxFee, 9),
|
15148
|
+
maxPriorityFeePerGas: parseUnits$1(payload.maxPriorityFee, 9)
|
15149
15149
|
};
|
15150
15150
|
return feeData;
|
15151
15151
|
} catch (error) {
|
@@ -18385,7 +18385,6 @@ const TOKEN_CONFIG = {
|
|
18385
18385
|
ethereum: {
|
18386
18386
|
contractAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
18387
18387
|
decimals: 6,
|
18388
|
-
// USDC has 6 decimals on Ethereum!
|
18389
18388
|
symbol: "USDC"
|
18390
18389
|
},
|
18391
18390
|
bsc: {
|
@@ -18406,7 +18405,6 @@ const TOKEN_CONFIG = {
|
|
18406
18405
|
},
|
18407
18406
|
BNB: {
|
18408
18407
|
bsc: {
|
18409
|
-
// BNB is native to BSC
|
18410
18408
|
decimals: 18,
|
18411
18409
|
symbol: "BNB",
|
18412
18410
|
isNative: true
|
@@ -18414,7 +18412,6 @@ const TOKEN_CONFIG = {
|
|
18414
18412
|
},
|
18415
18413
|
ETH: {
|
18416
18414
|
ethereum: {
|
18417
|
-
// ETH is native to Ethereum
|
18418
18415
|
decimals: 18,
|
18419
18416
|
symbol: "ETH",
|
18420
18417
|
isNative: true
|
@@ -18422,7 +18419,6 @@ const TOKEN_CONFIG = {
|
|
18422
18419
|
},
|
18423
18420
|
TRX: {
|
18424
18421
|
tron: {
|
18425
|
-
// TRX is native to TRON
|
18426
18422
|
decimals: 6,
|
18427
18423
|
symbol: "TRX",
|
18428
18424
|
isNative: true
|
@@ -18430,7 +18426,6 @@ const TOKEN_CONFIG = {
|
|
18430
18426
|
},
|
18431
18427
|
ALGO: {
|
18432
18428
|
algorand: {
|
18433
|
-
// ALGO is native to Algorand
|
18434
18429
|
decimals: 6,
|
18435
18430
|
symbol: "ALGO",
|
18436
18431
|
isNative: true
|
@@ -18496,6 +18491,42 @@ const debugWalletEnvironment = () => {
|
|
18496
18491
|
const wallets = detectWallets();
|
18497
18492
|
console.log("Detected wallets:", wallets);
|
18498
18493
|
};
|
18494
|
+
const parseEther = (value) => {
|
18495
|
+
try {
|
18496
|
+
if (parseEther$1) {
|
18497
|
+
return parseEther$1(value);
|
18498
|
+
}
|
18499
|
+
if (void 0)
|
18500
|
+
;
|
18501
|
+
const amount = parseFloat(value) * Math.pow(10, 18);
|
18502
|
+
return {
|
18503
|
+
toString: () => amount.toLocaleString("fullwide", { useGrouping: false })
|
18504
|
+
};
|
18505
|
+
} catch (error) {
|
18506
|
+
const amount = parseFloat(value) * Math.pow(10, 18);
|
18507
|
+
return {
|
18508
|
+
toString: () => amount.toLocaleString("fullwide", { useGrouping: false })
|
18509
|
+
};
|
18510
|
+
}
|
18511
|
+
};
|
18512
|
+
const parseUnits = (value, decimals) => {
|
18513
|
+
try {
|
18514
|
+
if (parseUnits$2) {
|
18515
|
+
return parseUnits$2(value, decimals);
|
18516
|
+
}
|
18517
|
+
if (void 0)
|
18518
|
+
;
|
18519
|
+
const amount = parseFloat(value) * Math.pow(10, decimals);
|
18520
|
+
return {
|
18521
|
+
toString: () => amount.toLocaleString("fullwide", { useGrouping: false })
|
18522
|
+
};
|
18523
|
+
} catch (error) {
|
18524
|
+
const amount = parseFloat(value) * Math.pow(10, decimals);
|
18525
|
+
return {
|
18526
|
+
toString: () => amount.toLocaleString("fullwide", { useGrouping: false })
|
18527
|
+
};
|
18528
|
+
}
|
18529
|
+
};
|
18499
18530
|
const connectMetamaskWallet = () => __async(void 0, null, function* () {
|
18500
18531
|
console.log("Connecting to MetaMask wallet...");
|
18501
18532
|
if (!window.ethereum || !window.ethereum.isMetaMask) {
|
@@ -18789,19 +18820,7 @@ const sendNativeTransaction = (walletConnection, toAddress, amount) => __async(v
|
|
18789
18820
|
const provider = walletConnection.provider;
|
18790
18821
|
const signer = provider.getSigner();
|
18791
18822
|
const amountInEther = amount.toString();
|
18792
|
-
|
18793
|
-
try {
|
18794
|
-
amountWei = parseEther(amountInEther);
|
18795
|
-
} catch (err) {
|
18796
|
-
try {
|
18797
|
-
amountWei = (void 0).parseEther(amountInEther);
|
18798
|
-
} catch (error) {
|
18799
|
-
const value = parseFloat(amountInEther) * Math.pow(10, 18);
|
18800
|
-
amountWei = {
|
18801
|
-
toString: () => value.toLocaleString("fullwide", { useGrouping: false })
|
18802
|
-
};
|
18803
|
-
}
|
18804
|
-
}
|
18823
|
+
const amountWei = parseEther(amountInEther);
|
18805
18824
|
console.log("Sending ETH/BNB:", {
|
18806
18825
|
to: toAddress,
|
18807
18826
|
value: amountWei.toString()
|
@@ -18852,32 +18871,14 @@ const sendNativeTransaction = (walletConnection, toAddress, amount) => __async(v
|
|
18852
18871
|
throw new Error(`Unsupported wallet type: ${walletConnection.walletType}`);
|
18853
18872
|
}
|
18854
18873
|
console.log("Transaction sent:", transaction);
|
18855
|
-
|
18856
|
-
|
18857
|
-
|
18858
|
-
return hash2;
|
18859
|
-
} else {
|
18860
|
-
throw new Error("No transaction hash returned");
|
18861
|
-
}
|
18874
|
+
const hash2 = transaction.hash || transaction.txID || transaction.txId || transaction;
|
18875
|
+
console.log("Transaction hash:", hash2);
|
18876
|
+
return hash2;
|
18862
18877
|
} catch (error) {
|
18863
18878
|
console.error("Native transaction error:", error);
|
18864
18879
|
throw error;
|
18865
18880
|
}
|
18866
18881
|
});
|
18867
|
-
const sendTransaction = (walletConnection, tokenConfig, toAddress, amount) => __async(void 0, null, function* () {
|
18868
|
-
console.log("Sending transaction with:", { tokenConfig, toAddress, amount });
|
18869
|
-
if (!walletConnection) {
|
18870
|
-
throw new Error("Wallet not connected");
|
18871
|
-
}
|
18872
|
-
if (!toAddress) {
|
18873
|
-
throw new Error("Recipient address not provided");
|
18874
|
-
}
|
18875
|
-
if (tokenConfig && tokenConfig.isNative) {
|
18876
|
-
return sendNativeTransaction(walletConnection, toAddress, amount);
|
18877
|
-
} else {
|
18878
|
-
return sendTokenTransaction(walletConnection, tokenConfig, toAddress, amount);
|
18879
|
-
}
|
18880
|
-
});
|
18881
18882
|
const sendTokenTransaction = (walletConnection, tokenConfig, toAddress, amount) => __async(void 0, null, function* () {
|
18882
18883
|
console.log("Sending token transaction with:", { tokenConfig, toAddress, amount });
|
18883
18884
|
if (!walletConnection || !walletConnection.provider) {
|
@@ -18913,19 +18914,7 @@ const sendERC20Transaction = (walletConnection, tokenConfig, toAddress, amount)
|
|
18913
18914
|
const { contractAddress, decimals, symbol } = tokenConfig;
|
18914
18915
|
const tokenAmount = parseFloat(amount);
|
18915
18916
|
const tokenDecimals = parseInt(decimals);
|
18916
|
-
|
18917
|
-
try {
|
18918
|
-
tokenUnits = parseUnits$1(tokenAmount.toString(), tokenDecimals);
|
18919
|
-
} catch (err) {
|
18920
|
-
try {
|
18921
|
-
tokenUnits = (void 0).parseUnits(tokenAmount.toString(), tokenDecimals);
|
18922
|
-
} catch (error) {
|
18923
|
-
const value = tokenAmount * Math.pow(10, tokenDecimals);
|
18924
|
-
tokenUnits = {
|
18925
|
-
toString: () => value.toLocaleString("fullwide", { useGrouping: false })
|
18926
|
-
};
|
18927
|
-
}
|
18928
|
-
}
|
18917
|
+
const tokenUnits = parseUnits(tokenAmount.toString(), tokenDecimals);
|
18929
18918
|
console.log(`Sending ${tokenAmount} ${symbol} (${tokenUnits.toString()} base units) to ${toAddress}`);
|
18930
18919
|
try {
|
18931
18920
|
const tokenContract = new Contract(
|
@@ -18949,7 +18938,6 @@ const sendERC20Transaction = (walletConnection, tokenConfig, toAddress, amount)
|
|
18949
18938
|
console.log("Trying USDC transaction with fixed gas limit");
|
18950
18939
|
const transaction = yield tokenContract.transfer(toAddress, tokenUnits, {
|
18951
18940
|
gasLimit: 15e4
|
18952
|
-
// Higher fixed gas limit for USDC
|
18953
18941
|
});
|
18954
18942
|
console.log("Transaction sent with fixed gas limit:", transaction);
|
18955
18943
|
return transaction.hash;
|
@@ -18993,13 +18981,10 @@ const sendTRC20Transaction = (walletConnection, tokenConfig, toAddress, amount)
|
|
18993
18981
|
const transaction = yield contract.transfer(
|
18994
18982
|
toAddress,
|
18995
18983
|
amountString
|
18996
|
-
// Use the raw amount string
|
18997
18984
|
).send({
|
18998
18985
|
feeLimit: 1e8,
|
18999
|
-
// 100 TRX fee limit
|
19000
18986
|
callValue: 0,
|
19001
18987
|
shouldPollResponse: false
|
19002
|
-
// Set to false for better handling
|
19003
18988
|
});
|
19004
18989
|
console.log("TRC20 transaction sent:", transaction);
|
19005
18990
|
return transaction;
|
@@ -19049,12 +19034,38 @@ const sendAlgorandAssetTransaction = (walletConnection, tokenConfig, toAddress,
|
|
19049
19034
|
}
|
19050
19035
|
}
|
19051
19036
|
});
|
19037
|
+
const sendTransaction = (walletConnection, transactionParams) => __async(void 0, null, function* () {
|
19038
|
+
console.log("sendTransaction called with:", transactionParams);
|
19039
|
+
if (!walletConnection) {
|
19040
|
+
throw new Error("Wallet not connected");
|
19041
|
+
}
|
19042
|
+
const { to, toAddress, amount, tokenAddress, tokenConfig, currency, network } = transactionParams;
|
19043
|
+
const recipientAddress = to || toAddress;
|
19044
|
+
if (!recipientAddress) {
|
19045
|
+
throw new Error("Recipient address not provided");
|
19046
|
+
}
|
19047
|
+
if (!tokenAddress && !tokenConfig) {
|
19048
|
+
return sendNativeTransaction(walletConnection, recipientAddress, amount);
|
19049
|
+
}
|
19050
|
+
let tokenConfiguration = tokenConfig;
|
19051
|
+
if (!tokenConfiguration && tokenAddress) {
|
19052
|
+
tokenConfiguration = {
|
19053
|
+
contractAddress: tokenAddress,
|
19054
|
+
decimals: 18,
|
19055
|
+
symbol: currency || "TOKEN"
|
19056
|
+
};
|
19057
|
+
}
|
19058
|
+
if (!tokenConfiguration) {
|
19059
|
+
throw new Error("Token configuration not provided");
|
19060
|
+
}
|
19061
|
+
return sendTokenTransaction(walletConnection, tokenConfiguration, recipientAddress, amount);
|
19062
|
+
});
|
19052
19063
|
let apiConfig = {
|
19053
19064
|
apiKey: null,
|
19054
19065
|
apiSecret: null,
|
19055
19066
|
apiUrl: "https://coinleyserver-production.up.railway.app",
|
19056
19067
|
merchantWalletAddresses: {}
|
19057
|
-
//
|
19068
|
+
// This will be populated dynamically
|
19058
19069
|
};
|
19059
19070
|
const initializeApi = (config) => {
|
19060
19071
|
apiConfig = __spreadValues(__spreadValues({}, apiConfig), config);
|
@@ -19064,6 +19075,10 @@ const initializeApi = (config) => {
|
|
19064
19075
|
hasWalletAddresses: Object.keys(apiConfig.merchantWalletAddresses || {}).length > 0
|
19065
19076
|
});
|
19066
19077
|
};
|
19078
|
+
const setMerchantWalletAddresses = (walletAddresses) => {
|
19079
|
+
apiConfig.merchantWalletAddresses = __spreadValues({}, walletAddresses);
|
19080
|
+
console.log("Updated merchant wallet addresses:", apiConfig.merchantWalletAddresses);
|
19081
|
+
};
|
19067
19082
|
const getHeaders = () => {
|
19068
19083
|
return {
|
19069
19084
|
"Content-Type": "application/json",
|
@@ -19072,6 +19087,7 @@ const getHeaders = () => {
|
|
19072
19087
|
};
|
19073
19088
|
};
|
19074
19089
|
const createPayment = (paymentData) => __async(void 0, null, function* () {
|
19090
|
+
var _a2;
|
19075
19091
|
try {
|
19076
19092
|
console.log("Creating payment with data:", paymentData);
|
19077
19093
|
console.log("API URL:", `${apiConfig.apiUrl}/api/payments/create`);
|
@@ -19079,7 +19095,24 @@ const createPayment = (paymentData) => __async(void 0, null, function* () {
|
|
19079
19095
|
throw new Error("Payment amount is required");
|
19080
19096
|
}
|
19081
19097
|
const enhancedPaymentData = __spreadProps(__spreadValues({}, paymentData), {
|
19082
|
-
|
19098
|
+
// Primary recipient address (highest priority)
|
19099
|
+
recipientAddress: paymentData.recipientAddress || paymentData.toAddress || paymentData.walletAddress,
|
19100
|
+
// Merchant wallet addresses (for network switching)
|
19101
|
+
merchantWalletAddresses: __spreadValues(__spreadValues({}, apiConfig.merchantWalletAddresses), paymentData.merchantWalletAddresses),
|
19102
|
+
// Legacy support
|
19103
|
+
walletAddress: paymentData.walletAddress || paymentData.recipientAddress || paymentData.toAddress,
|
19104
|
+
// Alternative naming
|
19105
|
+
toAddress: paymentData.toAddress || paymentData.recipientAddress || paymentData.walletAddress
|
19106
|
+
});
|
19107
|
+
const network = enhancedPaymentData.network || "ethereum";
|
19108
|
+
const recipientAddress = enhancedPaymentData.recipientAddress || ((_a2 = enhancedPaymentData.merchantWalletAddresses) == null ? void 0 : _a2[network]);
|
19109
|
+
if (!recipientAddress) {
|
19110
|
+
throw new Error(`No recipient address provided for network: ${network}. Please configure a wallet address.`);
|
19111
|
+
}
|
19112
|
+
console.log("Enhanced payment data:", {
|
19113
|
+
network,
|
19114
|
+
recipientAddress,
|
19115
|
+
merchantWalletAddresses: enhancedPaymentData.merchantWalletAddresses
|
19083
19116
|
});
|
19084
19117
|
const response = yield fetch(`${apiConfig.apiUrl}/api/payments/create`, {
|
19085
19118
|
method: "POST",
|
@@ -19099,6 +19132,9 @@ const createPayment = (paymentData) => __async(void 0, null, function* () {
|
|
19099
19132
|
}
|
19100
19133
|
const data = yield response.json();
|
19101
19134
|
console.log("Create payment response data:", data);
|
19135
|
+
if (data.merchantConfig && data.merchantConfig.walletAddresses) {
|
19136
|
+
setMerchantWalletAddresses(data.merchantConfig.walletAddresses);
|
19137
|
+
}
|
19102
19138
|
return data;
|
19103
19139
|
} catch (error) {
|
19104
19140
|
console.error("Create payment error:", error);
|
@@ -19142,11 +19178,17 @@ const processPayment = (processData) => __async(void 0, null, function* () {
|
|
19142
19178
|
if (!processData.transactionHash) {
|
19143
19179
|
throw new Error("Transaction hash is required");
|
19144
19180
|
}
|
19181
|
+
const enhancedProcessData = __spreadProps(__spreadValues({}, processData), {
|
19182
|
+
// Include timestamp
|
19183
|
+
processedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
19184
|
+
// Include source information
|
19185
|
+
source: "coinley_checkout"
|
19186
|
+
});
|
19145
19187
|
console.log("API URL:", `${apiConfig.apiUrl}/api/payments/process`);
|
19146
19188
|
const response = yield fetch(`${apiConfig.apiUrl}/api/payments/process`, {
|
19147
19189
|
method: "POST",
|
19148
19190
|
headers: getHeaders(),
|
19149
|
-
body: JSON.stringify(
|
19191
|
+
body: JSON.stringify(enhancedProcessData)
|
19150
19192
|
});
|
19151
19193
|
console.log("Process payment response status:", response.status);
|
19152
19194
|
if (!response.ok) {
|
@@ -19167,31 +19209,37 @@ const processPayment = (processData) => __async(void 0, null, function* () {
|
|
19167
19209
|
throw error;
|
19168
19210
|
}
|
19169
19211
|
});
|
19170
|
-
const
|
19212
|
+
const getMerchantWallets = (merchantToken) => __async(void 0, null, function* () {
|
19171
19213
|
try {
|
19172
|
-
const response = yield fetch(`${apiConfig.apiUrl}/api/
|
19214
|
+
const response = yield fetch(`${apiConfig.apiUrl}/api/merchants/wallets`, {
|
19173
19215
|
method: "GET",
|
19174
|
-
headers:
|
19216
|
+
headers: {
|
19217
|
+
"Content-Type": "application/json",
|
19218
|
+
"Authorization": `Bearer ${merchantToken}`
|
19219
|
+
}
|
19175
19220
|
});
|
19176
19221
|
if (!response.ok) {
|
19177
19222
|
let errorData;
|
19178
19223
|
try {
|
19179
19224
|
errorData = yield response.json();
|
19180
19225
|
} catch (e) {
|
19181
|
-
throw new Error(`Failed to get
|
19226
|
+
throw new Error(`Failed to get merchant wallets: ${response.status} ${response.statusText}`);
|
19182
19227
|
}
|
19183
|
-
throw new Error(errorData.error || `Failed to get
|
19228
|
+
throw new Error(errorData.error || `Failed to get merchant wallets: ${response.status}`);
|
19184
19229
|
}
|
19185
19230
|
const data = yield response.json();
|
19231
|
+
if (data.merchantWallets) {
|
19232
|
+
setMerchantWalletAddresses(data.merchantWallets);
|
19233
|
+
}
|
19186
19234
|
return data;
|
19187
19235
|
} catch (error) {
|
19188
|
-
console.error("Get
|
19236
|
+
console.error("Get merchant wallets error:", error);
|
19189
19237
|
throw error;
|
19190
19238
|
}
|
19191
19239
|
});
|
19192
|
-
const
|
19240
|
+
const getSupportedNetworks = () => __async(void 0, null, function* () {
|
19193
19241
|
try {
|
19194
|
-
const response = yield fetch(`${apiConfig.apiUrl}/api/
|
19242
|
+
const response = yield fetch(`${apiConfig.apiUrl}/api/networks`, {
|
19195
19243
|
method: "GET",
|
19196
19244
|
headers: getHeaders()
|
19197
19245
|
});
|
@@ -19200,53 +19248,75 @@ const getMerchantProfile = () => __async(void 0, null, function* () {
|
|
19200
19248
|
try {
|
19201
19249
|
errorData = yield response.json();
|
19202
19250
|
} catch (e) {
|
19203
|
-
throw new Error(`Failed to get
|
19251
|
+
throw new Error(`Failed to get networks: ${response.status} ${response.statusText}`);
|
19204
19252
|
}
|
19205
|
-
throw new Error(errorData.error || `Failed to get
|
19253
|
+
throw new Error(errorData.error || `Failed to get networks: ${response.status}`);
|
19206
19254
|
}
|
19207
19255
|
const data = yield response.json();
|
19208
|
-
if (data.merchant && data.merchant.walletAddresses) {
|
19209
|
-
apiConfig.merchantWalletAddresses = __spreadValues(__spreadValues({}, apiConfig.merchantWalletAddresses), data.merchant.walletAddresses);
|
19210
|
-
}
|
19211
19256
|
return data;
|
19212
19257
|
} catch (error) {
|
19213
|
-
console.error("Get
|
19258
|
+
console.error("Get supported networks error:", error);
|
19214
19259
|
throw error;
|
19215
19260
|
}
|
19216
19261
|
});
|
19217
|
-
const validateWalletAddress = (address, network) =>
|
19262
|
+
const validateWalletAddress = (address, network) => {
|
19263
|
+
if (!address || typeof address !== "string")
|
19264
|
+
return false;
|
19265
|
+
switch (network.toLowerCase()) {
|
19266
|
+
case "ethereum":
|
19267
|
+
case "bsc":
|
19268
|
+
return /^0x[a-fA-F0-9]{40}$/.test(address);
|
19269
|
+
case "tron":
|
19270
|
+
return /^T[a-zA-Z0-9]{33}$/.test(address);
|
19271
|
+
case "algorand":
|
19272
|
+
return /^[A-Z2-7]{58}$/.test(address);
|
19273
|
+
case "solana":
|
19274
|
+
return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(address);
|
19275
|
+
default:
|
19276
|
+
return address.length > 10;
|
19277
|
+
}
|
19278
|
+
};
|
19279
|
+
const generateMockTransactionHash = (network = "ethereum") => {
|
19280
|
+
const prefixes = {
|
19281
|
+
ethereum: "0x",
|
19282
|
+
bsc: "0x",
|
19283
|
+
tron: "",
|
19284
|
+
algorand: ""
|
19285
|
+
};
|
19286
|
+
const prefix = prefixes[network] || "0x";
|
19287
|
+
const hash2 = Array.from({ length: 64 }, () => Math.floor(Math.random() * 16).toString(16)).join("");
|
19288
|
+
return `${prefix}${hash2}`;
|
19289
|
+
};
|
19290
|
+
const getMerchantProfile = () => __async(void 0, null, function* () {
|
19218
19291
|
try {
|
19219
|
-
const response = yield fetch(`${apiConfig.apiUrl}/api/
|
19220
|
-
method: "
|
19221
|
-
headers: getHeaders()
|
19222
|
-
body: JSON.stringify({ address, network })
|
19292
|
+
const response = yield fetch(`${apiConfig.apiUrl}/api/merchants/profile`, {
|
19293
|
+
method: "GET",
|
19294
|
+
headers: getHeaders()
|
19223
19295
|
});
|
19224
19296
|
if (!response.ok) {
|
19225
19297
|
let errorData;
|
19226
19298
|
try {
|
19227
19299
|
errorData = yield response.json();
|
19228
19300
|
} catch (e) {
|
19229
|
-
throw new Error(`Failed to
|
19301
|
+
throw new Error(`Failed to get merchant profile: ${response.status} ${response.statusText}`);
|
19230
19302
|
}
|
19231
|
-
throw new Error(errorData.error || `Failed to
|
19303
|
+
throw new Error(errorData.error || `Failed to get merchant profile: ${response.status}`);
|
19232
19304
|
}
|
19233
19305
|
const data = yield response.json();
|
19306
|
+
if (data.merchant && data.merchant.walletAddresses) {
|
19307
|
+
apiConfig.merchantWalletAddresses = __spreadValues(__spreadValues({}, apiConfig.merchantWalletAddresses), data.merchant.walletAddresses);
|
19308
|
+
}
|
19234
19309
|
return data;
|
19235
19310
|
} catch (error) {
|
19236
|
-
console.error("
|
19311
|
+
console.error("Get merchant profile error:", error);
|
19237
19312
|
throw error;
|
19238
19313
|
}
|
19239
19314
|
});
|
19240
|
-
const
|
19241
|
-
|
19242
|
-
|
19243
|
-
|
19244
|
-
|
19245
|
-
algorand: ""
|
19246
|
-
};
|
19247
|
-
const prefix = prefixes[network] || "0x";
|
19248
|
-
const hash2 = Array.from({ length: 64 }, () => Math.floor(Math.random() * 16).toString(16)).join("");
|
19249
|
-
return `${prefix}${hash2}`;
|
19315
|
+
const fetchMerchantWalletAddresses = (merchantToken) => __async(void 0, null, function* () {
|
19316
|
+
return getMerchantWallets(merchantToken);
|
19317
|
+
});
|
19318
|
+
const getApiConfig = () => {
|
19319
|
+
return __spreadValues({}, apiConfig);
|
19250
19320
|
};
|
19251
19321
|
var jsxRuntime = { exports: {} };
|
19252
19322
|
var reactJsxRuntime_production_min = {};
|
@@ -21394,7 +21464,6 @@ const CoinleyCheckout = forwardRef(({
|
|
21394
21464
|
customerEmail,
|
21395
21465
|
merchantName = "Merchant",
|
21396
21466
|
merchantWalletAddresses = {},
|
21397
|
-
// Object with network-specific addresses
|
21398
21467
|
onSuccess,
|
21399
21468
|
onError,
|
21400
21469
|
onClose,
|
@@ -21403,7 +21472,6 @@ const CoinleyCheckout = forwardRef(({
|
|
21403
21472
|
debug = false,
|
21404
21473
|
testMode = false,
|
21405
21474
|
supportedNetworks = [],
|
21406
|
-
// Array of supported networks
|
21407
21475
|
preferredNetwork = NETWORK_TYPES.ETHEREUM,
|
21408
21476
|
preferredWallet = WALLET_TYPES.METAMASK
|
21409
21477
|
}, ref) => {
|
@@ -21418,8 +21486,10 @@ const CoinleyCheckout = forwardRef(({
|
|
21418
21486
|
const [walletConnection, setWalletConnection] = useState(null);
|
21419
21487
|
const [availableWallets, setAvailableWallets] = useState({});
|
21420
21488
|
const [step, setStep] = useState("select-currency");
|
21421
|
-
|
21422
|
-
|
21489
|
+
const [merchantWallets, setMerchantWallets] = useState({});
|
21490
|
+
const [isLoadingWallets, setIsLoadingWallets] = useState(false);
|
21491
|
+
const effectiveApiKey = apiKey || (coinleyContext == null ? void 0 : coinleyContext.apiKey);
|
21492
|
+
const effectiveApiSecret = apiSecret || (coinleyContext == null ? void 0 : coinleyContext.apiSecret);
|
21423
21493
|
apiUrl || (coinleyContext == null ? void 0 : coinleyContext.apiUrl);
|
21424
21494
|
const effectiveTheme = theme || contextTheme;
|
21425
21495
|
const effectiveDebug = debug || (coinleyContext == null ? void 0 : coinleyContext.debug);
|
@@ -21433,6 +21503,7 @@ const CoinleyCheckout = forwardRef(({
|
|
21433
21503
|
},
|
21434
21504
|
getPayment: () => payment,
|
21435
21505
|
getWalletConnection: () => walletConnection,
|
21506
|
+
getMerchantWallets: () => merchantWallets,
|
21436
21507
|
debugWallets: () => debugWalletEnvironment()
|
21437
21508
|
}));
|
21438
21509
|
const log = (message, data) => {
|
@@ -21450,6 +21521,44 @@ const CoinleyCheckout = forwardRef(({
|
|
21450
21521
|
detectWalletsAsync();
|
21451
21522
|
}
|
21452
21523
|
}, [effectiveDebug]);
|
21524
|
+
useEffect(() => {
|
21525
|
+
const loadMerchantWallets = () => __async(void 0, null, function* () {
|
21526
|
+
if (!effectiveApiKey || !effectiveApiSecret) {
|
21527
|
+
log("No API credentials available for wallet address fetching");
|
21528
|
+
return;
|
21529
|
+
}
|
21530
|
+
setIsLoadingWallets(true);
|
21531
|
+
try {
|
21532
|
+
const apiConfig2 = getApiConfig();
|
21533
|
+
if (apiConfig2.merchantWalletAddresses && Object.keys(apiConfig2.merchantWalletAddresses).length > 0) {
|
21534
|
+
setMerchantWallets(apiConfig2.merchantWalletAddresses);
|
21535
|
+
log("Loaded wallet addresses from API config:", apiConfig2.merchantWalletAddresses);
|
21536
|
+
} else {
|
21537
|
+
const walletAddresses = yield fetchMerchantWalletAddresses();
|
21538
|
+
if (walletAddresses && Object.keys(walletAddresses).length > 0) {
|
21539
|
+
setMerchantWallets(walletAddresses);
|
21540
|
+
log("Fetched wallet addresses from API:", walletAddresses);
|
21541
|
+
} else {
|
21542
|
+
log("No wallet addresses found in API response");
|
21543
|
+
}
|
21544
|
+
}
|
21545
|
+
if (merchantWalletAddresses && Object.keys(merchantWalletAddresses).length > 0) {
|
21546
|
+
setMerchantWallets((prev) => __spreadValues(__spreadValues({}, prev), merchantWalletAddresses));
|
21547
|
+
log("Added manual wallet addresses:", merchantWalletAddresses);
|
21548
|
+
}
|
21549
|
+
} catch (error2) {
|
21550
|
+
log("Error loading merchant wallet addresses:", error2);
|
21551
|
+
console.warn("Could not load merchant wallet addresses:", error2.message);
|
21552
|
+
if (merchantWalletAddresses && Object.keys(merchantWalletAddresses).length > 0) {
|
21553
|
+
setMerchantWallets(merchantWalletAddresses);
|
21554
|
+
log("Using fallback manual wallet addresses:", merchantWalletAddresses);
|
21555
|
+
}
|
21556
|
+
} finally {
|
21557
|
+
setIsLoadingWallets(false);
|
21558
|
+
}
|
21559
|
+
});
|
21560
|
+
loadMerchantWallets();
|
21561
|
+
}, [effectiveApiKey, effectiveApiSecret, merchantWalletAddresses, effectiveDebug]);
|
21453
21562
|
const handleOpen = (paymentDetails) => __async(void 0, null, function* () {
|
21454
21563
|
if (!paymentDetails || !paymentDetails.amount) {
|
21455
21564
|
setError("Payment amount is required");
|
@@ -21462,20 +21571,51 @@ const CoinleyCheckout = forwardRef(({
|
|
21462
21571
|
setStep("select-currency");
|
21463
21572
|
try {
|
21464
21573
|
log("Creating payment with details:", paymentDetails);
|
21574
|
+
let finalWalletAddresses = __spreadValues({}, merchantWallets);
|
21575
|
+
if (Object.keys(finalWalletAddresses).length === 0) {
|
21576
|
+
log("No wallet addresses available, attempting to fetch...");
|
21577
|
+
try {
|
21578
|
+
const fetchedWallets = yield fetchMerchantWalletAddresses();
|
21579
|
+
if (fetchedWallets) {
|
21580
|
+
finalWalletAddresses = fetchedWallets;
|
21581
|
+
setMerchantWallets(fetchedWallets);
|
21582
|
+
}
|
21583
|
+
} catch (fetchError) {
|
21584
|
+
log("Failed to fetch wallet addresses:", fetchError);
|
21585
|
+
}
|
21586
|
+
}
|
21587
|
+
if (paymentDetails.merchantWalletAddresses) {
|
21588
|
+
finalWalletAddresses = __spreadValues(__spreadValues({}, finalWalletAddresses), paymentDetails.merchantWalletAddresses);
|
21589
|
+
}
|
21590
|
+
if (merchantWalletAddresses) {
|
21591
|
+
finalWalletAddresses = __spreadValues(__spreadValues({}, finalWalletAddresses), merchantWalletAddresses);
|
21592
|
+
}
|
21593
|
+
log("Final wallet addresses for payment:", finalWalletAddresses);
|
21465
21594
|
const paymentResponse = yield createPayment({
|
21466
21595
|
amount: paymentDetails.amount,
|
21467
21596
|
currency: paymentDetails.currency || "USDT",
|
21468
21597
|
network: paymentDetails.network || preferredNetwork,
|
21469
21598
|
customerEmail: paymentDetails.customerEmail || customerEmail,
|
21470
21599
|
callbackUrl: paymentDetails.callbackUrl,
|
21471
|
-
metadata: paymentDetails.metadata
|
21472
|
-
|
21600
|
+
metadata: __spreadProps(__spreadValues({}, paymentDetails.metadata), {
|
21601
|
+
sdkVersion: "1.0.0",
|
21602
|
+
merchantWallets: finalWalletAddresses
|
21603
|
+
}),
|
21604
|
+
merchantWalletAddresses: finalWalletAddresses
|
21473
21605
|
});
|
21474
21606
|
log("Payment created:", paymentResponse);
|
21475
|
-
|
21476
|
-
|
21477
|
-
|
21478
|
-
|
21607
|
+
if (paymentResponse.payment) {
|
21608
|
+
setPayment(paymentResponse.payment);
|
21609
|
+
if (paymentResponse.merchantConfig && paymentResponse.merchantConfig.walletAddresses) {
|
21610
|
+
setMerchantWallets((prev) => __spreadValues(__spreadValues({}, prev), paymentResponse.merchantConfig.walletAddresses));
|
21611
|
+
log("Updated wallet addresses from payment response:", paymentResponse.merchantConfig.walletAddresses);
|
21612
|
+
}
|
21613
|
+
setPaymentStatus("idle");
|
21614
|
+
setError(null);
|
21615
|
+
} else {
|
21616
|
+
throw new Error("Invalid payment response structure");
|
21617
|
+
}
|
21618
|
+
log("Payment created and state updated successfully");
|
21479
21619
|
} catch (err) {
|
21480
21620
|
log("Error creating payment:", err);
|
21481
21621
|
setError(err.message || "Failed to create payment");
|
@@ -21490,60 +21630,67 @@ const CoinleyCheckout = forwardRef(({
|
|
21490
21630
|
setWalletConnection(null);
|
21491
21631
|
setSelectedPaymentMethod(null);
|
21492
21632
|
setStep("select-currency");
|
21633
|
+
setError(null);
|
21493
21634
|
if (onClose)
|
21494
21635
|
onClose();
|
21495
21636
|
};
|
21496
21637
|
const handlePaymentMethodSelect = (paymentMethod) => {
|
21497
|
-
console.log("=== PAYMENT METHOD SELECTION DEBUG ===");
|
21498
|
-
console.log("1. Payment method selected:", paymentMethod);
|
21499
|
-
console.log("2. Current step before:", step);
|
21500
21638
|
log("Payment method selected:", paymentMethod);
|
21501
21639
|
setSelectedPaymentMethod(paymentMethod);
|
21502
21640
|
setStep("confirm");
|
21503
|
-
console.log("3. Step should now be: confirm");
|
21504
|
-
console.log("=== END PAYMENT METHOD SELECTION DEBUG ===");
|
21505
21641
|
};
|
21506
21642
|
const handleBack = () => {
|
21507
21643
|
if (step === "confirm") {
|
21508
21644
|
setStep("select-currency");
|
21509
21645
|
setWalletConnection(null);
|
21646
|
+
setError(null);
|
21510
21647
|
} else if (step === "error") {
|
21511
21648
|
setStep("confirm");
|
21649
|
+
setError(null);
|
21512
21650
|
}
|
21513
21651
|
};
|
21514
21652
|
const handleConnectWallet = (walletType) => __async(void 0, null, function* () {
|
21515
|
-
console.log("=== WALLET CONNECTION DEBUG ===");
|
21516
|
-
console.log("1. Wallet type requested:", walletType);
|
21517
|
-
console.log("2. Selected payment method:", selectedPaymentMethod);
|
21518
|
-
console.log("3. Available wallets:", availableWallets);
|
21519
|
-
console.log("4. Current step:", step);
|
21520
21653
|
if (!selectedPaymentMethod) {
|
21521
|
-
console.error("No payment method selected");
|
21522
21654
|
setError("Please select a payment method first");
|
21523
21655
|
return;
|
21524
21656
|
}
|
21525
21657
|
try {
|
21526
|
-
console.log("5. Attempting to connect wallet...");
|
21527
21658
|
setError(null);
|
21528
21659
|
log("Connecting wallet:", { walletType, network: selectedPaymentMethod.network });
|
21529
21660
|
const connection = yield connectWallet(walletType, selectedPaymentMethod.network, 2);
|
21530
21661
|
setWalletConnection(connection);
|
21531
21662
|
setError(null);
|
21532
|
-
console.log("6. Connection successful:", connection);
|
21533
21663
|
log("Wallet connected successfully:", connection);
|
21534
21664
|
} catch (err) {
|
21535
|
-
console.error("7. Connection failed:", err);
|
21536
21665
|
log("Wallet connection error:", err);
|
21537
21666
|
setError(err.message || "Failed to connect wallet");
|
21538
21667
|
}
|
21539
|
-
console.log("=== END WALLET CONNECTION DEBUG ===");
|
21540
21668
|
});
|
21669
|
+
const getRecipientAddress = () => {
|
21670
|
+
if (!selectedPaymentMethod)
|
21671
|
+
return null;
|
21672
|
+
const network = selectedPaymentMethod.network;
|
21673
|
+
if (payment && payment.recipientWallet) {
|
21674
|
+
return payment.recipientWallet;
|
21675
|
+
}
|
21676
|
+
if (merchantWallets[network]) {
|
21677
|
+
return merchantWallets[network];
|
21678
|
+
}
|
21679
|
+
if (merchantWalletAddresses[network]) {
|
21680
|
+
return merchantWalletAddresses[network];
|
21681
|
+
}
|
21682
|
+
return null;
|
21683
|
+
};
|
21541
21684
|
const handlePayment = () => __async(void 0, null, function* () {
|
21542
|
-
var _a2, _b;
|
21543
21685
|
if (!payment || !selectedPaymentMethod) {
|
21544
21686
|
setError("Missing payment information");
|
21545
21687
|
return;
|
21546
21688
|
}
|
21689
|
+
const recipientAddress = getRecipientAddress();
|
21690
|
+
if (!recipientAddress && !testMode) {
|
21691
|
+
setError(`No recipient wallet address configured for ${selectedPaymentMethod.network} network`);
|
21692
|
+
return;
|
21693
|
+
}
|
21547
21694
|
if (!walletConnection && !testMode) {
|
21548
21695
|
setError("Please connect your wallet first");
|
21549
21696
|
return;
|
@@ -21558,18 +21705,20 @@ const CoinleyCheckout = forwardRef(({
|
|
21558
21705
|
log("Test mode: Generating mock transaction...");
|
21559
21706
|
txHash = `test_${Date.now().toString(16)}_${Math.random().toString(16).substring(2, 10)}`;
|
21560
21707
|
} else {
|
21561
|
-
|
21562
|
-
|
21563
|
-
|
21564
|
-
|
21565
|
-
|
21708
|
+
log("Sending transaction through wallet...", {
|
21709
|
+
recipientAddress,
|
21710
|
+
amount: payment.totalAmount || payment.amount,
|
21711
|
+
network: selectedPaymentMethod.network
|
21712
|
+
});
|
21713
|
+
const tokenConfig = payment.token || selectedPaymentMethod.tokenConfig;
|
21566
21714
|
txHash = yield sendTransaction(walletConnection, {
|
21567
|
-
to:
|
21568
|
-
amount: payment.amount,
|
21569
|
-
tokenAddress:
|
21570
|
-
tokenDecimals:
|
21715
|
+
to: recipientAddress,
|
21716
|
+
amount: payment.totalAmount || payment.amount,
|
21717
|
+
tokenAddress: tokenConfig == null ? void 0 : tokenConfig.contractAddress,
|
21718
|
+
tokenDecimals: tokenConfig == null ? void 0 : tokenConfig.decimals,
|
21571
21719
|
currency: selectedPaymentMethod.currency,
|
21572
|
-
network: selectedPaymentMethod.network
|
21720
|
+
network: selectedPaymentMethod.network,
|
21721
|
+
tokenConfig
|
21573
21722
|
});
|
21574
21723
|
}
|
21575
21724
|
log("Transaction hash:", txHash);
|
@@ -21590,16 +21739,27 @@ const CoinleyCheckout = forwardRef(({
|
|
21590
21739
|
onSuccess(payment.id, txHash, {
|
21591
21740
|
network: selectedPaymentMethod.network,
|
21592
21741
|
currency: selectedPaymentMethod.currency,
|
21593
|
-
amount: payment.amount
|
21742
|
+
amount: payment.totalAmount || payment.amount,
|
21743
|
+
recipientAddress
|
21594
21744
|
});
|
21595
21745
|
}
|
21596
21746
|
} catch (err) {
|
21597
21747
|
log("Payment error:", err);
|
21598
|
-
|
21748
|
+
let errorMessage = err.message || "Failed to process payment";
|
21749
|
+
if (errorMessage.includes("User rejected") || errorMessage.includes("user rejected")) {
|
21750
|
+
errorMessage = "Transaction was rejected by user";
|
21751
|
+
} else if (errorMessage.includes("insufficient funds")) {
|
21752
|
+
errorMessage = "Insufficient funds in wallet";
|
21753
|
+
} else if (errorMessage.includes("network")) {
|
21754
|
+
errorMessage = "Network error. Please check your connection and try again";
|
21755
|
+
} else if (errorMessage.includes("recipient") || errorMessage.includes("address")) {
|
21756
|
+
errorMessage = "Invalid recipient address. Please contact support";
|
21757
|
+
}
|
21758
|
+
setError(errorMessage);
|
21599
21759
|
setPaymentStatus("error");
|
21600
21760
|
setStep("error");
|
21601
21761
|
if (onError)
|
21602
|
-
onError(
|
21762
|
+
onError(new Error(errorMessage));
|
21603
21763
|
}
|
21604
21764
|
});
|
21605
21765
|
const getSupportedWallets = () => {
|
@@ -21607,6 +21767,12 @@ const CoinleyCheckout = forwardRef(({
|
|
21607
21767
|
return [];
|
21608
21768
|
return getSupportedWalletsForNetwork(selectedPaymentMethod.network);
|
21609
21769
|
};
|
21770
|
+
if (isLoadingWallets) {
|
21771
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "fixed inset-0 z-50 flex items-center justify-center bg-black/50", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "bg-white p-6 rounded-lg shadow-xl", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center space-x-3", children: [
|
21772
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "animate-spin rounded-full h-6 w-6 border-2 border-blue-500 border-t-transparent" }),
|
21773
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-gray-700", children: "Loading payment gateway..." })
|
21774
|
+
] }) }) });
|
21775
|
+
}
|
21610
21776
|
return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: isOpen && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
21611
21777
|
CoinleyModal,
|
21612
21778
|
{
|
@@ -21629,7 +21795,8 @@ const CoinleyCheckout = forwardRef(({
|
|
21629
21795
|
availableWallets,
|
21630
21796
|
supportedWallets: getSupportedWallets(),
|
21631
21797
|
step,
|
21632
|
-
merchantWalletAddresses,
|
21798
|
+
merchantWalletAddresses: merchantWallets,
|
21799
|
+
recipientAddress: getRecipientAddress(),
|
21633
21800
|
debug: effectiveDebug
|
21634
21801
|
}
|
21635
21802
|
) });
|