@kimafinance/kima-transaction-widget 1.2.41 → 1.2.43
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 +36 -110
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +35 -87
- package/dist/index.modern.js.map +1 -1
- package/dist/utils/constants.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.modern.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useState, useEffect, useMemo, useRef, useCallback } from 'react';
|
|
2
2
|
import * as toolkitRaw from '@reduxjs/toolkit';
|
|
3
|
-
import { clusterApiUrl,
|
|
3
|
+
import { clusterApiUrl, PublicKey, TransactionInstruction, Transaction } from '@solana/web3.js';
|
|
4
4
|
import { useSelector, useDispatch, Provider } from 'react-redux';
|
|
5
5
|
import * as SolanaAdapter from '@solana/wallet-adapter-react';
|
|
6
6
|
import { useWallet, useConnection } from '@solana/wallet-adapter-react';
|
|
@@ -18,7 +18,7 @@ import { WalletReadyState } from '@solana/wallet-adapter-base';
|
|
|
18
18
|
import { getAddress, AddressPurpose, BitcoinNetworkType, signTransaction, sendBtcTransaction } from 'sats-connect';
|
|
19
19
|
import { Contract } from '@ethersproject/contracts';
|
|
20
20
|
import { formatUnits, parseUnits } from '@ethersproject/units';
|
|
21
|
-
import { TOKEN_PROGRAM_ID,
|
|
21
|
+
import { TOKEN_PROGRAM_ID, AccountLayout, ASSOCIATED_TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
22
22
|
import { TronWeb } from 'tronweb';
|
|
23
23
|
import { ethers, utils as utils$3 } from 'ethers';
|
|
24
24
|
import BufferLayout from 'buffer-layout';
|
|
@@ -2077,43 +2077,6 @@ var ERC20ABI = {
|
|
|
2077
2077
|
abi: abi
|
|
2078
2078
|
};
|
|
2079
2079
|
|
|
2080
|
-
function createAssociatedTokenAccountInstruction(payer, associatedToken, owner, mint, programId = TOKEN_PROGRAM_ID, associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID) {
|
|
2081
|
-
const keys = [{
|
|
2082
|
-
pubkey: payer,
|
|
2083
|
-
isSigner: true,
|
|
2084
|
-
isWritable: true
|
|
2085
|
-
}, {
|
|
2086
|
-
pubkey: associatedToken,
|
|
2087
|
-
isSigner: false,
|
|
2088
|
-
isWritable: true
|
|
2089
|
-
}, {
|
|
2090
|
-
pubkey: owner,
|
|
2091
|
-
isSigner: false,
|
|
2092
|
-
isWritable: false
|
|
2093
|
-
}, {
|
|
2094
|
-
pubkey: mint,
|
|
2095
|
-
isSigner: false,
|
|
2096
|
-
isWritable: false
|
|
2097
|
-
}, {
|
|
2098
|
-
pubkey: SystemProgram.programId,
|
|
2099
|
-
isSigner: false,
|
|
2100
|
-
isWritable: false
|
|
2101
|
-
}, {
|
|
2102
|
-
pubkey: programId,
|
|
2103
|
-
isSigner: false,
|
|
2104
|
-
isWritable: false
|
|
2105
|
-
}, {
|
|
2106
|
-
pubkey: SYSVAR_RENT_PUBKEY,
|
|
2107
|
-
isSigner: false,
|
|
2108
|
-
isWritable: false
|
|
2109
|
-
}];
|
|
2110
|
-
return new TransactionInstruction({
|
|
2111
|
-
keys,
|
|
2112
|
-
programId: associatedTokenProgramId,
|
|
2113
|
-
data: Buffer.alloc(0)
|
|
2114
|
-
});
|
|
2115
|
-
}
|
|
2116
|
-
|
|
2117
2080
|
var AccountState;
|
|
2118
2081
|
(function (AccountState) {
|
|
2119
2082
|
AccountState[AccountState["Uninitialized"] = 0] = "Uninitialized";
|
|
@@ -2149,26 +2112,11 @@ async function getAssociatedTokenAddress(mint, owner, allowOwnerOffCurve = false
|
|
|
2149
2112
|
|
|
2150
2113
|
async function getOrCreateAssociatedTokenAccount(connection, payer, mint, owner, signTransaction, allowOwnerOffCurve = false, commitment, programId = TOKEN_PROGRAM_ID, associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID) {
|
|
2151
2114
|
const associatedToken = await getAssociatedTokenAddress(mint, owner, allowOwnerOffCurve, programId, associatedTokenProgramId);
|
|
2115
|
+
console.log(payer, signTransaction);
|
|
2152
2116
|
let account;
|
|
2153
2117
|
try {
|
|
2154
2118
|
account = await getAccountInfo(connection, associatedToken, commitment, programId);
|
|
2155
|
-
} catch (error) {
|
|
2156
|
-
const err = error;
|
|
2157
|
-
if (err.message === 'TokenAccountNotFoundError' || err.message === 'TokenInvalidAccountOwnerError') {
|
|
2158
|
-
try {
|
|
2159
|
-
const transaction = new Transaction().add(createAssociatedTokenAccountInstruction(payer, associatedToken, owner, mint, programId, associatedTokenProgramId));
|
|
2160
|
-
const blockHash = await connection.getRecentBlockhash();
|
|
2161
|
-
transaction.feePayer = await payer;
|
|
2162
|
-
transaction.recentBlockhash = await blockHash.blockhash;
|
|
2163
|
-
const signed = await signTransaction(transaction);
|
|
2164
|
-
const signature = await connection.sendRawTransaction(signed.serialize());
|
|
2165
|
-
await connection.confirmTransaction(signature);
|
|
2166
|
-
} catch (error) {}
|
|
2167
|
-
account = await getAccountInfo(connection, associatedToken, commitment, programId);
|
|
2168
|
-
} else {
|
|
2169
|
-
throw error;
|
|
2170
|
-
}
|
|
2171
|
-
}
|
|
2119
|
+
} catch (error) {}
|
|
2172
2120
|
if (!account.mint.equals(mint)) throw Error('TokenInvalidMintError');
|
|
2173
2121
|
if (!account.owner.equals(owner)) throw new Error('TokenInvalidOwnerError');
|
|
2174
2122
|
return account;
|
|
@@ -11965,53 +11913,53 @@ const {
|
|
|
11965
11913
|
WalletProvider: SolanaWalletProvider
|
|
11966
11914
|
} = SolanaAdapter;
|
|
11967
11915
|
const ethereum = {
|
|
11968
|
-
chainId:
|
|
11969
|
-
name: 'Ethereum
|
|
11916
|
+
chainId: 1,
|
|
11917
|
+
name: 'Ethereum Mainnet',
|
|
11970
11918
|
currency: 'ETH',
|
|
11971
|
-
explorerUrl: 'https://
|
|
11972
|
-
rpcUrl: 'https://
|
|
11919
|
+
explorerUrl: 'https://etherscan.io',
|
|
11920
|
+
rpcUrl: 'https://eth.llamarpc.com'
|
|
11973
11921
|
};
|
|
11974
11922
|
const bsc = {
|
|
11975
|
-
chainId:
|
|
11976
|
-
name: 'BNB Smart Chain
|
|
11977
|
-
currency: '
|
|
11978
|
-
explorerUrl: 'https://
|
|
11979
|
-
rpcUrl: 'https://
|
|
11923
|
+
chainId: 56,
|
|
11924
|
+
name: 'BNB Smart Chain Mainnet',
|
|
11925
|
+
currency: 'BNB',
|
|
11926
|
+
explorerUrl: 'https://bscscan.com',
|
|
11927
|
+
rpcUrl: 'https://binance.llamarpc.com'
|
|
11980
11928
|
};
|
|
11981
11929
|
const polygon = {
|
|
11982
|
-
chainId:
|
|
11983
|
-
name: '
|
|
11930
|
+
chainId: 137,
|
|
11931
|
+
name: 'Polygon Mainnet',
|
|
11984
11932
|
currency: 'MATIC',
|
|
11985
|
-
explorerUrl: 'https://
|
|
11986
|
-
rpcUrl: 'https://
|
|
11933
|
+
explorerUrl: 'https://polygonscan.com',
|
|
11934
|
+
rpcUrl: 'https://polygon.llamarpc.com'
|
|
11987
11935
|
};
|
|
11988
11936
|
const arbitrum = {
|
|
11989
|
-
chainId:
|
|
11990
|
-
name: 'Arbitrum
|
|
11937
|
+
chainId: 42161,
|
|
11938
|
+
name: 'Arbitrum Mainnet',
|
|
11991
11939
|
currency: 'ETH',
|
|
11992
|
-
explorerUrl: 'https://
|
|
11993
|
-
rpcUrl: 'https://
|
|
11940
|
+
explorerUrl: 'https://arbiscan.io',
|
|
11941
|
+
rpcUrl: 'https://arbitrum.llamarpc.com'
|
|
11994
11942
|
};
|
|
11995
11943
|
const optimism = {
|
|
11996
|
-
chainId:
|
|
11997
|
-
name: 'OP
|
|
11944
|
+
chainId: 10,
|
|
11945
|
+
name: 'OP Mainnet',
|
|
11998
11946
|
currency: 'ETH',
|
|
11999
|
-
explorerUrl: 'https://
|
|
12000
|
-
rpcUrl: 'https://
|
|
11947
|
+
explorerUrl: 'https://optimistic.etherscan.io',
|
|
11948
|
+
rpcUrl: 'https://optimism.llamarpc.com'
|
|
12001
11949
|
};
|
|
12002
11950
|
const avalanche = {
|
|
12003
|
-
chainId:
|
|
12004
|
-
name: 'Avalanche
|
|
11951
|
+
chainId: 43114,
|
|
11952
|
+
name: 'Avalanche Mainnet',
|
|
12005
11953
|
currency: 'AVAX',
|
|
12006
|
-
explorerUrl: 'https://
|
|
12007
|
-
rpcUrl: 'https://api.avax
|
|
11954
|
+
explorerUrl: 'https://snowtrace.io',
|
|
11955
|
+
rpcUrl: 'https://api.avax.network/ext/bc/C/rpc'
|
|
12008
11956
|
};
|
|
12009
11957
|
const zkEVM = {
|
|
12010
|
-
chainId:
|
|
11958
|
+
chainId: 1101,
|
|
12011
11959
|
name: 'Polygon zkEVM Cardona Testnet',
|
|
12012
11960
|
currency: 'ETH',
|
|
12013
|
-
explorerUrl: 'https://
|
|
12014
|
-
rpcUrl: 'https://
|
|
11961
|
+
explorerUrl: 'https://zkevm.polygonscan.com',
|
|
11962
|
+
rpcUrl: 'https://rpc.ankr.com/polygon_zkevm'
|
|
12015
11963
|
};
|
|
12016
11964
|
const metadata = {
|
|
12017
11965
|
name: 'Kima Transaction Widget',
|
|
@@ -12041,9 +11989,9 @@ const KimaProvider = ({
|
|
|
12041
11989
|
} else toast$1.error(e.message);
|
|
12042
11990
|
}
|
|
12043
11991
|
const onChainChanged = chainData => {
|
|
12044
|
-
toast$1.error('Please switch to Tron
|
|
12045
|
-
if (chainData.chainId !== '
|
|
12046
|
-
adapters[0].switchChain('
|
|
11992
|
+
toast$1.error('Please switch to Tron Mainnet!');
|
|
11993
|
+
if (chainData.chainId !== '0x2b6653dc') {
|
|
11994
|
+
adapters[0].switchChain('0x2b6653dc');
|
|
12047
11995
|
}
|
|
12048
11996
|
};
|
|
12049
11997
|
createWeb3Modal({
|