Skip to content

Commit 8ef2167

Browse files
fix some issue
1 parent 4583b57 commit 8ef2167

File tree

7 files changed

+51
-27
lines changed

7 files changed

+51
-27
lines changed

examples/react/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@interchain-kit/coin98-extension": "0.3.47",
3030
"@interchain-kit/compass-extension": "0.3.47",
3131
"@interchain-kit/core": "0.3.47",
32+
"@interchain-kit/store": "0.3.47",
3233
"@interchain-kit/cosmos-extension-metamask": "0.3.47",
3334
"@interchain-kit/exodus-extension": "0.3.47",
3435
"@interchain-kit/fin-extension": "0.3.47",
@@ -79,4 +80,4 @@
7980
"vite": "^5.3.1"
8081
},
8182
"gitHead": "23631f4e4f9c1781d4de792a8da826cf0041180d"
82-
}
83+
}

examples/react/src/main.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,17 @@ const _chains = [
149149
// "http://localhost:26657",
150150
// "http://localhost:1317"
151151
// ),
152-
];
152+
].map((c) => {
153+
if (c.chainName === "solana") {
154+
c.chainId = "4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ";
155+
}
156+
/**
157+
* 主网:solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ(或简化为 solana:mainnet)
158+
测试网:solana:8E9rvCKLFYuNbobMWfCabm7Kkm2PzQw6A6FMnH7nL5V(或 solana:devnet)
159+
开发网:solana:EtWTRABZaYq6iMfeAkw(或 solana:devnet)
160+
*/
161+
return c;
162+
});
153163
// const _chains = [starshipChain1]
154164
const _assetLists = [
155165
...assetLists.filter((a) => chainNames.includes(a.chainName)),
@@ -185,11 +195,11 @@ const _wallets: BaseWallet[] = [
185195
// cosmostationWallet,
186196
// stationWallet,
187197
// galaxyStationWallet,
188-
// walletConnect,
189-
// ledgerWallet,
190-
// cosmosExtensionMetaMask,
191198
walletConnect,
192199
// ledgerWallet,
200+
// cosmosExtensionMetaMask,
201+
// walletConnect,
202+
ledgerWallet,
193203
// leapCosmosExtensionMetaMask,
194204
// compassWallet,
195205
// trustWallet,

examples/react/src/pages/all-wallets.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
EthereumWallet,
55
isMobile,
66
MultiChainWallet,
7+
SolanaWallet,
78
WCWallet,
89
} from "@interchain-kit/core";
910
import {
@@ -22,7 +23,7 @@ import QRCode from "react-qr-code";
2223
import { send } from "interchainjs/cosmos/bank/v1beta1/tx.rpc.func";
2324
import { RpcClient } from "@interchainjs/cosmos/query/rpc";
2425
import { ethers } from "ethers";
25-
import { StatefulWallet } from "@interchain-kit/react/store/stateful-wallet";
26+
2627
import {
2728
Connection,
2829
PublicKey,
@@ -31,10 +32,11 @@ import {
3132
SystemProgram,
3233
} from "@solana/web3.js";
3334
import { MsgSend } from "interchainjs/cosmos/bank/v1beta1/tx";
35+
import { ChainWalletStore } from "@interchain-kit/store";
3436

3537
type BalanceProps = {
3638
address: string;
37-
wallet: StatefulWallet;
39+
wallet: ChainWalletStore;
3840
chainName: string;
3941
chainId: string;
4042
chain: Chain;
@@ -44,7 +46,7 @@ type BalanceProps = {
4446
const BalanceTd = ({ address, wallet, chain, assetList }: BalanceProps) => {
4547
const { rpcEndpoint } = useChainWallet(
4648
chain.chainName,
47-
wallet.info?.name as string
49+
wallet.info.name as string
4850
);
4951

5052
const [isLoading, setIsLoading] = useState(false);
@@ -98,7 +100,7 @@ const BalanceTd = ({ address, wallet, chain, assetList }: BalanceProps) => {
98100
};
99101

100102
type SendTokenProps = {
101-
wallet: StatefulWallet;
103+
wallet: ChainWalletStore;
102104
address: string;
103105
chain: Chain;
104106
};
@@ -207,9 +209,14 @@ const SendTokenTd = ({ wallet, address, chain }: SendTokenProps) => {
207209
transaction.feePayer = new PublicKey(address);
208210
const { blockhash } = await connection.getLatestBlockhash();
209211
transaction.recentBlockhash = blockhash;
210-
const client = await wallet.getProvider(chain.chainId as string);
211-
// 3. Phantom 签名
212-
const signed = await client.signTransaction(transaction);
212+
// const client = await wallet.getProvider(chain.chainId as string);
213+
//3. Phantom 签名
214+
// const signed = await client.signTransaction(transaction);
215+
// console.log(signed);
216+
217+
const solanaWallet = wallet.getWalletOfType(SolanaWallet);
218+
const signed = await solanaWallet.signTransaction(transaction);
219+
console.log(signed);
213220

214221
// 4. 发送交易
215222
const signature = await connection.sendRawTransaction(signed.serialize());

packages/store/src/store/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class InterchainStore {
144144
}
145145

146146
isChainWalletStateExisted(walletName: string, chainName: string) {
147-
return this.chainWalletIndexMap.get(`${walletName}-${chainName}`)
147+
return this.chainWalletIndexMap.get(`${walletName}-${chainName}`) !== undefined;
148148
}
149149
}
150150

packages/store/src/wallet-manager/chain-wallet-store.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { StdSignDoc } from '@interchainjs/types';
21
import { Chain } from '@chain-registry/types';
32
import { BaseWallet, CosmosWallet, DirectSignDoc, getWalletByType, isInstanceOf, OfflineAminoSigner, OfflineDirectSigner, SignType, WalletAccount, WalletManager, WalletState, WCWallet } from '@interchain-kit/core';
3+
import { StdSignDoc } from '@interchainjs/types';
44

55
import { InterchainStore } from '../store';
66

@@ -21,6 +21,7 @@ export class ChainWalletStore extends BaseWallet {
2121
this.chain = chain;
2222
this.store = store;
2323
this.walletManager = walletManager;
24+
this.info = this.wallet.info;
2425
}
2526

2627
get walletState(): WalletState {
@@ -33,14 +34,14 @@ export class ChainWalletStore extends BaseWallet {
3334

3435
async init(): Promise<void> {
3536
this.wallet.events.on('accountChanged', () => {
36-
this.refreshAccount()
37+
this.refreshAccount();
3738
});
3839
}
3940
async connect(): Promise<void> {
4041

4142
const chainWalletState = this.store.getChainWalletState(this.wallet.info.name, this.chain.chainName);
4243
if (chainWalletState && chainWalletState.walletState === WalletState.NotExist) {
43-
return Promise.resolve()
44+
return Promise.resolve();
4445
}
4546

4647
if (isInstanceOf(this.wallet, WCWallet)) {
@@ -51,7 +52,8 @@ export class ChainWalletStore extends BaseWallet {
5152
}
5253

5354
try {
54-
this.store.updateChainWalletState(this.wallet.info.name, this.chain.chainName, { walletState: WalletState.Connecting });
55+
console.log(1);
56+
this.store.updateChainWalletState(this.wallet.info.name, this.chain.chainName, { walletState: WalletState.Connecting, errorMessage: '' });
5557
await this.wallet.connect(this.chain.chainId);
5658
const account = await this.getAccount();
5759
this.store.updateChainWalletState(this.wallet.info.name, this.chain.chainName, { walletState: WalletState.Connected, account });
@@ -77,9 +79,7 @@ export class ChainWalletStore extends BaseWallet {
7779

7880
async refreshAccount(): Promise<void> {
7981
try {
80-
const account = await this.wallet.getAccount(this.chain.chainId)
81-
82-
console.log(this.wallet)
82+
const account = await this.wallet.getAccount(this.chain.chainId);
8383

8484
this.store.updateChainWalletState(this.wallet.info.name, this.chain.chainName, { account });
8585
} catch (error) {
@@ -108,20 +108,20 @@ export class ChainWalletStore extends BaseWallet {
108108

109109
const preferredSignTypeFromSettings = this.walletManager.getPreferSignType(this.chain.chainName);
110110

111-
const account = await this.getAccount()
111+
const account = await this.getAccount();
112112

113113
const aminoOfflineSigner = {
114114
getAccounts: async () => [account],
115115
signAmino: async (signer: string, signDoc: StdSignDoc) => {
116116
return cosmosWallet.signAmino(this.chain.chainId, signer, signDoc, {});
117117
}
118-
}
118+
};
119119
const directOfflineSigner = {
120120
getAccounts: async () => [account],
121121
signDirect: async (signer: string, signDoc: DirectSignDoc) => {
122122
return cosmosWallet.signDirect(this.chain.chainId, signer, signDoc, {});
123123
}
124-
}
124+
};
125125

126126
const signType = preferSignType || preferredSignTypeFromSettings;
127127

packages/store/src/wallet-manager/wallet-store.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Chain } from '@chain-registry/types';
2-
import { BaseWallet, WalletAccount, WalletManager, WalletState } from '@interchain-kit/core';
2+
import { BaseWallet, getWalletByType, WalletAccount, WalletManager, WalletState } from '@interchain-kit/core';
33

44
import { InterchainStore } from '../store';
55
import { ChainWalletStore } from './chain-wallet-store';
@@ -119,4 +119,7 @@ export class WalletStore extends BaseWallet {
119119
}
120120
return this.getChainWalletStore(chain.chainName).getProvider();
121121
}
122+
getWalletOfType<T>(WalletClass: new (...args: any[]) => T) {
123+
return getWalletByType(this.wallet, WalletClass);
124+
}
122125
}

wallets/coin98-extension/src/extension.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { CosmosWallet, EthereumWallet, MultiChainWallet } from '@interchain-kit/core';
22

3+
import { coin98ExtensionInfo } from './registry';
34

4-
const coin98Wallet = new MultiChainWallet(Coin98ExtensionInfo);
5+
export * from './registry';
56

6-
coin98Wallet.setNetworkWallet('eip155', new EthereumWallet(Coin98ExtensionInfo));
7-
coin98Wallet.setNetworkWallet('cosmos', new CosmosWallet(Coin98ExtensionInfo));
7+
const coin98Wallet = new MultiChainWallet(coin98ExtensionInfo);
8+
9+
coin98Wallet.setNetworkWallet('eip155', new EthereumWallet(coin98ExtensionInfo));
10+
coin98Wallet.setNetworkWallet('cosmos', new CosmosWallet(coin98ExtensionInfo));
811

912
export {
1013
coin98Wallet

0 commit comments

Comments
 (0)