@kimafinance/kima-transaction-widget 1.2.22-beta.1 → 1.2.24-beta.1

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/dist/index.js CHANGED
@@ -936,6 +936,8 @@ var createSlice = toolkitRaw.createSlice;
936
936
  var initialState = {
937
937
  theme: {},
938
938
  tokenOptions: {},
939
+ pendingTxs: 0,
940
+ pendingTxData: [],
939
941
  kimaExplorerUrl: 'explorer.kima.finance',
940
942
  mode: exports.ModeOptions.bridge,
941
943
  sourceChain: '',
@@ -1014,6 +1016,12 @@ var optionSlice = createSlice({
1014
1016
  state.targetNetworkFetching = false;
1015
1017
  state.signature = '';
1016
1018
  },
1019
+ setPendingTxs: function setPendingTxs(state, action) {
1020
+ state.pendingTxs = action.payload;
1021
+ },
1022
+ setPendingTxData: function setPendingTxData(state, action) {
1023
+ state.pendingTxData = action.payload;
1024
+ },
1017
1025
  setTokenOptions: function setTokenOptions(state, action) {
1018
1026
  state.tokenOptions = action.payload;
1019
1027
  },
@@ -1196,7 +1204,9 @@ var _optionSlice$actions = optionSlice.actions,
1196
1204
  setSignature = _optionSlice$actions.setSignature,
1197
1205
  setUuid = _optionSlice$actions.setUuid,
1198
1206
  setKYCStatus = _optionSlice$actions.setKYCStatus,
1199
- setExpireTime = _optionSlice$actions.setExpireTime;
1207
+ setExpireTime = _optionSlice$actions.setExpireTime,
1208
+ setPendingTxData = _optionSlice$actions.setPendingTxData,
1209
+ setPendingTxs = _optionSlice$actions.setPendingTxs;
1200
1210
  var optionReducer = optionSlice.reducer;
1201
1211
 
1202
1212
  var configureStore = toolkitRaw.configureStore;
@@ -1589,6 +1599,12 @@ var selectKycStatus = function selectKycStatus(state) {
1589
1599
  var selectExpireTime = function selectExpireTime(state) {
1590
1600
  return state.option.expireTime;
1591
1601
  };
1602
+ var selectPendingTxs = function selectPendingTxs(state) {
1603
+ return state.option.pendingTxs;
1604
+ };
1605
+ var selectPendingTxData = function selectPendingTxData(state) {
1606
+ return state.option.pendingTxData;
1607
+ };
1592
1608
 
1593
1609
  var Loading180Ring = function Loading180Ring(_ref) {
1594
1610
  var _ref$width = _ref.width,
@@ -2209,7 +2225,10 @@ function useIsWalletReady() {
2209
2225
  var _useState = React.useState('loading'),
2210
2226
  capabilityState = _useState[0],
2211
2227
  setCapabilityState = _useState[1];
2212
- var capabilityMessage = capabilityState === 'loading' ? 'Checking capabilities...' : capabilityState === 'cancelled' ? 'Capability check cancelled by wallet. Please refresh the page and try again.' : capabilityState === 'missing' ? 'Could not find an installed Sats Connect capable wallet. Please install a wallet and try again.' : undefined;
2228
+ var _useState2 = React.useState(),
2229
+ capabilities = _useState2[0],
2230
+ setCapabilities = _useState2[1];
2231
+ var capabilityMessage = capabilityState === 'loading' ? 'Checking capabilities...' : capabilityState === 'cancelled' ? 'Capability check cancelled by wallet. Please refresh the page and try again.' : capabilityState === 'missing' ? 'Could not find an installed Sats Connect capable wallet. Please install a wallet and try again.' : !capabilities ? 'Something went wrong with getting capabilities' : undefined;
2213
2232
  React.useEffect(function () {
2214
2233
  var _events$data, _events$data2;
2215
2234
  if (((_events$data = events.data) === null || _events$data === void 0 ? void 0 : _events$data.event) === 'SELECT_WALLET' || ((_events$data2 = events.data) === null || _events$data2 === void 0 ? void 0 : _events$data2.event) === 'CONNECT_SUCCESS') {
@@ -2218,7 +2237,6 @@ function useIsWalletReady() {
2218
2237
  }
2219
2238
  }, [events]);
2220
2239
  React.useEffect(function () {
2221
- if (sourceChain !== exports.SupportNetworks.BTC) return;
2222
2240
  var runCapabilityCheck = function runCapabilityCheck() {
2223
2241
  try {
2224
2242
  var runs = 0;
@@ -2229,12 +2247,13 @@ function useIsWalletReady() {
2229
2247
  }, void 0, function () {
2230
2248
  function _temp2() {
2231
2249
  return Promise.resolve(new Promise(function (resolve) {
2232
- return setTimeout(resolve, 1000);
2250
+ return setTimeout(resolve, 100);
2233
2251
  })).then(function () {});
2234
2252
  }
2235
2253
  var _temp = _catch(function () {
2236
2254
  return Promise.resolve(satsConnect.getCapabilities({
2237
- onFinish: function onFinish() {
2255
+ onFinish: function onFinish(response) {
2256
+ setCapabilities(new Set(response));
2238
2257
  setCapabilityState('loaded');
2239
2258
  },
2240
2259
  onCancel: function onCancel() {
@@ -2260,7 +2279,7 @@ function useIsWalletReady() {
2260
2279
  }
2261
2280
  };
2262
2281
  runCapabilityCheck();
2263
- }, [sourceChain]);
2282
+ }, []);
2264
2283
  var connectBitcoinWallet = React.useCallback(function () {
2265
2284
  try {
2266
2285
  return Promise.resolve(satsConnect.getAddress({
@@ -2796,7 +2815,6 @@ function useBalance() {
2796
2815
  var tokenOptions = reactRedux.useSelector(selectTokenOptions);
2797
2816
  var tokenAddress = React.useMemo(function () {
2798
2817
  if (isEmptyObject(tokenOptions) || sourceChain === exports.SupportNetworks.FIAT) return '';
2799
- console.log(tokenOptions);
2800
2818
  if (tokenOptions && typeof tokenOptions === 'object') {
2801
2819
  var coinOptions = tokenOptions[selectedCoin];
2802
2820
  if (coinOptions && typeof coinOptions === 'object') {
@@ -8243,79 +8261,6 @@ var PendingTxPopup = function PendingTxPopup(_ref) {
8243
8261
  }))))));
8244
8262
  };
8245
8263
 
8246
- function usePendingTx(_ref) {
8247
- var walletAddress = _ref.walletAddress;
8248
- var _useState = React.useState(0),
8249
- pendingTxs = _useState[0],
8250
- setPendingTxs = _useState[1];
8251
- var _useState2 = React.useState([]),
8252
- pendingTxData = _useState2[0],
8253
- setPendingTxData = _useState2[1];
8254
- var sourceChain = reactRedux.useSelector(selectSourceChain);
8255
- var nodeProviderQuery = reactRedux.useSelector(selectNodeProviderQuery);
8256
- React.useEffect(function () {
8257
- console.log(nodeProviderQuery, sourceChain, walletAddress);
8258
- if (!nodeProviderQuery || sourceChain !== exports.SupportNetworks.BTC || !walletAddress) return;
8259
- var updatePendingTxs = function updatePendingTxs() {
8260
- try {
8261
- var _temp = _catch(function () {
8262
- return Promise.resolve(fetchWrapper.get(nodeProviderQuery + "/kima-finance/kima-blockchain/transaction/get_htlc_transaction/" + walletAddress)).then(function (result) {
8263
- var data = result === null || result === void 0 ? void 0 : result.htlcLockingTransaction;
8264
- var txData = [];
8265
- if (data.length > 0) {
8266
- for (var _iterator = _createForOfIteratorHelperLoose(data), _step; !(_step = _iterator()).done;) {
8267
- var tx = _step.value;
8268
- var status = '';
8269
- if (tx.status !== 'Completed') {
8270
- status = 'Confirming';
8271
- } else if (tx.pull_status === 'htlc_pull_available') {
8272
- status = 'Pending';
8273
- } else if (tx.pull_status === 'htlc_pull_in_progress') {
8274
- status = 'In Progress';
8275
- } else if (tx.pull_status === 'htlc_pull_succeed') {
8276
- status = 'Completed';
8277
- } else if (tx.pull_status === 'htlc_pull_failed') {
8278
- status = 'Failed';
8279
- }
8280
- txData.push({
8281
- hash: tx.txHash,
8282
- amount: tx.amount,
8283
- expireTime: tx.htlcTimestamp,
8284
- status: status
8285
- });
8286
- }
8287
- console.log(txData);
8288
- setPendingTxData([].concat(txData));
8289
- setPendingTxs(txData.filter(function (tx) {
8290
- return tx.status === 'Pending' || tx.status === 'Confirming';
8291
- }).length);
8292
- }
8293
- });
8294
- }, function (e) {
8295
- console.log(e);
8296
- });
8297
- return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
8298
- } catch (e) {
8299
- return Promise.reject(e);
8300
- }
8301
- };
8302
- var timerId = setInterval(function () {
8303
- updatePendingTxs();
8304
- }, 10000);
8305
- updatePendingTxs();
8306
- return function () {
8307
- console.log('clearInterval', timerId);
8308
- clearInterval(timerId);
8309
- };
8310
- }, [sourceChain, nodeProviderQuery, walletAddress]);
8311
- return React.useMemo(function () {
8312
- return {
8313
- pendingTxData: pendingTxData,
8314
- pendingTxs: pendingTxs
8315
- };
8316
- }, [pendingTxs, pendingTxData]);
8317
- }
8318
-
8319
8264
  var TransferWidget = function TransferWidget(_ref) {
8320
8265
  var _theme$backgroundColo;
8321
8266
  var theme = _ref.theme,
@@ -8387,11 +8332,8 @@ var TransferWidget = function TransferWidget(_ref) {
8387
8332
  var _useIsWalletReady = useIsWalletReady(),
8388
8333
  isReady = _useIsWalletReady.isReady,
8389
8334
  walletAddress = _useIsWalletReady.walletAddress;
8390
- var _usePendingTx = usePendingTx({
8391
- walletAddress: walletAddress || ''
8392
- }),
8393
- pendingTxData = _usePendingTx.pendingTxData,
8394
- pendingTxs = _usePendingTx.pendingTxs;
8335
+ var pendingTxData = reactRedux.useSelector(selectPendingTxData);
8336
+ var pendingTxs = reactRedux.useSelector(selectPendingTxs);
8395
8337
  var _useAllowance = useAllowance({
8396
8338
  setApproving: setApproving
8397
8339
  }),
@@ -8861,6 +8803,58 @@ var TransferWidget = function TransferWidget(_ref) {
8861
8803
  React.useEffect(function () {
8862
8804
  dispatch(setTheme(theme));
8863
8805
  }, [theme]);
8806
+ var updatePendingTxs = function updatePendingTxs() {
8807
+ try {
8808
+ var _temp9 = _catch(function () {
8809
+ return Promise.resolve(fetchWrapper.get(nodeProviderQuery + "/kima-finance/kima-blockchain/transaction/get_htlc_transaction/" + walletAddress)).then(function (result) {
8810
+ var data = result === null || result === void 0 ? void 0 : result.htlcLockingTransaction;
8811
+ var txData = [];
8812
+ if (data.length > 0) {
8813
+ for (var _iterator5 = _createForOfIteratorHelperLoose(data), _step5; !(_step5 = _iterator5()).done;) {
8814
+ var tx = _step5.value;
8815
+ var status = '';
8816
+ if (tx.status !== 'Completed') {
8817
+ status = 'Confirming';
8818
+ } else if (tx.pull_status === 'htlc_pull_available') {
8819
+ status = 'Pending';
8820
+ } else if (tx.pull_status === 'htlc_pull_in_progress') {
8821
+ status = 'In Progress';
8822
+ } else if (tx.pull_status === 'htlc_pull_succeed') {
8823
+ status = 'Completed';
8824
+ } else if (tx.pull_status === 'htlc_pull_failed') {
8825
+ status = 'Failed';
8826
+ }
8827
+ txData.push({
8828
+ hash: tx.txHash,
8829
+ amount: tx.amount,
8830
+ expireTime: tx.htlcTimestamp,
8831
+ status: status
8832
+ });
8833
+ }
8834
+ dispatch(setPendingTxData([].concat(txData)));
8835
+ dispatch(setPendingTxs(txData.filter(function (tx) {
8836
+ return tx.status === 'Pending' || tx.status === 'Confirming';
8837
+ }).length));
8838
+ }
8839
+ });
8840
+ }, function (e) {
8841
+ console.log(e);
8842
+ });
8843
+ return Promise.resolve(_temp9 && _temp9.then ? _temp9.then(function () {}) : void 0);
8844
+ } catch (e) {
8845
+ return Promise.reject(e);
8846
+ }
8847
+ };
8848
+ React.useEffect(function () {
8849
+ if (!nodeProviderQuery || sourceChain !== exports.SupportNetworks.BTC || !walletAddress) return;
8850
+ updatePendingTxs();
8851
+ var timerId = setInterval(function () {
8852
+ updatePendingTxs();
8853
+ }, 10000);
8854
+ return function () {
8855
+ clearInterval(timerId);
8856
+ };
8857
+ }, [sourceChain, nodeProviderQuery, walletAddress]);
8864
8858
  return React__default.createElement("div", {
8865
8859
  className: "kima-card " + theme.colorMode + " font-" + theme.fontSize,
8866
8860
  style: {