@iota/dapp-kit 0.5.2 → 0.7.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 +42 -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 +2 -1
- package/dist/cjs/components/ConnectButton.js +163 -89
- package/dist/cjs/components/ConnectButton.js.map +4 -4
- package/dist/cjs/components/WalletProvider.d.ts +3 -1
- package/dist/cjs/components/WalletProvider.js +7 -3
- package/dist/cjs/components/WalletProvider.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/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 +179 -118
- 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 +2 -1
- package/dist/esm/components/ConnectButton.js +145 -71
- package/dist/esm/components/ConnectButton.js.map +4 -4
- package/dist/esm/components/WalletProvider.d.ts +3 -1
- package/dist/esm/components/WalletProvider.js +7 -3
- package/dist/esm/components/WalletProvider.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/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 +150 -89
- 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 +7 -1
- package/src/components/WalletProvider.tsx +5 -0
- package/src/hooks/useGetDefaultIotaName.ts +43 -0
- 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
|
@@ -810,27 +810,129 @@ function ChevronIcon(props) {
|
|
|
810
810
|
) });
|
|
811
811
|
}
|
|
812
812
|
|
|
813
|
-
// src/
|
|
813
|
+
// src/hooks/useGetDefaultIotaName.ts
|
|
814
|
+
var import_client2 = require("@iota/iota-sdk/client");
|
|
815
|
+
var import_react_query4 = require("@tanstack/react-query");
|
|
816
|
+
var import_iota_names_sdk = require("@iota/iota-names-sdk");
|
|
817
|
+
|
|
818
|
+
// src/hooks/useIotaClient.ts
|
|
819
|
+
var import_react10 = require("react");
|
|
820
|
+
|
|
821
|
+
// src/components/IotaClientProvider.tsx
|
|
822
|
+
var import_client = require("@iota/iota-sdk/client");
|
|
823
|
+
var import_react9 = require("react");
|
|
814
824
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
815
|
-
|
|
825
|
+
var IotaClientContext = (0, import_react9.createContext)(null);
|
|
826
|
+
var DEFAULT_NETWORKS = {
|
|
827
|
+
localnet: { url: (0, import_client.getNetwork)(import_client.Network.Localnet)?.url }
|
|
828
|
+
};
|
|
829
|
+
var DEFAULT_CREATE_CLIENT = function createClient(_name, config) {
|
|
830
|
+
if ((0, import_client.isIotaClient)(config)) {
|
|
831
|
+
return config;
|
|
832
|
+
}
|
|
833
|
+
return new import_client.IotaClient(config);
|
|
834
|
+
};
|
|
835
|
+
function IotaClientProvider(props) {
|
|
836
|
+
const { onNetworkChange, network, children } = props;
|
|
837
|
+
const networks = props.networks ?? DEFAULT_NETWORKS;
|
|
838
|
+
const createClient2 = props.createClient ?? DEFAULT_CREATE_CLIENT;
|
|
839
|
+
const [selectedNetwork, setSelectedNetwork] = (0, import_react9.useState)(
|
|
840
|
+
props.network ?? props.defaultNetwork ?? Object.keys(networks)[0]
|
|
841
|
+
);
|
|
842
|
+
const currentNetwork = props.network ?? selectedNetwork;
|
|
843
|
+
const client = (0, import_react9.useMemo)(() => {
|
|
844
|
+
return createClient2(currentNetwork, networks[currentNetwork]);
|
|
845
|
+
}, [createClient2, currentNetwork, networks]);
|
|
846
|
+
const ctx = (0, import_react9.useMemo)(() => {
|
|
847
|
+
return {
|
|
848
|
+
client,
|
|
849
|
+
networks,
|
|
850
|
+
network: currentNetwork,
|
|
851
|
+
config: networks[currentNetwork] instanceof import_client.IotaClient ? null : networks[currentNetwork],
|
|
852
|
+
selectNetwork: (newNetwork) => {
|
|
853
|
+
if (currentNetwork === newNetwork) {
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
if (!network && newNetwork !== selectedNetwork) {
|
|
857
|
+
setSelectedNetwork(newNetwork);
|
|
858
|
+
}
|
|
859
|
+
onNetworkChange?.(newNetwork);
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
}, [client, networks, selectedNetwork, currentNetwork, network, onNetworkChange]);
|
|
863
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(IotaClientContext.Provider, { value: ctx, children });
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
// src/hooks/useIotaClient.ts
|
|
867
|
+
function useIotaClientContext() {
|
|
868
|
+
const iotaClient = (0, import_react10.useContext)(IotaClientContext);
|
|
869
|
+
if (!iotaClient) {
|
|
870
|
+
throw new Error(
|
|
871
|
+
"Could not find IotaClientContext. Ensure that you have set up the IotaClientProvider"
|
|
872
|
+
);
|
|
873
|
+
}
|
|
874
|
+
return iotaClient;
|
|
875
|
+
}
|
|
876
|
+
function useIotaClient() {
|
|
877
|
+
return useIotaClientContext().client;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
// src/hooks/useGetDefaultIotaName.ts
|
|
881
|
+
var import_react11 = require("react");
|
|
882
|
+
var import_graphql = require("@iota/iota-sdk/graphql");
|
|
883
|
+
function useGetDefaultIotaName(address, iotaNamesEnabled) {
|
|
884
|
+
const iotaContext = useIotaClientContext();
|
|
885
|
+
const network = (0, import_client2.getNetwork)(iotaContext.network);
|
|
886
|
+
const iotaNamesClient = (0, import_react11.useMemo)(() => {
|
|
887
|
+
const iotaGraphQLClient = new import_graphql.IotaGraphQLClient({
|
|
888
|
+
url: network.graphql
|
|
889
|
+
});
|
|
890
|
+
return new import_iota_names_sdk.IotaNamesClient({
|
|
891
|
+
graphQlClient: iotaGraphQLClient,
|
|
892
|
+
network: network.id
|
|
893
|
+
});
|
|
894
|
+
}, [network.id]);
|
|
895
|
+
const iotaNamesSupported = !!iotaNamesClient.config;
|
|
896
|
+
return (0, import_react_query4.useQuery)({
|
|
897
|
+
queryKey: ["iota-name", "default-name", address],
|
|
898
|
+
queryFn: async () => {
|
|
899
|
+
if (!address) return null;
|
|
900
|
+
const name = await iotaNamesClient?.getDefaultName(address);
|
|
901
|
+
return name ? (0, import_iota_names_sdk.normalizeIotaName)(name) : name;
|
|
902
|
+
},
|
|
903
|
+
enabled: !!iotaNamesClient && !!address && iotaNamesEnabled && iotaNamesSupported,
|
|
904
|
+
staleTime: 1e3 * 60 * 10
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// src/components/AccountDropdownMenu.tsx
|
|
909
|
+
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
910
|
+
function AccountDropdownMenu({
|
|
911
|
+
currentAccount,
|
|
912
|
+
size = "lg",
|
|
913
|
+
iotaNamesEnabled
|
|
914
|
+
}) {
|
|
816
915
|
const { mutate: disconnectWallet } = useDisconnectWallet();
|
|
817
916
|
const accounts = useAccounts();
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
917
|
+
const { data: iotaName } = useGetDefaultIotaName(currentAccount.address, iotaNamesEnabled);
|
|
918
|
+
const displayAccount = iotaName ?? currentAccount.label ?? (0, import_utils.formatAddress)(currentAccount.address);
|
|
919
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(DropdownMenu.Root, { modal: false, children: [
|
|
920
|
+
/* @__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: [
|
|
921
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Text, { mono: true, weight: "bold", children: displayAccount }),
|
|
922
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(ChevronIcon, {})
|
|
822
923
|
] }) }) }),
|
|
823
|
-
/* @__PURE__ */ (0,
|
|
824
|
-
/* @__PURE__ */ (0,
|
|
924
|
+
/* @__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: [
|
|
925
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: scrollableContent, children: accounts.map((account) => /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
825
926
|
AccountDropdownMenuItem,
|
|
826
927
|
{
|
|
827
928
|
account,
|
|
828
|
-
active: currentAccount.address === account.address
|
|
929
|
+
active: currentAccount.address === account.address,
|
|
930
|
+
iotaNamesEnabled
|
|
829
931
|
},
|
|
830
932
|
account.address
|
|
831
933
|
)) }),
|
|
832
|
-
/* @__PURE__ */ (0,
|
|
833
|
-
/* @__PURE__ */ (0,
|
|
934
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(DropdownMenu.Separator, { className: separator }),
|
|
935
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
834
936
|
DropdownMenu.Item,
|
|
835
937
|
{
|
|
836
938
|
className: (0, import_clsx7.default)(menuItem),
|
|
@@ -843,85 +945,51 @@ function AccountDropdownMenu({ currentAccount, size = "lg" }) {
|
|
|
843
945
|
}
|
|
844
946
|
function AccountDropdownMenuItem({
|
|
845
947
|
account,
|
|
846
|
-
active
|
|
948
|
+
active,
|
|
949
|
+
iotaNamesEnabled
|
|
847
950
|
}) {
|
|
848
951
|
const { mutate: switchAccount } = useSwitchAccount();
|
|
849
|
-
|
|
952
|
+
const { data: iotaName } = useGetDefaultIotaName(account.address, iotaNamesEnabled);
|
|
953
|
+
const displayAccount = iotaName ?? account.label ?? (0, import_utils.formatAddress)(account.address);
|
|
954
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
|
|
850
955
|
DropdownMenu.Item,
|
|
851
956
|
{
|
|
852
957
|
className: (0, import_clsx7.default)(menuItem, switchAccountMenuItem),
|
|
853
958
|
onSelect: () => switchAccount({ account }),
|
|
854
959
|
children: [
|
|
855
|
-
/* @__PURE__ */ (0,
|
|
856
|
-
active ? /* @__PURE__ */ (0,
|
|
960
|
+
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Text, { mono: true, children: displayAccount }),
|
|
961
|
+
active ? /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(CheckIcon, {}) : null
|
|
857
962
|
]
|
|
858
963
|
}
|
|
859
964
|
);
|
|
860
965
|
}
|
|
861
966
|
|
|
862
967
|
// src/components/ConnectButton.tsx
|
|
863
|
-
var
|
|
968
|
+
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
864
969
|
function ConnectButton({
|
|
865
970
|
connectText = "Connect Wallet",
|
|
866
971
|
size,
|
|
972
|
+
iotaNamesEnabled = true,
|
|
867
973
|
...buttonProps
|
|
868
974
|
}) {
|
|
869
975
|
const currentAccount = useCurrentAccount();
|
|
870
|
-
return currentAccount ? /* @__PURE__ */ (0,
|
|
976
|
+
return currentAccount ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
977
|
+
AccountDropdownMenu,
|
|
978
|
+
{
|
|
979
|
+
currentAccount,
|
|
980
|
+
size,
|
|
981
|
+
iotaNamesEnabled
|
|
982
|
+
}
|
|
983
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
871
984
|
ConnectModal,
|
|
872
985
|
{
|
|
873
|
-
trigger: /* @__PURE__ */ (0,
|
|
986
|
+
trigger: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(StyleMarker, { children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Button, { ...buttonProps, size, children: connectText }) })
|
|
874
987
|
}
|
|
875
988
|
);
|
|
876
989
|
}
|
|
877
990
|
|
|
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
991
|
// src/components/WalletProvider.tsx
|
|
924
|
-
var
|
|
992
|
+
var import_react16 = require("react");
|
|
925
993
|
|
|
926
994
|
// src/utils/stateStorage.ts
|
|
927
995
|
function createInMemoryStore() {
|
|
@@ -950,8 +1018,8 @@ var WALLET_CHROME_EXTENSION_ID = "iidjkmdceolghepehaaddojmnjnkkija";
|
|
|
950
1018
|
var WALLET_DOWNLOAD_URL = "https://chromewebstore.google.com/detail/" + WALLET_CHROME_EXTENSION_ID;
|
|
951
1019
|
|
|
952
1020
|
// src/hooks/wallet/useAutoConnectWallet.ts
|
|
953
|
-
var
|
|
954
|
-
var
|
|
1021
|
+
var import_react_query5 = require("@tanstack/react-query");
|
|
1022
|
+
var import_react12 = require("react");
|
|
955
1023
|
function useAutoConnectWallet() {
|
|
956
1024
|
const { mutateAsync: connectWallet } = useConnectWallet();
|
|
957
1025
|
const autoConnectEnabled = useWalletStore((state) => state.autoConnectEnabled);
|
|
@@ -961,11 +1029,11 @@ function useAutoConnectWallet() {
|
|
|
961
1029
|
);
|
|
962
1030
|
const wallets = useWallets();
|
|
963
1031
|
const { isConnected } = useCurrentWallet();
|
|
964
|
-
const [clientOnly, setClientOnly] = (0,
|
|
965
|
-
(0,
|
|
1032
|
+
const [clientOnly, setClientOnly] = (0, import_react12.useState)(false);
|
|
1033
|
+
(0, import_react12.useLayoutEffect)(() => {
|
|
966
1034
|
setClientOnly(true);
|
|
967
1035
|
}, []);
|
|
968
|
-
const { data, isError } = (0,
|
|
1036
|
+
const { data, isError } = (0, import_react_query5.useQuery)({
|
|
969
1037
|
queryKey: [
|
|
970
1038
|
"@iota/dapp-kit",
|
|
971
1039
|
"autoconnect",
|
|
@@ -1029,28 +1097,11 @@ var import_ed25519 = require("@iota/iota-sdk/keypairs/ed25519");
|
|
|
1029
1097
|
var import_transactions = require("@iota/iota-sdk/transactions");
|
|
1030
1098
|
var import_utils2 = require("@iota/iota-sdk/utils");
|
|
1031
1099
|
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
|
|
1100
|
+
var import_react13 = require("react");
|
|
1050
1101
|
var WALLET_NAME = "Unsafe Burner Wallet";
|
|
1051
1102
|
function useUnsafeBurnerWallet(enabled) {
|
|
1052
1103
|
const iotaClient = useIotaClient();
|
|
1053
|
-
(0,
|
|
1104
|
+
(0, import_react13.useEffect)(() => {
|
|
1054
1105
|
if (!enabled) {
|
|
1055
1106
|
return;
|
|
1056
1107
|
}
|
|
@@ -1177,11 +1228,11 @@ function registerUnsafeBurnerWallet(iotaClient) {
|
|
|
1177
1228
|
}
|
|
1178
1229
|
|
|
1179
1230
|
// src/hooks/wallet/useWalletPropertiesChanged.ts
|
|
1180
|
-
var
|
|
1231
|
+
var import_react14 = require("react");
|
|
1181
1232
|
function useWalletPropertiesChanged() {
|
|
1182
1233
|
const { currentWallet } = useCurrentWallet();
|
|
1183
1234
|
const updateWalletAccounts = useWalletStore((state) => state.updateWalletAccounts);
|
|
1184
|
-
(0,
|
|
1235
|
+
(0, import_react14.useEffect)(() => {
|
|
1185
1236
|
const unsubscribeFromEvents = currentWallet?.features["standard:events"].on(
|
|
1186
1237
|
"change",
|
|
1187
1238
|
({ accounts }) => {
|
|
@@ -1196,11 +1247,11 @@ function useWalletPropertiesChanged() {
|
|
|
1196
1247
|
|
|
1197
1248
|
// src/hooks/wallet/useWalletsChanged.ts
|
|
1198
1249
|
var import_wallet_standard4 = require("@iota/wallet-standard");
|
|
1199
|
-
var
|
|
1250
|
+
var import_react15 = require("react");
|
|
1200
1251
|
function useWalletsChanged(preferredWallets, walletFilter) {
|
|
1201
1252
|
const setWalletRegistered = useWalletStore((state) => state.setWalletRegistered);
|
|
1202
1253
|
const setWalletUnregistered = useWalletStore((state) => state.setWalletUnregistered);
|
|
1203
|
-
(0,
|
|
1254
|
+
(0, import_react15.useEffect)(() => {
|
|
1204
1255
|
const walletsApi = (0, import_wallet_standard4.getWallets)();
|
|
1205
1256
|
setWalletRegistered(getRegisteredWallets(preferredWallets, walletFilter));
|
|
1206
1257
|
const unsubscribeFromRegister = walletsApi.on("register", () => {
|
|
@@ -1290,7 +1341,8 @@ function createWalletStore({
|
|
|
1290
1341
|
wallets,
|
|
1291
1342
|
storage,
|
|
1292
1343
|
storageKey,
|
|
1293
|
-
autoConnectEnabled
|
|
1344
|
+
autoConnectEnabled,
|
|
1345
|
+
chain
|
|
1294
1346
|
}) {
|
|
1295
1347
|
return (0, import_zustand2.createStore)()(
|
|
1296
1348
|
(0, import_middleware.persist)(
|
|
@@ -1304,6 +1356,7 @@ function createWalletStore({
|
|
|
1304
1356
|
lastConnectedWalletName: null,
|
|
1305
1357
|
connectionStatus: "disconnected",
|
|
1306
1358
|
supportedIntents: [],
|
|
1359
|
+
chain,
|
|
1307
1360
|
setConnectionStatus(connectionStatus2) {
|
|
1308
1361
|
set(() => ({
|
|
1309
1362
|
connectionStatus: connectionStatus2
|
|
@@ -1489,14 +1542,16 @@ function WalletProvider({
|
|
|
1489
1542
|
enableUnsafeBurner = false,
|
|
1490
1543
|
autoConnect = false,
|
|
1491
1544
|
theme = lightTheme,
|
|
1492
|
-
children
|
|
1545
|
+
children,
|
|
1546
|
+
chain
|
|
1493
1547
|
}) {
|
|
1494
|
-
const storeRef = (0,
|
|
1548
|
+
const storeRef = (0, import_react16.useRef)(
|
|
1495
1549
|
createWalletStore({
|
|
1496
1550
|
autoConnectEnabled: autoConnect,
|
|
1497
1551
|
wallets: getRegisteredWallets(preferredWallets, walletFilter),
|
|
1498
1552
|
storage: storage || createInMemoryStore(),
|
|
1499
|
-
storageKey
|
|
1553
|
+
storageKey,
|
|
1554
|
+
chain
|
|
1500
1555
|
})
|
|
1501
1556
|
);
|
|
1502
1557
|
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(WalletContext.Provider, { value: storeRef.current, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(
|
|
@@ -1551,14 +1606,14 @@ function createNetworkConfig(networkConfig) {
|
|
|
1551
1606
|
}
|
|
1552
1607
|
|
|
1553
1608
|
// src/hooks/useIotaClientInfiniteQuery.ts
|
|
1554
|
-
var
|
|
1609
|
+
var import_react_query6 = require("@tanstack/react-query");
|
|
1555
1610
|
function useIotaClientInfiniteQuery(method, params, {
|
|
1556
1611
|
queryKey = [],
|
|
1557
1612
|
enabled = !!params,
|
|
1558
1613
|
...options
|
|
1559
1614
|
} = {}) {
|
|
1560
1615
|
const iotaContext = useIotaClientContext();
|
|
1561
|
-
return (0,
|
|
1616
|
+
return (0, import_react_query6.useInfiniteQuery)({
|
|
1562
1617
|
...options,
|
|
1563
1618
|
initialPageParam: null,
|
|
1564
1619
|
queryKey: [iotaContext.network, method, params, ...queryKey],
|
|
@@ -1572,10 +1627,10 @@ function useIotaClientInfiniteQuery(method, params, {
|
|
|
1572
1627
|
}
|
|
1573
1628
|
|
|
1574
1629
|
// src/hooks/useIotaClientMutation.ts
|
|
1575
|
-
var
|
|
1630
|
+
var import_react_query7 = require("@tanstack/react-query");
|
|
1576
1631
|
function useIotaClientMutation(method, options = {}) {
|
|
1577
1632
|
const iotaContext = useIotaClientContext();
|
|
1578
|
-
return (0,
|
|
1633
|
+
return (0, import_react_query7.useMutation)({
|
|
1579
1634
|
...options,
|
|
1580
1635
|
mutationFn: async (params) => {
|
|
1581
1636
|
return await iotaContext.client[method](params);
|
|
@@ -1584,8 +1639,8 @@ function useIotaClientMutation(method, options = {}) {
|
|
|
1584
1639
|
}
|
|
1585
1640
|
|
|
1586
1641
|
// src/hooks/useIotaClientQuery.ts
|
|
1587
|
-
var
|
|
1588
|
-
var
|
|
1642
|
+
var import_react_query8 = require("@tanstack/react-query");
|
|
1643
|
+
var import_react17 = require("react");
|
|
1589
1644
|
function getIotaClientQuery({
|
|
1590
1645
|
client,
|
|
1591
1646
|
network,
|
|
@@ -1593,7 +1648,7 @@ function getIotaClientQuery({
|
|
|
1593
1648
|
params,
|
|
1594
1649
|
options
|
|
1595
1650
|
}) {
|
|
1596
|
-
return (0,
|
|
1651
|
+
return (0, import_react_query8.queryOptions)({
|
|
1597
1652
|
...options,
|
|
1598
1653
|
queryKey: [network, method, params],
|
|
1599
1654
|
queryFn: async () => {
|
|
@@ -1604,7 +1659,7 @@ function getIotaClientQuery({
|
|
|
1604
1659
|
function useIotaClientQuery(...args) {
|
|
1605
1660
|
const [method, params, { queryKey = [], ...options } = {}] = args;
|
|
1606
1661
|
const iotaContext = useIotaClientContext();
|
|
1607
|
-
return (0,
|
|
1662
|
+
return (0, import_react_query8.useQuery)({
|
|
1608
1663
|
...options,
|
|
1609
1664
|
queryKey: [iotaContext.network, method, params, ...queryKey],
|
|
1610
1665
|
queryFn: async () => {
|
|
@@ -1617,7 +1672,7 @@ function useIotaClientQuery(...args) {
|
|
|
1617
1672
|
function useIotaClientSuspenseQuery(...args) {
|
|
1618
1673
|
const [method, params, options = {}] = args;
|
|
1619
1674
|
const iotaContext = useIotaClientContext();
|
|
1620
|
-
const query = (0,
|
|
1675
|
+
const query = (0, import_react17.useMemo)(() => {
|
|
1621
1676
|
return getIotaClientQuery({
|
|
1622
1677
|
client: iotaContext.client,
|
|
1623
1678
|
network: iotaContext.network,
|
|
@@ -1626,17 +1681,17 @@ function useIotaClientSuspenseQuery(...args) {
|
|
|
1626
1681
|
options
|
|
1627
1682
|
});
|
|
1628
1683
|
}, [iotaContext.network, method, params, options]);
|
|
1629
|
-
return (0,
|
|
1684
|
+
return (0, import_react_query8.useSuspenseQuery)(query);
|
|
1630
1685
|
}
|
|
1631
1686
|
|
|
1632
1687
|
// src/hooks/useIotaClientQueries.ts
|
|
1633
|
-
var
|
|
1688
|
+
var import_react_query9 = require("@tanstack/react-query");
|
|
1634
1689
|
function useIotaClientQueries({
|
|
1635
1690
|
queries,
|
|
1636
1691
|
combine
|
|
1637
1692
|
}) {
|
|
1638
1693
|
const iotaContext = useIotaClientContext();
|
|
1639
|
-
return (0,
|
|
1694
|
+
return (0, import_react_query9.useQueries)({
|
|
1640
1695
|
combine,
|
|
1641
1696
|
queries: queries.map((query) => {
|
|
1642
1697
|
const { method, params, options: { queryKey = [], ...restOptions } = {} } = query;
|
|
@@ -1654,18 +1709,18 @@ function useIotaClientQueries({
|
|
|
1654
1709
|
// src/hooks/wallet/useSignAndExecuteTransaction.ts
|
|
1655
1710
|
var import_utils4 = require("@iota/iota-sdk/utils");
|
|
1656
1711
|
var import_wallet_standard5 = require("@iota/wallet-standard");
|
|
1657
|
-
var
|
|
1712
|
+
var import_react_query11 = require("@tanstack/react-query");
|
|
1658
1713
|
|
|
1659
1714
|
// src/hooks/wallet/useReportTransactionEffects.ts
|
|
1660
1715
|
var import_utils3 = require("@iota/iota-sdk/utils");
|
|
1661
|
-
var
|
|
1716
|
+
var import_react_query10 = require("@tanstack/react-query");
|
|
1662
1717
|
function useReportTransactionEffects({
|
|
1663
1718
|
mutationKey,
|
|
1664
1719
|
...mutationOptions
|
|
1665
1720
|
} = {}) {
|
|
1666
1721
|
const { currentWallet } = useCurrentWallet();
|
|
1667
1722
|
const currentAccount = useCurrentAccount();
|
|
1668
|
-
return (0,
|
|
1723
|
+
return (0, import_react_query10.useMutation)({
|
|
1669
1724
|
mutationKey: walletMutationKeys.reportTransactionEffects(mutationKey),
|
|
1670
1725
|
mutationFn: async ({
|
|
1671
1726
|
effects,
|
|
@@ -1693,12 +1748,18 @@ function useReportTransactionEffects({
|
|
|
1693
1748
|
});
|
|
1694
1749
|
}
|
|
1695
1750
|
|
|
1751
|
+
// src/hooks/wallet/useCurrentChain.ts
|
|
1752
|
+
function useCurrentChain() {
|
|
1753
|
+
return useWalletStore((state) => state.chain);
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1696
1756
|
// src/hooks/wallet/useSignAndExecuteTransaction.ts
|
|
1697
1757
|
function useSignAndExecuteTransaction({
|
|
1698
1758
|
mutationKey,
|
|
1699
1759
|
execute,
|
|
1700
1760
|
...mutationOptions
|
|
1701
1761
|
} = {}) {
|
|
1762
|
+
const currentChain = useCurrentChain();
|
|
1702
1763
|
const { currentWallet, supportedIntents } = useCurrentWallet();
|
|
1703
1764
|
const currentAccount = useCurrentAccount();
|
|
1704
1765
|
const client = useIotaClient();
|
|
@@ -1719,7 +1780,7 @@ function useSignAndExecuteTransaction({
|
|
|
1719
1780
|
signature
|
|
1720
1781
|
};
|
|
1721
1782
|
});
|
|
1722
|
-
return (0,
|
|
1783
|
+
return (0, import_react_query11.useMutation)({
|
|
1723
1784
|
mutationKey: walletMutationKeys.signAndExecuteTransaction(mutationKey),
|
|
1724
1785
|
mutationFn: async ({ transaction, ...signTransactionArgs }) => {
|
|
1725
1786
|
if (!currentWallet) {
|
|
@@ -1731,12 +1792,12 @@ function useSignAndExecuteTransaction({
|
|
|
1731
1792
|
"No wallet account is selected to sign the transaction with."
|
|
1732
1793
|
);
|
|
1733
1794
|
}
|
|
1734
|
-
const chain = signTransactionArgs.chain ?? signerAccount?.chains[0];
|
|
1735
1795
|
if (!currentWallet.features["iota:signTransaction"]) {
|
|
1736
1796
|
throw new WalletFeatureNotSupportedError(
|
|
1737
1797
|
"This wallet doesn't support the `signTransaction` feature."
|
|
1738
1798
|
);
|
|
1739
1799
|
}
|
|
1800
|
+
const chain = signTransactionArgs.chain ?? currentChain ?? signerAccount?.chains[0];
|
|
1740
1801
|
const { signature, bytes } = await (0, import_wallet_standard5.signTransaction)(currentWallet, {
|
|
1741
1802
|
...signTransactionArgs,
|
|
1742
1803
|
transaction: {
|
|
@@ -1748,7 +1809,7 @@ function useSignAndExecuteTransaction({
|
|
|
1748
1809
|
}
|
|
1749
1810
|
},
|
|
1750
1811
|
account: signerAccount,
|
|
1751
|
-
chain
|
|
1812
|
+
chain
|
|
1752
1813
|
});
|
|
1753
1814
|
const result = await executeTransaction({ bytes, signature });
|
|
1754
1815
|
let effects;
|
|
@@ -1772,14 +1833,14 @@ function useSignAndExecuteTransaction({
|
|
|
1772
1833
|
}
|
|
1773
1834
|
|
|
1774
1835
|
// src/hooks/wallet/useSignPersonalMessage.ts
|
|
1775
|
-
var
|
|
1836
|
+
var import_react_query12 = require("@tanstack/react-query");
|
|
1776
1837
|
function useSignPersonalMessage({
|
|
1777
1838
|
mutationKey,
|
|
1778
1839
|
...mutationOptions
|
|
1779
1840
|
} = {}) {
|
|
1780
1841
|
const { currentWallet } = useCurrentWallet();
|
|
1781
1842
|
const currentAccount = useCurrentAccount();
|
|
1782
|
-
return (0,
|
|
1843
|
+
return (0, import_react_query12.useMutation)({
|
|
1783
1844
|
mutationKey: walletMutationKeys.signPersonalMessage(mutationKey),
|
|
1784
1845
|
mutationFn: async (signPersonalMessageArgs) => {
|
|
1785
1846
|
if (!currentWallet) {
|
|
@@ -1808,7 +1869,7 @@ function useSignPersonalMessage({
|
|
|
1808
1869
|
|
|
1809
1870
|
// src/hooks/wallet/useSignTransaction.ts
|
|
1810
1871
|
var import_wallet_standard6 = require("@iota/wallet-standard");
|
|
1811
|
-
var
|
|
1872
|
+
var import_react_query13 = require("@tanstack/react-query");
|
|
1812
1873
|
function useSignTransaction({
|
|
1813
1874
|
mutationKey,
|
|
1814
1875
|
...mutationOptions
|
|
@@ -1817,7 +1878,7 @@ function useSignTransaction({
|
|
|
1817
1878
|
const currentAccount = useCurrentAccount();
|
|
1818
1879
|
const client = useIotaClient();
|
|
1819
1880
|
const { mutate: reportTransactionEffects } = useReportTransactionEffects();
|
|
1820
|
-
return (0,
|
|
1881
|
+
return (0, import_react_query13.useMutation)({
|
|
1821
1882
|
mutationKey: walletMutationKeys.signTransaction(mutationKey),
|
|
1822
1883
|
mutationFn: async ({ transaction, ...signTransactionArgs }) => {
|
|
1823
1884
|
if (!currentWallet) {
|