@iota/dapp-kit 0.5.3 → 0.8.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/CHANGELOG.md +52 -0
- package/dist/cjs/components/AccountDropdownMenu.d.ts +4 -2
- package/dist/cjs/components/AccountDropdownMenu.js +81 -15
- package/dist/cjs/components/AccountDropdownMenu.js.map +4 -4
- package/dist/cjs/components/ConnectButton.d.ts +6 -1
- package/dist/cjs/components/ConnectButton.js +177 -91
- package/dist/cjs/components/ConnectButton.js.map +4 -4
- package/dist/cjs/components/WalletProvider.d.ts +3 -1
- package/dist/cjs/components/WalletProvider.js +9 -3
- package/dist/cjs/components/WalletProvider.js.map +2 -2
- package/dist/cjs/components/connect-modal/ConnectModal.d.ts +5 -1
- package/dist/cjs/components/connect-modal/ConnectModal.js +12 -2
- package/dist/cjs/components/connect-modal/ConnectModal.js.map +2 -2
- package/dist/cjs/hooks/useGetDefaultIotaName.d.ts +1 -0
- package/dist/cjs/hooks/useGetDefaultIotaName.js +80 -0
- package/dist/cjs/hooks/useGetDefaultIotaName.js.map +7 -0
- package/dist/cjs/hooks/wallet/useAutoConnectWallet.js +2 -0
- package/dist/cjs/hooks/wallet/useAutoConnectWallet.js.map +2 -2
- package/dist/cjs/hooks/wallet/useConnectWallet.d.ts +6 -2
- package/dist/cjs/hooks/wallet/useConnectWallet.js +2 -0
- package/dist/cjs/hooks/wallet/useConnectWallet.js.map +2 -2
- package/dist/cjs/hooks/wallet/useCurrentChain.d.ts +5 -0
- package/dist/cjs/hooks/wallet/useCurrentChain.js +50 -0
- package/dist/cjs/hooks/wallet/useCurrentChain.js.map +7 -0
- package/dist/cjs/hooks/wallet/useSignAndExecuteTransaction.js +8 -2
- package/dist/cjs/hooks/wallet/useSignAndExecuteTransaction.js.map +3 -3
- package/dist/cjs/index.js +193 -120
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/walletStore.d.ts +4 -1
- package/dist/cjs/walletStore.js +3 -1
- package/dist/cjs/walletStore.js.map +2 -2
- package/dist/esm/components/AccountDropdownMenu.d.ts +4 -2
- package/dist/esm/components/AccountDropdownMenu.js +79 -13
- package/dist/esm/components/AccountDropdownMenu.js.map +4 -4
- package/dist/esm/components/ConnectButton.d.ts +6 -1
- package/dist/esm/components/ConnectButton.js +159 -73
- package/dist/esm/components/ConnectButton.js.map +4 -4
- package/dist/esm/components/WalletProvider.d.ts +3 -1
- package/dist/esm/components/WalletProvider.js +9 -3
- package/dist/esm/components/WalletProvider.js.map +2 -2
- package/dist/esm/components/connect-modal/ConnectModal.d.ts +5 -1
- package/dist/esm/components/connect-modal/ConnectModal.js +12 -2
- package/dist/esm/components/connect-modal/ConnectModal.js.map +2 -2
- package/dist/esm/hooks/useGetDefaultIotaName.d.ts +1 -0
- package/dist/esm/hooks/useGetDefaultIotaName.js +59 -0
- package/dist/esm/hooks/useGetDefaultIotaName.js.map +7 -0
- package/dist/esm/hooks/wallet/useAutoConnectWallet.js +2 -0
- package/dist/esm/hooks/wallet/useAutoConnectWallet.js.map +2 -2
- package/dist/esm/hooks/wallet/useConnectWallet.d.ts +6 -2
- package/dist/esm/hooks/wallet/useConnectWallet.js +2 -0
- package/dist/esm/hooks/wallet/useConnectWallet.js.map +2 -2
- package/dist/esm/hooks/wallet/useCurrentChain.d.ts +5 -0
- package/dist/esm/hooks/wallet/useCurrentChain.js +27 -0
- package/dist/esm/hooks/wallet/useCurrentChain.js.map +7 -0
- package/dist/esm/hooks/wallet/useSignAndExecuteTransaction.js +8 -2
- package/dist/esm/hooks/wallet/useSignAndExecuteTransaction.js.map +3 -3
- package/dist/esm/index.js +164 -91
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/walletStore.d.ts +4 -1
- package/dist/esm/walletStore.js +3 -1
- package/dist/esm/walletStore.js.map +2 -2
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -3
- package/src/components/AccountDropdownMenu.tsx +17 -3
- package/src/components/ConnectButton.tsx +11 -1
- package/src/components/WalletProvider.tsx +5 -0
- package/src/components/connect-modal/ConnectModal.tsx +12 -2
- package/src/hooks/useGetDefaultIotaName.ts +43 -0
- package/src/hooks/wallet/useConnectWallet.ts +6 -1
- package/src/hooks/wallet/useCurrentChain.ts +12 -0
- package/src/hooks/wallet/useSignAndExecuteTransaction.ts +5 -2
- package/src/walletStore.ts +5 -0
package/dist/cjs/index.js
CHANGED
|
@@ -135,6 +135,7 @@ function useWalletStore(selector) {
|
|
|
135
135
|
|
|
136
136
|
// src/hooks/wallet/useConnectWallet.ts
|
|
137
137
|
function useConnectWallet({
|
|
138
|
+
onConnected,
|
|
138
139
|
mutationKey,
|
|
139
140
|
...mutationOptions
|
|
140
141
|
} = {}) {
|
|
@@ -156,6 +157,7 @@ function useConnectWallet({
|
|
|
156
157
|
selectedAccount,
|
|
157
158
|
connectResult.supportedIntents
|
|
158
159
|
);
|
|
160
|
+
onConnected?.({ wallet });
|
|
159
161
|
return { accounts: connectedIotaAccounts };
|
|
160
162
|
} catch (error) {
|
|
161
163
|
setConnectionStatus("disconnected");
|
|
@@ -543,11 +545,19 @@ function WalletList({ selectedWalletName, onPlaceholderClick, onSelect }) {
|
|
|
543
545
|
|
|
544
546
|
// src/components/connect-modal/ConnectModal.tsx
|
|
545
547
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
546
|
-
function ConnectModal({
|
|
548
|
+
function ConnectModal({
|
|
549
|
+
trigger,
|
|
550
|
+
open,
|
|
551
|
+
defaultOpen,
|
|
552
|
+
onOpenChange,
|
|
553
|
+
onConnected
|
|
554
|
+
}) {
|
|
547
555
|
const [isModalOpen, setModalOpen] = (0, import_react8.useState)(open ?? defaultOpen);
|
|
548
556
|
const [currentView, setCurrentView] = (0, import_react8.useState)();
|
|
549
557
|
const [selectedWallet, setSelectedWallet] = (0, import_react8.useState)();
|
|
550
|
-
const { mutate, isError } = useConnectWallet(
|
|
558
|
+
const { mutate, isError } = useConnectWallet({
|
|
559
|
+
onConnected
|
|
560
|
+
});
|
|
551
561
|
const resetSelection = () => {
|
|
552
562
|
setSelectedWallet(void 0);
|
|
553
563
|
setCurrentView(void 0);
|
|
@@ -810,27 +820,129 @@ function ChevronIcon(props) {
|
|
|
810
820
|
) });
|
|
811
821
|
}
|
|
812
822
|
|
|
813
|
-
// src/
|
|
823
|
+
// src/hooks/useGetDefaultIotaName.ts
|
|
824
|
+
var import_client2 = require("@iota/iota-sdk/client");
|
|
825
|
+
var import_react_query4 = require("@tanstack/react-query");
|
|
826
|
+
var import_iota_names_sdk = require("@iota/iota-names-sdk");
|
|
827
|
+
|
|
828
|
+
// src/hooks/useIotaClient.ts
|
|
829
|
+
var import_react10 = require("react");
|
|
830
|
+
|
|
831
|
+
// src/components/IotaClientProvider.tsx
|
|
832
|
+
var import_client = require("@iota/iota-sdk/client");
|
|
833
|
+
var import_react9 = require("react");
|
|
814
834
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
815
|
-
|
|
835
|
+
var IotaClientContext = (0, import_react9.createContext)(null);
|
|
836
|
+
var DEFAULT_NETWORKS = {
|
|
837
|
+
localnet: { url: (0, import_client.getNetwork)(import_client.Network.Localnet)?.url }
|
|
838
|
+
};
|
|
839
|
+
var DEFAULT_CREATE_CLIENT = function createClient(_name, config) {
|
|
840
|
+
if ((0, import_client.isIotaClient)(config)) {
|
|
841
|
+
return config;
|
|
842
|
+
}
|
|
843
|
+
return new import_client.IotaClient(config);
|
|
844
|
+
};
|
|
845
|
+
function IotaClientProvider(props) {
|
|
846
|
+
const { onNetworkChange, network, children } = props;
|
|
847
|
+
const networks = props.networks ?? DEFAULT_NETWORKS;
|
|
848
|
+
const createClient2 = props.createClient ?? DEFAULT_CREATE_CLIENT;
|
|
849
|
+
const [selectedNetwork, setSelectedNetwork] = (0, import_react9.useState)(
|
|
850
|
+
props.network ?? props.defaultNetwork ?? Object.keys(networks)[0]
|
|
851
|
+
);
|
|
852
|
+
const currentNetwork = props.network ?? selectedNetwork;
|
|
853
|
+
const client = (0, import_react9.useMemo)(() => {
|
|
854
|
+
return createClient2(currentNetwork, networks[currentNetwork]);
|
|
855
|
+
}, [createClient2, currentNetwork, networks]);
|
|
856
|
+
const ctx = (0, import_react9.useMemo)(() => {
|
|
857
|
+
return {
|
|
858
|
+
client,
|
|
859
|
+
networks,
|
|
860
|
+
network: currentNetwork,
|
|
861
|
+
config: networks[currentNetwork] instanceof import_client.IotaClient ? null : networks[currentNetwork],
|
|
862
|
+
selectNetwork: (newNetwork) => {
|
|
863
|
+
if (currentNetwork === newNetwork) {
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
if (!network && newNetwork !== selectedNetwork) {
|
|
867
|
+
setSelectedNetwork(newNetwork);
|
|
868
|
+
}
|
|
869
|
+
onNetworkChange?.(newNetwork);
|
|
870
|
+
}
|
|
871
|
+
};
|
|
872
|
+
}, [client, networks, selectedNetwork, currentNetwork, network, onNetworkChange]);
|
|
873
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(IotaClientContext.Provider, { value: ctx, children });
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
// src/hooks/useIotaClient.ts
|
|
877
|
+
function useIotaClientContext() {
|
|
878
|
+
const iotaClient = (0, import_react10.useContext)(IotaClientContext);
|
|
879
|
+
if (!iotaClient) {
|
|
880
|
+
throw new Error(
|
|
881
|
+
"Could not find IotaClientContext. Ensure that you have set up the IotaClientProvider"
|
|
882
|
+
);
|
|
883
|
+
}
|
|
884
|
+
return iotaClient;
|
|
885
|
+
}
|
|
886
|
+
function useIotaClient() {
|
|
887
|
+
return useIotaClientContext().client;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
// src/hooks/useGetDefaultIotaName.ts
|
|
891
|
+
var import_react11 = require("react");
|
|
892
|
+
var import_graphql = require("@iota/iota-sdk/graphql");
|
|
893
|
+
function useGetDefaultIotaName(address, iotaNamesEnabled) {
|
|
894
|
+
const iotaContext = useIotaClientContext();
|
|
895
|
+
const network = (0, import_client2.getNetwork)(iotaContext.network);
|
|
896
|
+
const iotaNamesClient = (0, import_react11.useMemo)(() => {
|
|
897
|
+
const iotaGraphQLClient = new import_graphql.IotaGraphQLClient({
|
|
898
|
+
url: network.graphql
|
|
899
|
+
});
|
|
900
|
+
return new import_iota_names_sdk.IotaNamesClient({
|
|
901
|
+
graphQlClient: iotaGraphQLClient,
|
|
902
|
+
network: network.id
|
|
903
|
+
});
|
|
904
|
+
}, [network.id]);
|
|
905
|
+
const iotaNamesSupported = !!iotaNamesClient.config;
|
|
906
|
+
return (0, import_react_query4.useQuery)({
|
|
907
|
+
queryKey: ["iota-name", "default-name", address],
|
|
908
|
+
queryFn: async () => {
|
|
909
|
+
if (!address) return null;
|
|
910
|
+
const name = await iotaNamesClient?.getDefaultName(address);
|
|
911
|
+
return name ? (0, import_iota_names_sdk.normalizeIotaName)(name) : name;
|
|
912
|
+
},
|
|
913
|
+
enabled: !!iotaNamesClient && !!address && iotaNamesEnabled && iotaNamesSupported,
|
|
914
|
+
staleTime: 1e3 * 60 * 10
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
// src/components/AccountDropdownMenu.tsx
|
|
919
|
+
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
920
|
+
function AccountDropdownMenu({
|
|
921
|
+
currentAccount,
|
|
922
|
+
size = "lg",
|
|
923
|
+
iotaNamesEnabled
|
|
924
|
+
}) {
|
|
816
925
|
const { mutate: disconnectWallet } = useDisconnectWallet();
|
|
817
926
|
const accounts = useAccounts();
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
927
|
+
const { data: iotaName } = useGetDefaultIotaName(currentAccount.address, iotaNamesEnabled);
|
|
928
|
+
const displayAccount = iotaName ?? currentAccount.label ?? (0, import_utils.formatAddress)(currentAccount.address);
|
|
929
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(DropdownMenu.Root, { modal: false, children: [
|
|
930
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(StyleMarker, { children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(Button, { size, className: connectedAccount, children: [
|
|
931
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Text, { mono: true, weight: "bold", children: displayAccount }),
|
|
932
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(ChevronIcon, {})
|
|
822
933
|
] }) }) }),
|
|
823
|
-
/* @__PURE__ */ (0,
|
|
824
|
-
/* @__PURE__ */ (0,
|
|
934
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(DropdownMenu.Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(StyleMarker, { className: menuContainer, children: /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(DropdownMenu.Content, { className: menuContent, children: [
|
|
935
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: scrollableContent, children: accounts.map((account) => /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
825
936
|
AccountDropdownMenuItem,
|
|
826
937
|
{
|
|
827
938
|
account,
|
|
828
|
-
active: currentAccount.address === account.address
|
|
939
|
+
active: currentAccount.address === account.address,
|
|
940
|
+
iotaNamesEnabled
|
|
829
941
|
},
|
|
830
942
|
account.address
|
|
831
943
|
)) }),
|
|
832
|
-
/* @__PURE__ */ (0,
|
|
833
|
-
/* @__PURE__ */ (0,
|
|
944
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(DropdownMenu.Separator, { className: separator }),
|
|
945
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
834
946
|
DropdownMenu.Item,
|
|
835
947
|
{
|
|
836
948
|
className: (0, import_clsx7.default)(menuItem),
|
|
@@ -843,85 +955,53 @@ function AccountDropdownMenu({ currentAccount, size = "lg" }) {
|
|
|
843
955
|
}
|
|
844
956
|
function AccountDropdownMenuItem({
|
|
845
957
|
account,
|
|
846
|
-
active
|
|
958
|
+
active,
|
|
959
|
+
iotaNamesEnabled
|
|
847
960
|
}) {
|
|
848
961
|
const { mutate: switchAccount } = useSwitchAccount();
|
|
849
|
-
|
|
962
|
+
const { data: iotaName } = useGetDefaultIotaName(account.address, iotaNamesEnabled);
|
|
963
|
+
const displayAccount = iotaName ?? account.label ?? (0, import_utils.formatAddress)(account.address);
|
|
964
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
|
|
850
965
|
DropdownMenu.Item,
|
|
851
966
|
{
|
|
852
967
|
className: (0, import_clsx7.default)(menuItem, switchAccountMenuItem),
|
|
853
968
|
onSelect: () => switchAccount({ account }),
|
|
854
969
|
children: [
|
|
855
|
-
/* @__PURE__ */ (0,
|
|
856
|
-
active ? /* @__PURE__ */ (0,
|
|
970
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Text, { mono: true, children: displayAccount }),
|
|
971
|
+
active ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(CheckIcon, {}) : null
|
|
857
972
|
]
|
|
858
973
|
}
|
|
859
974
|
);
|
|
860
975
|
}
|
|
861
976
|
|
|
862
977
|
// src/components/ConnectButton.tsx
|
|
863
|
-
var
|
|
978
|
+
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
864
979
|
function ConnectButton({
|
|
865
980
|
connectText = "Connect Wallet",
|
|
866
981
|
size,
|
|
982
|
+
iotaNamesEnabled = true,
|
|
983
|
+
onConnected,
|
|
867
984
|
...buttonProps
|
|
868
985
|
}) {
|
|
869
986
|
const currentAccount = useCurrentAccount();
|
|
870
|
-
return currentAccount ? /* @__PURE__ */ (0,
|
|
987
|
+
return currentAccount ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
988
|
+
AccountDropdownMenu,
|
|
989
|
+
{
|
|
990
|
+
currentAccount,
|
|
991
|
+
size,
|
|
992
|
+
iotaNamesEnabled
|
|
993
|
+
}
|
|
994
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
871
995
|
ConnectModal,
|
|
872
996
|
{
|
|
873
|
-
|
|
997
|
+
onConnected,
|
|
998
|
+
trigger: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(StyleMarker, { children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Button, { ...buttonProps, size, children: connectText }) })
|
|
874
999
|
}
|
|
875
1000
|
);
|
|
876
1001
|
}
|
|
877
1002
|
|
|
878
|
-
// src/components/IotaClientProvider.tsx
|
|
879
|
-
var import_client = require("@iota/iota-sdk/client");
|
|
880
|
-
var import_react9 = require("react");
|
|
881
|
-
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
882
|
-
var IotaClientContext = (0, import_react9.createContext)(null);
|
|
883
|
-
var DEFAULT_NETWORKS = {
|
|
884
|
-
localnet: { url: (0, import_client.getNetwork)(import_client.Network.Localnet)?.url }
|
|
885
|
-
};
|
|
886
|
-
var DEFAULT_CREATE_CLIENT = function createClient(_name, config) {
|
|
887
|
-
if ((0, import_client.isIotaClient)(config)) {
|
|
888
|
-
return config;
|
|
889
|
-
}
|
|
890
|
-
return new import_client.IotaClient(config);
|
|
891
|
-
};
|
|
892
|
-
function IotaClientProvider(props) {
|
|
893
|
-
const { onNetworkChange, network, children } = props;
|
|
894
|
-
const networks = props.networks ?? DEFAULT_NETWORKS;
|
|
895
|
-
const createClient2 = props.createClient ?? DEFAULT_CREATE_CLIENT;
|
|
896
|
-
const [selectedNetwork, setSelectedNetwork] = (0, import_react9.useState)(
|
|
897
|
-
props.network ?? props.defaultNetwork ?? Object.keys(networks)[0]
|
|
898
|
-
);
|
|
899
|
-
const currentNetwork = props.network ?? selectedNetwork;
|
|
900
|
-
const client = (0, import_react9.useMemo)(() => {
|
|
901
|
-
return createClient2(currentNetwork, networks[currentNetwork]);
|
|
902
|
-
}, [createClient2, currentNetwork, networks]);
|
|
903
|
-
const ctx = (0, import_react9.useMemo)(() => {
|
|
904
|
-
return {
|
|
905
|
-
client,
|
|
906
|
-
networks,
|
|
907
|
-
network: currentNetwork,
|
|
908
|
-
config: networks[currentNetwork] instanceof import_client.IotaClient ? null : networks[currentNetwork],
|
|
909
|
-
selectNetwork: (newNetwork) => {
|
|
910
|
-
if (currentNetwork === newNetwork) {
|
|
911
|
-
return;
|
|
912
|
-
}
|
|
913
|
-
if (!network && newNetwork !== selectedNetwork) {
|
|
914
|
-
setSelectedNetwork(newNetwork);
|
|
915
|
-
}
|
|
916
|
-
onNetworkChange?.(newNetwork);
|
|
917
|
-
}
|
|
918
|
-
};
|
|
919
|
-
}, [client, networks, selectedNetwork, currentNetwork, network, onNetworkChange]);
|
|
920
|
-
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(IotaClientContext.Provider, { value: ctx, children });
|
|
921
|
-
}
|
|
922
|
-
|
|
923
1003
|
// src/components/WalletProvider.tsx
|
|
924
|
-
var
|
|
1004
|
+
var import_react16 = require("react");
|
|
925
1005
|
|
|
926
1006
|
// src/utils/stateStorage.ts
|
|
927
1007
|
function createInMemoryStore() {
|
|
@@ -950,8 +1030,8 @@ var WALLET_CHROME_EXTENSION_ID = "iidjkmdceolghepehaaddojmnjnkkija";
|
|
|
950
1030
|
var WALLET_DOWNLOAD_URL = "https://chromewebstore.google.com/detail/" + WALLET_CHROME_EXTENSION_ID;
|
|
951
1031
|
|
|
952
1032
|
// src/hooks/wallet/useAutoConnectWallet.ts
|
|
953
|
-
var
|
|
954
|
-
var
|
|
1033
|
+
var import_react_query5 = require("@tanstack/react-query");
|
|
1034
|
+
var import_react12 = require("react");
|
|
955
1035
|
function useAutoConnectWallet() {
|
|
956
1036
|
const { mutateAsync: connectWallet } = useConnectWallet();
|
|
957
1037
|
const autoConnectEnabled = useWalletStore((state) => state.autoConnectEnabled);
|
|
@@ -961,11 +1041,11 @@ function useAutoConnectWallet() {
|
|
|
961
1041
|
);
|
|
962
1042
|
const wallets = useWallets();
|
|
963
1043
|
const { isConnected } = useCurrentWallet();
|
|
964
|
-
const [clientOnly, setClientOnly] = (0,
|
|
965
|
-
(0,
|
|
1044
|
+
const [clientOnly, setClientOnly] = (0, import_react12.useState)(false);
|
|
1045
|
+
(0, import_react12.useLayoutEffect)(() => {
|
|
966
1046
|
setClientOnly(true);
|
|
967
1047
|
}, []);
|
|
968
|
-
const { data, isError } = (0,
|
|
1048
|
+
const { data, isError } = (0, import_react_query5.useQuery)({
|
|
969
1049
|
queryKey: [
|
|
970
1050
|
"@iota/dapp-kit",
|
|
971
1051
|
"autoconnect",
|
|
@@ -1029,28 +1109,11 @@ var import_ed25519 = require("@iota/iota-sdk/keypairs/ed25519");
|
|
|
1029
1109
|
var import_transactions = require("@iota/iota-sdk/transactions");
|
|
1030
1110
|
var import_utils2 = require("@iota/iota-sdk/utils");
|
|
1031
1111
|
var import_wallet_standard3 = require("@iota/wallet-standard");
|
|
1032
|
-
var
|
|
1033
|
-
|
|
1034
|
-
// src/hooks/useIotaClient.ts
|
|
1035
|
-
var import_react11 = require("react");
|
|
1036
|
-
function useIotaClientContext() {
|
|
1037
|
-
const iotaClient = (0, import_react11.useContext)(IotaClientContext);
|
|
1038
|
-
if (!iotaClient) {
|
|
1039
|
-
throw new Error(
|
|
1040
|
-
"Could not find IotaClientContext. Ensure that you have set up the IotaClientProvider"
|
|
1041
|
-
);
|
|
1042
|
-
}
|
|
1043
|
-
return iotaClient;
|
|
1044
|
-
}
|
|
1045
|
-
function useIotaClient() {
|
|
1046
|
-
return useIotaClientContext().client;
|
|
1047
|
-
}
|
|
1048
|
-
|
|
1049
|
-
// src/hooks/wallet/useUnsafeBurnerWallet.ts
|
|
1112
|
+
var import_react13 = require("react");
|
|
1050
1113
|
var WALLET_NAME = "Unsafe Burner Wallet";
|
|
1051
1114
|
function useUnsafeBurnerWallet(enabled) {
|
|
1052
1115
|
const iotaClient = useIotaClient();
|
|
1053
|
-
(0,
|
|
1116
|
+
(0, import_react13.useEffect)(() => {
|
|
1054
1117
|
if (!enabled) {
|
|
1055
1118
|
return;
|
|
1056
1119
|
}
|
|
@@ -1177,11 +1240,11 @@ function registerUnsafeBurnerWallet(iotaClient) {
|
|
|
1177
1240
|
}
|
|
1178
1241
|
|
|
1179
1242
|
// src/hooks/wallet/useWalletPropertiesChanged.ts
|
|
1180
|
-
var
|
|
1243
|
+
var import_react14 = require("react");
|
|
1181
1244
|
function useWalletPropertiesChanged() {
|
|
1182
1245
|
const { currentWallet } = useCurrentWallet();
|
|
1183
1246
|
const updateWalletAccounts = useWalletStore((state) => state.updateWalletAccounts);
|
|
1184
|
-
(0,
|
|
1247
|
+
(0, import_react14.useEffect)(() => {
|
|
1185
1248
|
const unsubscribeFromEvents = currentWallet?.features["standard:events"].on(
|
|
1186
1249
|
"change",
|
|
1187
1250
|
({ accounts }) => {
|
|
@@ -1196,11 +1259,11 @@ function useWalletPropertiesChanged() {
|
|
|
1196
1259
|
|
|
1197
1260
|
// src/hooks/wallet/useWalletsChanged.ts
|
|
1198
1261
|
var import_wallet_standard4 = require("@iota/wallet-standard");
|
|
1199
|
-
var
|
|
1262
|
+
var import_react15 = require("react");
|
|
1200
1263
|
function useWalletsChanged(preferredWallets, walletFilter) {
|
|
1201
1264
|
const setWalletRegistered = useWalletStore((state) => state.setWalletRegistered);
|
|
1202
1265
|
const setWalletUnregistered = useWalletStore((state) => state.setWalletUnregistered);
|
|
1203
|
-
(0,
|
|
1266
|
+
(0, import_react15.useEffect)(() => {
|
|
1204
1267
|
const walletsApi = (0, import_wallet_standard4.getWallets)();
|
|
1205
1268
|
setWalletRegistered(getRegisteredWallets(preferredWallets, walletFilter));
|
|
1206
1269
|
const unsubscribeFromRegister = walletsApi.on("register", () => {
|
|
@@ -1290,7 +1353,8 @@ function createWalletStore({
|
|
|
1290
1353
|
wallets,
|
|
1291
1354
|
storage,
|
|
1292
1355
|
storageKey,
|
|
1293
|
-
autoConnectEnabled
|
|
1356
|
+
autoConnectEnabled,
|
|
1357
|
+
chain
|
|
1294
1358
|
}) {
|
|
1295
1359
|
return (0, import_zustand2.createStore)()(
|
|
1296
1360
|
(0, import_middleware.persist)(
|
|
@@ -1304,6 +1368,7 @@ function createWalletStore({
|
|
|
1304
1368
|
lastConnectedWalletName: null,
|
|
1305
1369
|
connectionStatus: "disconnected",
|
|
1306
1370
|
supportedIntents: [],
|
|
1371
|
+
chain,
|
|
1307
1372
|
setConnectionStatus(connectionStatus2) {
|
|
1308
1373
|
set(() => ({
|
|
1309
1374
|
connectionStatus: connectionStatus2
|
|
@@ -1489,14 +1554,16 @@ function WalletProvider({
|
|
|
1489
1554
|
enableUnsafeBurner = false,
|
|
1490
1555
|
autoConnect = false,
|
|
1491
1556
|
theme = lightTheme,
|
|
1492
|
-
children
|
|
1557
|
+
children,
|
|
1558
|
+
chain
|
|
1493
1559
|
}) {
|
|
1494
|
-
const storeRef = (0,
|
|
1560
|
+
const storeRef = (0, import_react16.useRef)(
|
|
1495
1561
|
createWalletStore({
|
|
1496
1562
|
autoConnectEnabled: autoConnect,
|
|
1497
1563
|
wallets: getRegisteredWallets(preferredWallets, walletFilter),
|
|
1498
1564
|
storage: storage || createInMemoryStore(),
|
|
1499
|
-
storageKey
|
|
1565
|
+
storageKey,
|
|
1566
|
+
chain
|
|
1500
1567
|
})
|
|
1501
1568
|
);
|
|
1502
1569
|
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(WalletContext.Provider, { value: storeRef.current, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(
|
|
@@ -1551,14 +1618,14 @@ function createNetworkConfig(networkConfig) {
|
|
|
1551
1618
|
}
|
|
1552
1619
|
|
|
1553
1620
|
// src/hooks/useIotaClientInfiniteQuery.ts
|
|
1554
|
-
var
|
|
1621
|
+
var import_react_query6 = require("@tanstack/react-query");
|
|
1555
1622
|
function useIotaClientInfiniteQuery(method, params, {
|
|
1556
1623
|
queryKey = [],
|
|
1557
1624
|
enabled = !!params,
|
|
1558
1625
|
...options
|
|
1559
1626
|
} = {}) {
|
|
1560
1627
|
const iotaContext = useIotaClientContext();
|
|
1561
|
-
return (0,
|
|
1628
|
+
return (0, import_react_query6.useInfiniteQuery)({
|
|
1562
1629
|
...options,
|
|
1563
1630
|
initialPageParam: null,
|
|
1564
1631
|
queryKey: [iotaContext.network, method, params, ...queryKey],
|
|
@@ -1572,10 +1639,10 @@ function useIotaClientInfiniteQuery(method, params, {
|
|
|
1572
1639
|
}
|
|
1573
1640
|
|
|
1574
1641
|
// src/hooks/useIotaClientMutation.ts
|
|
1575
|
-
var
|
|
1642
|
+
var import_react_query7 = require("@tanstack/react-query");
|
|
1576
1643
|
function useIotaClientMutation(method, options = {}) {
|
|
1577
1644
|
const iotaContext = useIotaClientContext();
|
|
1578
|
-
return (0,
|
|
1645
|
+
return (0, import_react_query7.useMutation)({
|
|
1579
1646
|
...options,
|
|
1580
1647
|
mutationFn: async (params) => {
|
|
1581
1648
|
return await iotaContext.client[method](params);
|
|
@@ -1584,8 +1651,8 @@ function useIotaClientMutation(method, options = {}) {
|
|
|
1584
1651
|
}
|
|
1585
1652
|
|
|
1586
1653
|
// src/hooks/useIotaClientQuery.ts
|
|
1587
|
-
var
|
|
1588
|
-
var
|
|
1654
|
+
var import_react_query8 = require("@tanstack/react-query");
|
|
1655
|
+
var import_react17 = require("react");
|
|
1589
1656
|
function getIotaClientQuery({
|
|
1590
1657
|
client,
|
|
1591
1658
|
network,
|
|
@@ -1593,7 +1660,7 @@ function getIotaClientQuery({
|
|
|
1593
1660
|
params,
|
|
1594
1661
|
options
|
|
1595
1662
|
}) {
|
|
1596
|
-
return (0,
|
|
1663
|
+
return (0, import_react_query8.queryOptions)({
|
|
1597
1664
|
...options,
|
|
1598
1665
|
queryKey: [network, method, params],
|
|
1599
1666
|
queryFn: async () => {
|
|
@@ -1604,7 +1671,7 @@ function getIotaClientQuery({
|
|
|
1604
1671
|
function useIotaClientQuery(...args) {
|
|
1605
1672
|
const [method, params, { queryKey = [], ...options } = {}] = args;
|
|
1606
1673
|
const iotaContext = useIotaClientContext();
|
|
1607
|
-
return (0,
|
|
1674
|
+
return (0, import_react_query8.useQuery)({
|
|
1608
1675
|
...options,
|
|
1609
1676
|
queryKey: [iotaContext.network, method, params, ...queryKey],
|
|
1610
1677
|
queryFn: async () => {
|
|
@@ -1617,7 +1684,7 @@ function useIotaClientQuery(...args) {
|
|
|
1617
1684
|
function useIotaClientSuspenseQuery(...args) {
|
|
1618
1685
|
const [method, params, options = {}] = args;
|
|
1619
1686
|
const iotaContext = useIotaClientContext();
|
|
1620
|
-
const query = (0,
|
|
1687
|
+
const query = (0, import_react17.useMemo)(() => {
|
|
1621
1688
|
return getIotaClientQuery({
|
|
1622
1689
|
client: iotaContext.client,
|
|
1623
1690
|
network: iotaContext.network,
|
|
@@ -1626,17 +1693,17 @@ function useIotaClientSuspenseQuery(...args) {
|
|
|
1626
1693
|
options
|
|
1627
1694
|
});
|
|
1628
1695
|
}, [iotaContext.network, method, params, options]);
|
|
1629
|
-
return (0,
|
|
1696
|
+
return (0, import_react_query8.useSuspenseQuery)(query);
|
|
1630
1697
|
}
|
|
1631
1698
|
|
|
1632
1699
|
// src/hooks/useIotaClientQueries.ts
|
|
1633
|
-
var
|
|
1700
|
+
var import_react_query9 = require("@tanstack/react-query");
|
|
1634
1701
|
function useIotaClientQueries({
|
|
1635
1702
|
queries,
|
|
1636
1703
|
combine
|
|
1637
1704
|
}) {
|
|
1638
1705
|
const iotaContext = useIotaClientContext();
|
|
1639
|
-
return (0,
|
|
1706
|
+
return (0, import_react_query9.useQueries)({
|
|
1640
1707
|
combine,
|
|
1641
1708
|
queries: queries.map((query) => {
|
|
1642
1709
|
const { method, params, options: { queryKey = [], ...restOptions } = {} } = query;
|
|
@@ -1654,18 +1721,18 @@ function useIotaClientQueries({
|
|
|
1654
1721
|
// src/hooks/wallet/useSignAndExecuteTransaction.ts
|
|
1655
1722
|
var import_utils4 = require("@iota/iota-sdk/utils");
|
|
1656
1723
|
var import_wallet_standard5 = require("@iota/wallet-standard");
|
|
1657
|
-
var
|
|
1724
|
+
var import_react_query11 = require("@tanstack/react-query");
|
|
1658
1725
|
|
|
1659
1726
|
// src/hooks/wallet/useReportTransactionEffects.ts
|
|
1660
1727
|
var import_utils3 = require("@iota/iota-sdk/utils");
|
|
1661
|
-
var
|
|
1728
|
+
var import_react_query10 = require("@tanstack/react-query");
|
|
1662
1729
|
function useReportTransactionEffects({
|
|
1663
1730
|
mutationKey,
|
|
1664
1731
|
...mutationOptions
|
|
1665
1732
|
} = {}) {
|
|
1666
1733
|
const { currentWallet } = useCurrentWallet();
|
|
1667
1734
|
const currentAccount = useCurrentAccount();
|
|
1668
|
-
return (0,
|
|
1735
|
+
return (0, import_react_query10.useMutation)({
|
|
1669
1736
|
mutationKey: walletMutationKeys.reportTransactionEffects(mutationKey),
|
|
1670
1737
|
mutationFn: async ({
|
|
1671
1738
|
effects,
|
|
@@ -1693,12 +1760,18 @@ function useReportTransactionEffects({
|
|
|
1693
1760
|
});
|
|
1694
1761
|
}
|
|
1695
1762
|
|
|
1763
|
+
// src/hooks/wallet/useCurrentChain.ts
|
|
1764
|
+
function useCurrentChain() {
|
|
1765
|
+
return useWalletStore((state) => state.chain);
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1696
1768
|
// src/hooks/wallet/useSignAndExecuteTransaction.ts
|
|
1697
1769
|
function useSignAndExecuteTransaction({
|
|
1698
1770
|
mutationKey,
|
|
1699
1771
|
execute,
|
|
1700
1772
|
...mutationOptions
|
|
1701
1773
|
} = {}) {
|
|
1774
|
+
const currentChain = useCurrentChain();
|
|
1702
1775
|
const { currentWallet, supportedIntents } = useCurrentWallet();
|
|
1703
1776
|
const currentAccount = useCurrentAccount();
|
|
1704
1777
|
const client = useIotaClient();
|
|
@@ -1719,7 +1792,7 @@ function useSignAndExecuteTransaction({
|
|
|
1719
1792
|
signature
|
|
1720
1793
|
};
|
|
1721
1794
|
});
|
|
1722
|
-
return (0,
|
|
1795
|
+
return (0, import_react_query11.useMutation)({
|
|
1723
1796
|
mutationKey: walletMutationKeys.signAndExecuteTransaction(mutationKey),
|
|
1724
1797
|
mutationFn: async ({ transaction, ...signTransactionArgs }) => {
|
|
1725
1798
|
if (!currentWallet) {
|
|
@@ -1731,12 +1804,12 @@ function useSignAndExecuteTransaction({
|
|
|
1731
1804
|
"No wallet account is selected to sign the transaction with."
|
|
1732
1805
|
);
|
|
1733
1806
|
}
|
|
1734
|
-
const chain = signTransactionArgs.chain ?? signerAccount?.chains[0];
|
|
1735
1807
|
if (!currentWallet.features["iota:signTransaction"]) {
|
|
1736
1808
|
throw new WalletFeatureNotSupportedError(
|
|
1737
1809
|
"This wallet doesn't support the `signTransaction` feature."
|
|
1738
1810
|
);
|
|
1739
1811
|
}
|
|
1812
|
+
const chain = signTransactionArgs.chain ?? currentChain ?? signerAccount?.chains[0];
|
|
1740
1813
|
const { signature, bytes } = await (0, import_wallet_standard5.signTransaction)(currentWallet, {
|
|
1741
1814
|
...signTransactionArgs,
|
|
1742
1815
|
transaction: {
|
|
@@ -1748,7 +1821,7 @@ function useSignAndExecuteTransaction({
|
|
|
1748
1821
|
}
|
|
1749
1822
|
},
|
|
1750
1823
|
account: signerAccount,
|
|
1751
|
-
chain
|
|
1824
|
+
chain
|
|
1752
1825
|
});
|
|
1753
1826
|
const result = await executeTransaction({ bytes, signature });
|
|
1754
1827
|
let effects;
|
|
@@ -1772,14 +1845,14 @@ function useSignAndExecuteTransaction({
|
|
|
1772
1845
|
}
|
|
1773
1846
|
|
|
1774
1847
|
// src/hooks/wallet/useSignPersonalMessage.ts
|
|
1775
|
-
var
|
|
1848
|
+
var import_react_query12 = require("@tanstack/react-query");
|
|
1776
1849
|
function useSignPersonalMessage({
|
|
1777
1850
|
mutationKey,
|
|
1778
1851
|
...mutationOptions
|
|
1779
1852
|
} = {}) {
|
|
1780
1853
|
const { currentWallet } = useCurrentWallet();
|
|
1781
1854
|
const currentAccount = useCurrentAccount();
|
|
1782
|
-
return (0,
|
|
1855
|
+
return (0, import_react_query12.useMutation)({
|
|
1783
1856
|
mutationKey: walletMutationKeys.signPersonalMessage(mutationKey),
|
|
1784
1857
|
mutationFn: async (signPersonalMessageArgs) => {
|
|
1785
1858
|
if (!currentWallet) {
|
|
@@ -1808,7 +1881,7 @@ function useSignPersonalMessage({
|
|
|
1808
1881
|
|
|
1809
1882
|
// src/hooks/wallet/useSignTransaction.ts
|
|
1810
1883
|
var import_wallet_standard6 = require("@iota/wallet-standard");
|
|
1811
|
-
var
|
|
1884
|
+
var import_react_query13 = require("@tanstack/react-query");
|
|
1812
1885
|
function useSignTransaction({
|
|
1813
1886
|
mutationKey,
|
|
1814
1887
|
...mutationOptions
|
|
@@ -1817,7 +1890,7 @@ function useSignTransaction({
|
|
|
1817
1890
|
const currentAccount = useCurrentAccount();
|
|
1818
1891
|
const client = useIotaClient();
|
|
1819
1892
|
const { mutate: reportTransactionEffects } = useReportTransactionEffects();
|
|
1820
|
-
return (0,
|
|
1893
|
+
return (0, import_react_query13.useMutation)({
|
|
1821
1894
|
mutationKey: walletMutationKeys.signTransaction(mutationKey),
|
|
1822
1895
|
mutationFn: async ({ transaction, ...signTransactionArgs }) => {
|
|
1823
1896
|
if (!currentWallet) {
|