sui-svelte-wallet-kit
Version:
Svelte 5 wallet kit for Sui: connect wallets, manage accounts, SuiNS, balance, sign transactions/messages
73 lines (72 loc) • 2.24 kB
JavaScript
/**
* useMultisig Hook
* Provides access to Multisig store
*/
import { multisigStore } from './MultisigStore.svelte.js';
// Re-export store and types
export { multisigStore };
/**
* Initialize Multisig (called by SuiModule)
*/
export function initializeMultisig(config, providers, network) {
multisigStore.initialize(config, network);
multisigStore.setProviders(providers);
}
/**
* useMultisig hook
* Returns the Multisig store instance for reactive access
*/
export function useMultisig() {
const store = multisigStore;
return {
// State (reactive via $derived in store)
get state() {
return store.state;
},
get address() {
return store.address;
},
get isReady() {
return store.isReady;
},
get signers() {
return store.signers;
},
get mode() {
return store.mode;
},
get threshold() {
return store.threshold;
},
get resolvedCount() {
return store.resolvedCount;
},
get totalWeight() {
return store.totalWeight;
},
// Actions
createProposal: (tx) => store.createProposal(tx),
refreshSigners: async () => store.resolveSigners(),
addSignerFromCurrentWallet: (options) => store.addSignerFromCurrentWallet(options),
addSigner: async (signer) => store.addSigner(signer),
updateSignerWeight: (signerId, weight) => store.updateSignerWeight(signerId, weight),
removeSigner: (signerId) => store.removeSigner(signerId),
setThreshold: (threshold) => store.setThreshold(threshold),
saveConfig: () => store.saveConfig(),
loadConfig: () => {
const config = store.config;
if (config?.storageKey) {
store.loadFromStorage(config.storageKey);
store.resolveSigners();
}
},
clearConfig: () => store.clearConfig()
};
}
// Legacy exports for backward compatibility
export function setMultisigContext() {
// No-op, using global store now
}
export function getMultisigContext() {
return multisigStore.providers ? multisigStore : null;
}