@kimafinance/kima-transaction-widget 1.1.1 → 1.1.3
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 +8 -21
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +9 -20
- package/dist/index.modern.js.map +1 -1
- package/dist/store/optionSlice.d.ts +1 -3
- package/dist/store/selectors.d.ts +2 -3
- package/package.json +1 -1
package/dist/index.modern.js
CHANGED
|
@@ -9,7 +9,7 @@ import { ethers, BigNumber } from 'ethers';
|
|
|
9
9
|
import AnimatedNumber from 'animated-number-react';
|
|
10
10
|
import { WalletReadyState } from '@solana/wallet-adapter-base';
|
|
11
11
|
import { Contract } from '@ethersproject/contracts';
|
|
12
|
-
import { parseUnits } from '@ethersproject/units';
|
|
12
|
+
import { formatUnits, parseUnits } from '@ethersproject/units';
|
|
13
13
|
import { TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID, AccountLayout } from '@solana/spl-token';
|
|
14
14
|
|
|
15
15
|
const Cross = ({
|
|
@@ -492,7 +492,7 @@ const CHAIN_NAMES_TO_EXPLORER = {
|
|
|
492
492
|
[ChainName.AVALANCHE]: 'testnet.snowtrace.io',
|
|
493
493
|
[ChainName.FUSE]: 'explorer.fuse.io',
|
|
494
494
|
[ChainName.CELO]: 'explorer.celo.org',
|
|
495
|
-
[ChainName.SOLANA]: 'solscan.io'
|
|
495
|
+
[ChainName.SOLANA]: 'solscan.io/blocks?cluster=devnet'
|
|
496
496
|
};
|
|
497
497
|
const CHAIN_NAMES_TO_GECKO_ID = {
|
|
498
498
|
[ChainName.ETHEREUM]: 'ethereum',
|
|
@@ -615,7 +615,6 @@ const initialState = {
|
|
|
615
615
|
isSubmitting: false,
|
|
616
616
|
isConfirming: false,
|
|
617
617
|
feeDeduct: false,
|
|
618
|
-
splAllowance: 0,
|
|
619
618
|
errorHandler: () => void 0,
|
|
620
619
|
closeHandler: () => void 0,
|
|
621
620
|
successHandler: () => void 0,
|
|
@@ -677,9 +676,6 @@ const optionSlice = createSlice({
|
|
|
677
676
|
setSubmitting: (state, action) => {
|
|
678
677
|
state.isSubmitting = action.payload;
|
|
679
678
|
},
|
|
680
|
-
setSplAllowance: (state, action) => {
|
|
681
|
-
state.splAllowance = action.payload;
|
|
682
|
-
},
|
|
683
679
|
setErrorHandler: (state, action) => {
|
|
684
680
|
state.errorHandler = action.payload;
|
|
685
681
|
},
|
|
@@ -731,7 +727,6 @@ const {
|
|
|
731
727
|
setApproving,
|
|
732
728
|
setSubmitting,
|
|
733
729
|
setConfirming,
|
|
734
|
-
setSplAllowance,
|
|
735
730
|
setErrorHandler,
|
|
736
731
|
setCloseHandler,
|
|
737
732
|
setSuccessHandler,
|
|
@@ -767,7 +762,6 @@ const selectTransactionOption = state => state.option.transactionOption;
|
|
|
767
762
|
const selectAmount = state => state.option.amount;
|
|
768
763
|
const selectApproving = state => state.option.isApproving;
|
|
769
764
|
const selectSubmitting = state => state.option.isSubmitting;
|
|
770
|
-
const selectSplAllowance = state => state.option.splAllowance;
|
|
771
765
|
const selectErrorHandler = state => state.option.errorHandler;
|
|
772
766
|
const selectCloseHandler = state => state.option.closeHandler;
|
|
773
767
|
const selectSuccessHandler = state => state.option.successHandler;
|
|
@@ -6194,7 +6188,7 @@ class TokenAmount extends bn {
|
|
|
6194
6188
|
|
|
6195
6189
|
function useAllowance() {
|
|
6196
6190
|
const dispatch = useDispatch();
|
|
6197
|
-
const [allowance, setAllowance] = useState(
|
|
6191
|
+
const [allowance, setAllowance] = useState(0);
|
|
6198
6192
|
const [decimals, setDecimals] = useState(null);
|
|
6199
6193
|
const {
|
|
6200
6194
|
signerAddress,
|
|
@@ -6212,8 +6206,6 @@ function useAllowance() {
|
|
|
6212
6206
|
}, [selectedNetwork, evmChainId]);
|
|
6213
6207
|
const amount = useSelector(selectAmount);
|
|
6214
6208
|
const serviceFee = useSelector(selectServiceFee);
|
|
6215
|
-
const isApproving = useSelector(selectApproving);
|
|
6216
|
-
const splAllowance = useSelector(selectSplAllowance);
|
|
6217
6209
|
const nodeProviderQuery = useSelector(selectNodeProviderQuery);
|
|
6218
6210
|
const {
|
|
6219
6211
|
connection
|
|
@@ -6228,12 +6220,8 @@ function useAllowance() {
|
|
|
6228
6220
|
}, [selectedCoin, sourceChain]);
|
|
6229
6221
|
const [targetAddress, setTargetAddress] = useState();
|
|
6230
6222
|
const isApproved = useMemo(() => {
|
|
6231
|
-
|
|
6232
|
-
|
|
6233
|
-
}
|
|
6234
|
-
if (allowance && amount && allowance.gte(parseUnits((amount + serviceFee).toString(), decimals))) return true;
|
|
6235
|
-
return false;
|
|
6236
|
-
}, [decimals, sourceChain, allowance, amount, splAllowance, serviceFee]);
|
|
6223
|
+
return allowance >= amount + serviceFee;
|
|
6224
|
+
}, [allowance, amount, serviceFee]);
|
|
6237
6225
|
const updatePoolAddress = async () => {
|
|
6238
6226
|
try {
|
|
6239
6227
|
var _result$tssPubkey;
|
|
@@ -6273,12 +6261,12 @@ function useAllowance() {
|
|
|
6273
6261
|
const decimals = await erc20Contract.decimals();
|
|
6274
6262
|
const userAllowance = await erc20Contract.allowance(signerAddress, targetAddress);
|
|
6275
6263
|
setDecimals(+decimals);
|
|
6276
|
-
setAllowance(userAllowance);
|
|
6264
|
+
setAllowance(+formatUnits(userAllowance, decimals));
|
|
6277
6265
|
} catch (error) {
|
|
6278
6266
|
errorHandler(error);
|
|
6279
6267
|
}
|
|
6280
6268
|
})();
|
|
6281
|
-
}, [signerAddress, tokenAddress, targetAddress,
|
|
6269
|
+
}, [signerAddress, tokenAddress, targetAddress, sourceChain, publicKey]);
|
|
6282
6270
|
const approve = useCallback(async () => {
|
|
6283
6271
|
if (isEVMChain(sourceChain)) {
|
|
6284
6272
|
if (!decimals || !tokenAddress || !signer || !targetAddress) return;
|
|
@@ -6288,6 +6276,7 @@ function useAllowance() {
|
|
|
6288
6276
|
const approve = await erc20Contract.approve(targetAddress, parseUnits((amount + serviceFee).toString(), decimals));
|
|
6289
6277
|
await approve.wait();
|
|
6290
6278
|
dispatch(setApproving(false));
|
|
6279
|
+
setAllowance(amount + serviceFee);
|
|
6291
6280
|
} catch (error) {
|
|
6292
6281
|
errorHandler(error);
|
|
6293
6282
|
dispatch(setApproving(false));
|
|
@@ -6306,7 +6295,7 @@ function useAllowance() {
|
|
|
6306
6295
|
transaction.recentBlockhash = await blockHash.blockhash;
|
|
6307
6296
|
const signed = await signTransaction(transaction);
|
|
6308
6297
|
await connection.sendRawTransaction(signed.serialize());
|
|
6309
|
-
|
|
6298
|
+
setAllowance(amount + serviceFee);
|
|
6310
6299
|
dispatch(setApproving(false));
|
|
6311
6300
|
} catch (e) {
|
|
6312
6301
|
errorHandler(e);
|