@vela-ventures/aosync-sdk-react 1.0.32 → 1.1.0

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.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  import { useWallet } from "./walletContext";
2
2
  import { AOSyncProvider } from "./walletContext";
3
- export { AOSyncProvider, useWallet };
3
+ import { AOSyncSDKContext as AOSyncTypes } from "./types";
4
+ export { AOSyncProvider, useWallet, AOSyncTypes };
5
+ export type { ChainType, AccountType, MultiChainWallet, TypedDataParams } from "./types";
package/dist/types.d.ts CHANGED
@@ -1,21 +1,35 @@
1
1
  import WalletClient from "@vela-ventures/ao-sync-sdk";
2
+ import type { ChainType, AccountType, MultiChainWallet, TypedDataParams } from "@vela-ventures/ao-sync-sdk";
2
3
  import { DataItem, UserTokensResult } from "arconnect";
3
4
  import Transaction from "arweave/web/lib/transaction";
5
+ export type { ChainType, AccountType, MultiChainWallet, TypedDataParams };
4
6
  export interface AOSyncSDKContext {
5
7
  isConnected: boolean;
6
8
  isSessionActive: boolean;
9
+ activeChain: ChainType | null;
10
+ supportedChains: ChainType[];
11
+ multiChainAddresses: MultiChainWallet | null;
12
+ accountType: AccountType | null;
7
13
  connect: () => Promise<void>;
8
14
  disconnect: () => Promise<void>;
15
+ switchChain: (chain: ChainType) => void;
16
+ getActiveChain: () => ChainType;
17
+ getSupportedChains: () => ChainType[];
18
+ getMultiChainAddresses: () => Promise<MultiChainWallet>;
9
19
  getAllAddresses: () => Promise<string[]>;
10
20
  getAddress: () => Promise<string | undefined>;
11
- sendAR: (recipient: string, quantity: string) => Promise<any>;
21
+ signMessage: (message: string | Uint8Array) => Promise<string>;
22
+ signTransaction: (transaction: any) => Promise<any>;
23
+ sendTransaction: (transaction: any) => Promise<string>;
24
+ signTypedData: (params: TypedDataParams) => Promise<string>;
12
25
  getWalletNames: () => Promise<{
13
26
  [addr: string]: string;
14
27
  }>;
15
28
  getWallets: () => ReturnType<WalletClient['getWallets']>;
16
29
  userTokens: () => Promise<UserTokensResult>;
17
- signAOMessage: (dataItem: DataItem) => Promise<string>;
18
30
  swapActiveWallet: (walletAddress: string) => Promise<string>;
19
31
  getContacts: () => ReturnType<WalletClient['getContacts']>;
32
+ sendAR: (recipient: string, quantity: string) => Promise<any>;
33
+ signAOMessage: (dataItem: DataItem) => Promise<string>;
20
34
  sign: (transaction: Transaction) => Promise<Transaction>;
21
35
  }
