@shelby-protocol/solana-kit 0.1.2-alpha.6 → 0.1.2-alpha.8
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/README.md +32 -9
- package/dist/react/index.d.ts +8 -5
- package/dist/react/index.mjs +9 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -143,28 +143,26 @@ await shelbyClient.upload({
|
|
|
143
143
|
|
|
144
144
|
## React Integration
|
|
145
145
|
|
|
146
|
-
For React applications, use the `useStorageAccount` hook
|
|
146
|
+
For React applications, use the `useStorageAccount` hook with `@solana/react-hooks`:
|
|
147
147
|
|
|
148
148
|
```tsx
|
|
149
149
|
"use client";
|
|
150
150
|
|
|
151
151
|
import { useStorageAccount, Network } from "@shelby-protocol/solana-kit/react";
|
|
152
152
|
import { ShelbyClient } from "@shelby-protocol/sdk/browser";
|
|
153
|
-
import {
|
|
153
|
+
import { useWalletConnection } from "@solana/react-hooks";
|
|
154
154
|
|
|
155
155
|
function MyComponent() {
|
|
156
|
-
const wallet =
|
|
156
|
+
const { wallet } = useWalletConnection();
|
|
157
157
|
const shelbyClient = new ShelbyClient({
|
|
158
158
|
network: Network.SHELBYNET,
|
|
159
159
|
apiKey: "AG-***",
|
|
160
160
|
});
|
|
161
161
|
|
|
162
|
-
const { storageAccountAddress } = useStorageAccount(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
);
|
|
162
|
+
const { storageAccountAddress, signAndSubmitTransaction } = useStorageAccount({
|
|
163
|
+
client: shelbyClient,
|
|
164
|
+
wallet,
|
|
165
|
+
});
|
|
168
166
|
|
|
169
167
|
return (
|
|
170
168
|
<div>
|
|
@@ -174,6 +172,31 @@ function MyComponent() {
|
|
|
174
172
|
}
|
|
175
173
|
```
|
|
176
174
|
|
|
175
|
+
### Using with `@solana/wallet-adapter-react`
|
|
176
|
+
|
|
177
|
+
If you're using the `@solana/wallet-adapter-react` package, you can adapt the wallet to the expected shape:
|
|
178
|
+
|
|
179
|
+
```tsx
|
|
180
|
+
import { useWallet } from "@solana/wallet-adapter-react";
|
|
181
|
+
|
|
182
|
+
function MyComponent() {
|
|
183
|
+
const { publicKey, signMessage, signIn } = useWallet();
|
|
184
|
+
|
|
185
|
+
const { storageAccountAddress } = useStorageAccount({
|
|
186
|
+
client: shelbyClient,
|
|
187
|
+
wallet: publicKey
|
|
188
|
+
? {
|
|
189
|
+
account: { address: publicKey },
|
|
190
|
+
signMessage,
|
|
191
|
+
signIn,
|
|
192
|
+
}
|
|
193
|
+
: null,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// ...
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
177
200
|
## Retrieving a file
|
|
178
201
|
|
|
179
202
|
### Through Shelby Explorer
|
package/dist/react/index.d.ts
CHANGED
|
@@ -8,14 +8,17 @@ declare const Network: {
|
|
|
8
8
|
type Network = (typeof Network)[keyof typeof Network];
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
* Compatible with @solana/
|
|
11
|
+
* Wallet shape from @solana/react-hooks useWalletConnection()
|
|
12
|
+
* Compatible with the modern @solana/kit stack.
|
|
13
13
|
*/
|
|
14
14
|
interface SolanaWallet {
|
|
15
|
-
|
|
15
|
+
account: {
|
|
16
|
+
address: {
|
|
17
|
+
toString(): string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
16
20
|
signMessage?: (message: Uint8Array) => Promise<Uint8Array>;
|
|
17
21
|
signIn?: (input?: SolanaSignInInput) => Promise<SolanaSignInOutput>;
|
|
18
|
-
name?: string;
|
|
19
22
|
}
|
|
20
23
|
type SignTransactionInput = {
|
|
21
24
|
data: InputEntryFunctionData;
|
|
@@ -29,7 +32,7 @@ type SignAndSubmitTransactionInput = {
|
|
|
29
32
|
} & InputTransactionPluginData;
|
|
30
33
|
interface UseStorageAccountParams {
|
|
31
34
|
client: ShelbyClient;
|
|
32
|
-
wallet: SolanaWallet | null;
|
|
35
|
+
wallet: SolanaWallet | null | undefined;
|
|
33
36
|
}
|
|
34
37
|
interface UseStorageAccountResult {
|
|
35
38
|
storageAccountAddress: AccountAddress | null;
|
package/dist/react/index.mjs
CHANGED
|
@@ -23,14 +23,15 @@ import { useMemo } from "react";
|
|
|
23
23
|
function useStorageAccount(params) {
|
|
24
24
|
const { client, wallet } = params;
|
|
25
25
|
const domain = typeof window !== "undefined" ? window.location.host : void 0;
|
|
26
|
+
const publicKey = wallet?.account?.address?.toString() ?? null;
|
|
26
27
|
const derivedPublicKey = useMemo(() => {
|
|
27
|
-
if (!
|
|
28
|
+
if (!publicKey || !domain) return null;
|
|
28
29
|
return new SolanaDerivedPublicKey2({
|
|
29
30
|
domain,
|
|
30
|
-
solanaPublicKey: new PublicKey(
|
|
31
|
+
solanaPublicKey: new PublicKey(publicKey),
|
|
31
32
|
authenticationFunction: defaultAuthenticationFunction3
|
|
32
33
|
});
|
|
33
|
-
}, [
|
|
34
|
+
}, [publicKey, domain]);
|
|
34
35
|
const storageAccountAddress = useMemo(
|
|
35
36
|
() => derivedPublicKey?.authKey().derivedAddress() ?? null,
|
|
36
37
|
[derivedPublicKey]
|
|
@@ -39,25 +40,22 @@ function useStorageAccount(params) {
|
|
|
39
40
|
if (!storageAccountAddress) {
|
|
40
41
|
throw new Error("Storage account address not found");
|
|
41
42
|
}
|
|
42
|
-
if (!
|
|
43
|
+
if (!publicKey) {
|
|
43
44
|
throw new Error("Wallet not connected");
|
|
44
45
|
}
|
|
45
46
|
const rawTransaction = await client.aptos.transaction.build.simple({
|
|
46
47
|
sender: storageAccountAddress,
|
|
47
48
|
data: params2.data
|
|
48
49
|
});
|
|
49
|
-
if (!wallet) {
|
|
50
|
-
throw new Error("Wallet not connected");
|
|
51
|
-
}
|
|
52
50
|
if (!domain) {
|
|
53
51
|
throw new Error("Domain is required in the browser");
|
|
54
52
|
}
|
|
55
53
|
const response = await signAptosTransactionWithSolana({
|
|
56
54
|
solanaWallet: {
|
|
57
|
-
publicKey: new PublicKey(
|
|
58
|
-
signMessage: wallet
|
|
59
|
-
signIn: wallet
|
|
60
|
-
name:
|
|
55
|
+
publicKey: new PublicKey(publicKey),
|
|
56
|
+
signMessage: wallet?.signMessage,
|
|
57
|
+
signIn: wallet?.signIn,
|
|
58
|
+
name: "Solana Wallet"
|
|
61
59
|
},
|
|
62
60
|
authenticationFunction: defaultAuthenticationFunction3,
|
|
63
61
|
rawTransaction,
|