@@ -15,7 +15,7 @@ export const AOSyncContext = createContext(undefined);
15
15
  export function AOSyncProvider({ gatewayConfig = { host: "arweave.net", port: 443, protocol: "https" }, muUrl = "https://mu.ao-testnet.xyz", children, appInfo, }) {
16
16
  var _a;
17
17
  const walletRef = useRef(new WalletClient());
18
- const [isConnected, setIsConnected] = useState(!!((_a = walletRef === null || walletRef === void 0 ? void 0 : walletRef.current) === null || _a === void 0 ? void 0 : _a.uid));
18
+ const [isConnected, setIsConnected] = useState(((_a = walletRef === null || walletRef === void 0 ? void 0 : walletRef.current) === null || _a === void 0 ? void 0 : _a.hasActiveSession()) || false);
19
19
  const [isSessionActive, setIsSessionActive] = useState(() => {
20
20
  if (typeof window !== "undefined") {
21
21
  const sessionValue = sessionStorage.getItem("aosync-session-active");
@@ -23,16 +23,48 @@ export function AOSyncProvider({ gatewayConfig = { host: "arweave.net", port: 44
23
23
  }
24
24
  return false;
25
25
  });
26
+ // Multi-chain state
27
+ const [activeChain, setActiveChain] = useState(null);
28
+ const [supportedChains, setSupportedChains] = useState([]);
29
+ const [multiChainAddresses, setMultiChainAddresses] = useState(null);
30
+ const [accountType, setAccountType] = useState(null);
26
31
  useEffect(() => {
27
32
  const wallet = walletRef.current;
28
33
  wallet.reconnect();
29
34
  const handleDisconnect = () => setIsConnected(false);
30
- const handleConnect = () => setIsConnected(true);
35
+ const handleConnect = () => {
36
+ setIsConnected(true);
37
+ // Initialize chain state on connection
38
+ try {
39
+ setAccountType(wallet.getAccountType());
40
+ setSupportedChains(wallet.getSupportedChains());
41
+ setActiveChain(wallet.getActiveChain());
42
+ }
43
+ catch (error) {
44
+ console.error("Error initializing chain state:", error);
45
+ }
46
+ };
47
+ const handleChainChanged = (data) => {
48
+ setActiveChain(data.currentChain);
49
+ };
31
50
  wallet.on("disconnected", handleDisconnect);
32
51
  wallet.on("connected", handleConnect);
52
+ wallet.on("chainChanged", handleChainChanged);
53
+ // Initialize chain state if already connected
54
+ if (wallet.hasActiveSession()) {
55
+ try {
56
+ setAccountType(wallet.getAccountType());
57
+ setSupportedChains(wallet.getSupportedChains());
58
+ setActiveChain(wallet.getActiveChain());
59
+ }
60
+ catch (error) {
61
+ console.error("Error initializing chain state:", error);
62
+ }
63
+ }
33
64
  return () => {
34
65
  wallet.off("disconnected", handleDisconnect);
35
66
  wallet.off("connected", handleConnect);
67
+ wallet.off("chainChanged", handleChainChanged);
36
68
  };
37
69
  }, []);
38
70
  useEffect(() => {
@@ -49,6 +81,7 @@ export function AOSyncProvider({ gatewayConfig = { host: "arweave.net", port: 44
49
81
  yield walletRef.current.connect({
50
82
  gateway: gatewayConfig,
51
83
  appInfo,
84
+ accountType: "multichain",
52
85
  });
53
86
  }
54
87
  catch (error) {
@@ -187,20 +220,116 @@ export function AOSyncProvider({ gatewayConfig = { host: "arweave.net", port: 44
187
220
  throw error;
188
221
  }
189
222
  });
223
+ // Multi-chain methods
224
+ const switchChain = (chain) => {
225
+ try {
226
+ walletRef.current.switchChain(chain);
227
+ }
228
+ catch (error) {
229
+ console.error("Error switching chain:", error);
230
+ throw error;
231
+ }
232
+ };
233
+ const getActiveChain = () => {
234
+ try {
235
+ return walletRef.current.getActiveChain();
236
+ }
237
+ catch (error) {
238
+ console.error("Error getting active chain:", error);
239
+ throw error;
240
+ }
241
+ };
242
+ const getSupportedChains = () => {
243
+ try {
244
+ return walletRef.current.getSupportedChains();
245
+ }
246
+ catch (error) {
247
+ console.error("Error getting supported chains:", error);
248
+ throw error;
249
+ }
250
+ };
251
+ const getMultiChainAddresses = () => __awaiter(this, void 0, void 0, function* () {
252
+ try {
253
+ const addresses = yield walletRef.current.getMultiChainAddresses();
254
+ setMultiChainAddresses(addresses);
255
+ return addresses;
256
+ }
257
+ catch (error) {
258
+ console.error("Error getting multi-chain addresses:", error);
259
+ throw error;
260
+ }
261
+ });
262
+ // Universal signing methods
263
+ const signMessage = (message) => __awaiter(this, void 0, void 0, function* () {
264
+ try {
265
+ return yield walletRef.current.signMessage(message);
266
+ }
267
+ catch (error) {
268
+ console.error("Error signing message:", error);
269
+ throw error;
270
+ }
271
+ });
272
+ const signTransaction = (transaction) => __awaiter(this, void 0, void 0, function* () {
273
+ try {
274
+ return yield walletRef.current.signTransaction(transaction);
275
+ }
276
+ catch (error) {
277
+ console.error("Error signing transaction:", error);
278
+ throw error;
279
+ }
280
+ });
281
+ const sendTransaction = (transaction) => __awaiter(this, void 0, void 0, function* () {
282
+ try {
283
+ return yield walletRef.current.sendTransaction(transaction);
284
+ }
285
+ catch (error) {
286
+ console.error("Error sending transaction:", error);
287
+ throw error;
288
+ }
289
+ });
290
+ const signTypedData = (params) => __awaiter(this, void 0, void 0, function* () {
291
+ try {
292
+ return yield walletRef.current.signTypedData(params);
293
+ }
294
+ catch (error) {
295
+ console.error("Error signing typed data:", error);
296
+ throw error;
297
+ }
298
+ });
190
299
  return (React.createElement(AOSyncContext.Provider, { value: {
300
+ // Connection state
191
301
  isConnected,
192
302
  isSessionActive,
303
+ // Multi-chain state
304
+ activeChain,
305
+ supportedChains,
306
+ multiChainAddresses,
307
+ accountType,
308
+ // Connection methods
193
309
  connect,
194
310
  disconnect,
311
+ // Chain management
312
+ switchChain,
313
+ getActiveChain,
314
+ getSupportedChains,
315
+ getMultiChainAddresses,
316
+ // Address methods
195
317
  getAddress,
196
318
  getAllAddresses,
319
+ // Universal signing methods
320
+ signMessage,
321
+ signTransaction,
322
+ sendTransaction,
323
+ signTypedData,
324
+ // Wallet management
197
325
  getWalletNames,
198
326
  getWallets,
199
327
  userTokens,
200
- sendAR,
201
- signAOMessage,
202
328
  swapActiveWallet,
203
329
  getContacts,
330
+ // Legacy Arweave methods
331
+ sendAR,
332
+ signAOMessage,
204
333
  sign,
205
334
  } }, children));
206
335
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vela-ventures/aosync-sdk-react",
3
- "version": "1.0.32",
3
+ "version": "1.1.0",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist"
@@ -65,6 +65,6 @@
65
65
  "react": "^17.0.0 || ^18.0.0 || ^19.0.0"
66
66
  },
67
67
  "dependencies": {
68
- "@vela-ventures/ao-sync-sdk": "^1.1.32"
68
+ "@vela-ventures/ao-sync-sdk": "^1.2.0"
69
69
  }
70
70
  }