@mintmoney/react 0.1.0-alpha.12 → 0.1.0-alpha.14
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 +19 -0
- package/dist/css/styles.css +34 -0
- package/dist/esm/api/payments.js +1 -1
- package/dist/esm/api/types.js +1 -7
- package/dist/esm/api/types.js.map +1 -1
- package/dist/esm/checkout/index.js +17 -3
- package/dist/esm/checkout/index.js.map +1 -1
- package/dist/esm/checkout/modal.js +6 -0
- package/dist/esm/checkout/modal.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/curreny.js +1 -1
- package/dist/esm/checkout/views/crypto-intent/curreny.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/methods.js +3 -3
- package/dist/esm/checkout/views/crypto-intent/methods.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/processing.js +2 -4
- package/dist/esm/checkout/views/crypto-intent/processing.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/wallet-select.js +21 -0
- package/dist/esm/checkout/views/crypto-intent/wallet-select.js.map +1 -0
- package/dist/esm/components/buttons/async-button.js +16 -0
- package/dist/esm/components/buttons/async-button.js.map +1 -0
- package/dist/esm/components/buttons/index.js +74 -1
- package/dist/esm/components/buttons/index.js.map +1 -1
- package/dist/esm/components/buttons/use-async-button.js +44 -0
- package/dist/esm/components/buttons/use-async-button.js.map +1 -0
- package/dist/esm/components/icons/alert.js +20 -0
- package/dist/esm/components/icons/alert.js.map +1 -0
- package/dist/esm/components/icons/index.js +3 -0
- package/dist/esm/components/icons/index.js.map +1 -1
- package/dist/esm/components/icons/link.js +20 -0
- package/dist/esm/components/icons/link.js.map +1 -0
- package/dist/esm/components/icons/loading.js +20 -0
- package/dist/esm/components/icons/loading.js.map +1 -0
- package/dist/esm/components/inputs/index.js +32 -0
- package/dist/esm/components/inputs/index.js.map +1 -0
- package/dist/esm/components/wallet-selector/component.js +61 -0
- package/dist/esm/components/wallet-selector/component.js.map +1 -0
- package/dist/esm/components/wallet-selector/domain.js +2 -0
- package/dist/esm/components/wallet-selector/domain.js.map +1 -0
- package/dist/esm/components/wallet-selector/helper.js +12 -0
- package/dist/esm/components/wallet-selector/helper.js.map +1 -0
- package/dist/esm/components/wallet-selector/index.js +5 -0
- package/dist/esm/components/wallet-selector/index.js.map +1 -0
- package/dist/esm/components/wallet-selector/provider.js +15 -0
- package/dist/esm/components/wallet-selector/provider.js.map +1 -0
- package/dist/esm/components/wallet-selector/schemas.js +6 -0
- package/dist/esm/components/wallet-selector/schemas.js.map +1 -0
- package/dist/esm/components/wallet-selector/store.js +79 -0
- package/dist/esm/components/wallet-selector/store.js.map +1 -0
- package/dist/esm/components/wallet-selector/util/exceptions.js +16 -0
- package/dist/esm/components/wallet-selector/util/exceptions.js.map +1 -0
- package/dist/esm/components/wallet-selector/wallets/address/addressInput.js +17 -0
- package/dist/esm/components/wallet-selector/wallets/address/addressInput.js.map +1 -0
- package/dist/esm/components/wallet-selector/wallets/address/index.js +75 -0
- package/dist/esm/components/wallet-selector/wallets/address/index.js.map +1 -0
- package/dist/esm/components/wallet-selector/wallets/index.js +5 -0
- package/dist/esm/components/wallet-selector/wallets/index.js.map +1 -0
- package/dist/esm/components/wallet-selector/wallets/recommended/index.js +64 -0
- package/dist/esm/components/wallet-selector/wallets/recommended/index.js.map +1 -0
- package/dist/esm/components/wallet-selector/wallets/wagmi/index.js +211 -0
- package/dist/esm/components/wallet-selector/wallets/wagmi/index.js.map +1 -0
- package/dist/esm/components/wallet-selector/wallets/wagmi/usdt-abi.json +671 -0
- package/dist/esm/config.js +1 -10
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/state/checkout/store.js +2 -2
- package/dist/esm/state/checkout/store.js.map +1 -1
- package/dist/esm/themes/default.js +42 -0
- package/dist/esm/themes/default.js.map +1 -1
- package/dist/types/api/types.d.ts +0 -6
- package/dist/types/api/types.d.ts.map +1 -1
- package/dist/types/checkout/index.d.ts.map +1 -1
- package/dist/types/checkout/modal.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/curreny.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/processing.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/wallet-select.d.ts +3 -0
- package/dist/types/checkout/views/crypto-intent/wallet-select.d.ts.map +1 -0
- package/dist/types/components/buttons/async-button.d.ts +14 -0
- package/dist/types/components/buttons/async-button.d.ts.map +1 -0
- package/dist/types/components/buttons/index.d.ts +20 -3
- package/dist/types/components/buttons/index.d.ts.map +1 -1
- package/dist/types/components/buttons/use-async-button.d.ts +16 -0
- package/dist/types/components/buttons/use-async-button.d.ts.map +1 -0
- package/dist/types/components/icons/alert.d.ts +6 -0
- package/dist/types/components/icons/alert.d.ts.map +1 -0
- package/dist/types/components/icons/index.d.ts +3 -0
- package/dist/types/components/icons/index.d.ts.map +1 -1
- package/dist/types/components/icons/link.d.ts +6 -0
- package/dist/types/components/icons/link.d.ts.map +1 -0
- package/dist/types/components/icons/loading.d.ts +6 -0
- package/dist/types/components/icons/loading.d.ts.map +1 -0
- package/dist/types/components/inputs/index.d.ts +7 -0
- package/dist/types/components/inputs/index.d.ts.map +1 -0
- package/dist/types/components/wallet-selector/component.d.ts +13 -0
- package/dist/types/components/wallet-selector/component.d.ts.map +1 -0
- package/dist/types/components/wallet-selector/domain.d.ts +86 -0
- package/dist/types/components/wallet-selector/domain.d.ts.map +1 -0
- package/dist/types/components/wallet-selector/helper.d.ts +4 -0
- package/dist/types/components/wallet-selector/helper.d.ts.map +1 -0
- package/dist/types/components/wallet-selector/index.d.ts +7 -0
- package/dist/types/components/wallet-selector/index.d.ts.map +1 -0
- package/dist/types/components/wallet-selector/provider.d.ts +10 -0
- package/dist/types/components/wallet-selector/provider.d.ts.map +1 -0
- package/dist/types/components/wallet-selector/schemas.d.ts +4 -0
- package/dist/types/components/wallet-selector/schemas.d.ts.map +1 -0
- package/dist/types/components/wallet-selector/store.d.ts +27 -0
- package/dist/types/components/wallet-selector/store.d.ts.map +1 -0
- package/dist/types/components/wallet-selector/util/exceptions.d.ts +7 -0
- package/dist/types/components/wallet-selector/util/exceptions.d.ts.map +1 -0
- package/dist/types/components/wallet-selector/wallets/address/addressInput.d.ts +7 -0
- package/dist/types/components/wallet-selector/wallets/address/addressInput.d.ts.map +1 -0
- package/dist/types/components/wallet-selector/wallets/address/index.d.ts +7 -0
- package/dist/types/components/wallet-selector/wallets/address/index.d.ts.map +1 -0
- package/dist/types/components/wallet-selector/wallets/index.d.ts +5 -0
- package/dist/types/components/wallet-selector/wallets/index.d.ts.map +1 -0
- package/dist/types/components/wallet-selector/wallets/recommended/index.d.ts +23 -0
- package/dist/types/components/wallet-selector/wallets/recommended/index.d.ts.map +1 -0
- package/dist/types/components/wallet-selector/wallets/wagmi/index.d.ts +15 -0
- package/dist/types/components/wallet-selector/wallets/wagmi/index.d.ts.map +1 -0
- package/dist/types/config.d.ts +0 -7
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/state/checkout/store.d.ts +1 -1
- package/dist/types/state/checkout/store.d.ts.map +1 -1
- package/dist/types/themes/default.d.ts.map +1 -1
- package/dist/types/themes/types.d.ts +4 -0
- package/dist/types/themes/types.d.ts.map +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { clsx } from "clsx";
|
|
3
|
+
import { useState, useEffect, useMemo, useContext } from "react";
|
|
4
|
+
import { AsyncButton } from "../../components/buttons/async-button.js";
|
|
5
|
+
import { WalletContext } from "./provider.js";
|
|
6
|
+
const cn = (...inputs) => clsx(inputs);
|
|
7
|
+
const WalletSelector = ({ className, loading: propsLoading, walletProviders, recommendWallets = true, onWalletSelect, transformWallets, }) => {
|
|
8
|
+
const walletContext = useContext(WalletContext);
|
|
9
|
+
const [wallets, setWallets] = useState({});
|
|
10
|
+
const [loading, setLoading] = useState(false);
|
|
11
|
+
const [selectedWallet, setSelectedWallet] = useState(null);
|
|
12
|
+
const [installedWallets] = useMemo(() => {
|
|
13
|
+
const walletValues = transformWallets
|
|
14
|
+
? transformWallets(Object.values(wallets))
|
|
15
|
+
: Object.values(wallets);
|
|
16
|
+
return [
|
|
17
|
+
walletValues.filter((w) => w.installed),
|
|
18
|
+
recommendWallets ? walletValues.filter((w) => !w.installed) : [],
|
|
19
|
+
];
|
|
20
|
+
}, [wallets]);
|
|
21
|
+
const anyLoading = propsLoading || loading;
|
|
22
|
+
const handleWalletSelect = async (wallet) => {
|
|
23
|
+
if (!wallet.renderConfigureStep) {
|
|
24
|
+
await onWalletSelect(wallet);
|
|
25
|
+
walletContext?.setWallet(wallet);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
setSelectedWallet(wallet);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const handleConfigureWallet = async (wallet) => {
|
|
32
|
+
if (wallet) {
|
|
33
|
+
await onWalletSelect(wallet);
|
|
34
|
+
walletContext?.setWallet(wallet);
|
|
35
|
+
}
|
|
36
|
+
setSelectedWallet(null);
|
|
37
|
+
};
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
setLoading(true);
|
|
40
|
+
const tempWallets = {};
|
|
41
|
+
for (const provider of walletProviders) {
|
|
42
|
+
const wallet = provider();
|
|
43
|
+
if (Array.isArray(wallet)) {
|
|
44
|
+
wallet.forEach((w) => {
|
|
45
|
+
tempWallets[w.name] = w;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
else if (wallet) {
|
|
49
|
+
tempWallets[wallet.name] = wallet;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
setWallets(tempWallets);
|
|
53
|
+
setLoading(false);
|
|
54
|
+
}, [walletProviders]);
|
|
55
|
+
if (selectedWallet && selectedWallet.renderConfigureStep) {
|
|
56
|
+
return selectedWallet.renderConfigureStep(handleConfigureWallet);
|
|
57
|
+
}
|
|
58
|
+
return (_jsx("div", { className: cn(className), children: installedWallets.map((w) => (_jsx(AsyncButton, { onAsyncClick: () => handleWalletSelect(w), loadingContent: _jsx("span", { children: "Loading..." }), successContent: _jsx("span", { children: "Connected!" }), errorContent: _jsx("span", { children: "Failed" }), disabled: anyLoading, children: w.name }, w.name))) }));
|
|
59
|
+
};
|
|
60
|
+
export default WalletSelector;
|
|
61
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../../../src/components/wallet-selector/component.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAmB,IAAI,EAAE,MAAM,MAAM,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AAGvE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,EAAE,GAAG,CAAC,GAAG,MAAoB,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAYrD,MAAM,cAAc,GAAG,CAAC,EACtB,SAAS,EACT,OAAO,EAAE,YAAY,EACrB,eAAe,EACf,gBAAgB,GAAG,IAAI,EACvB,cAAc,EACd,gBAAgB,GACI,EAAE,EAAE;IACxB,MAAM,aAAa,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IAEhD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAkC,EAAE,CAAC,CAAC;IAC5E,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAU,KAAK,CAAC,CAAC;IACvD,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAClD,IAAI,CACL,CAAC;IAEF,MAAM,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE;QACtC,MAAM,YAAY,GAAG,gBAAgB;YACnC,CAAC,CAAC,gBAAgB,CAAC,MAAM,CAAC,MAA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AC1B,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;oBACnB,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBAC1B,CAAC,CAAC,CAAC;YACL,CAAC;iBAAM,IAAI,MAAM,EAAE,CAAC;gBAClB,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;YACpC,CAAC;QACH,CAAC;QACD,UAAU,CAAC,WAAW,CAAC,CAAC;QACxB,UAAU,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;IAEtB,IAAI,cAAc,IAAI,cAAc,CAAC,mBAAmB,EAAE,CAAC;QACzD,OAAO,cAAc,CAAC,mBAAmB,CAAC,qBAAqB,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,CACL,cAAK,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,YAC1B,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAC3B,KAAC,WAAW,IAEV,YAAY,EAAE,GAAG,EAAE,CAAC,kBAAkB,CAAC,CAAC,CAAC,EACzC,cAAc,EAAE,wCAAuB,EACvC,cAAc,EAAE,wCAAuB,EACvC,YAAY,EAAE,oCAAmB,EACjC,QAAQ,EAAE,UAAU,YAEnB,CAAC,CAAC,IAAI,IAPF,CAAC,CAAC,IAAI,CAQC,CACf,CAAC,GACE,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain.js","sourceRoot":"","sources":["../../../../src/components/wallet-selector/domain.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Given a config and a list of properties ensure that the properties are defined
|
|
2
|
+
// otherwise throw an error
|
|
3
|
+
// This should return a type safe config object
|
|
4
|
+
export const ensureConfig = (config, properties) => {
|
|
5
|
+
const missingProperties = properties.filter((property) => config[property] === undefined);
|
|
6
|
+
if (missingProperties.length > 0) {
|
|
7
|
+
throw new Error(`Missing properties in config: ${missingProperties.join(", ")}`);
|
|
8
|
+
}
|
|
9
|
+
return config;
|
|
10
|
+
};
|
|
11
|
+
export const normaliseName = (n) => n.toLowerCase().replaceAll(" ", "");
|
|
12
|
+
//# sourceMappingURL=helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../src/components/wallet-selector/helper.ts"],"names":[],"mappings":"AAEA,iFAAiF;AACjF,2BAA2B;AAC3B,+CAA+C;AAC/C,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,MAAuB,EACvB,UAAkB,EAClB,EAAE;IACF,MAAM,iBAAiB,GAAG,UAAU,CAAC,MAAM,CACzC,CAAC,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,SAAS,CAC7C,CAAC;IACF,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CACb,iCAAiC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAChE,CAAC;IACJ,CAAC;IACD,OAAO,MAAoC,CAAC;AAC9C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/wallet-selector/index.tsx"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAK5C,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,CAAC;AACzC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState, createContext } from "react";
|
|
3
|
+
export const WalletContext = createContext({
|
|
4
|
+
wallet: null,
|
|
5
|
+
setWallet: () => { },
|
|
6
|
+
});
|
|
7
|
+
export const WalletProvider = ({ children, }) => {
|
|
8
|
+
const [wallet, setWallet] = useState(null);
|
|
9
|
+
const value = {
|
|
10
|
+
wallet,
|
|
11
|
+
setWallet,
|
|
12
|
+
};
|
|
13
|
+
return (_jsx(WalletContext.Provider, { value: value, children: children }));
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../../src/components/wallet-selector/provider.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAIvD,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAGvC;IACD,MAAM,EAAE,IAAI;IACZ,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC;CACpB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAC7B,QAAQ,GAGT,EAAE,EAAE;IACH,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAyB,IAAI,CAAC,CAAC;IAEnE,MAAM,KAAK,GAAG;QACZ,MAAM;QACN,SAAS;KACV,CAAC;IACF,OAAO,CACL,KAAC,aAAa,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAA0B,CAC1E,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../../../src/components/wallet-selector/schemas.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C;QACE,KAAK,CAAC,qCAAqC,CAAC,CAAC;IAC/C,CAAC;CACF"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
import { immer } from "zustand/middleware/immer";
|
|
3
|
+
export var ACTIONS;
|
|
4
|
+
(function (ACTIONS) {
|
|
5
|
+
ACTIONS["GET_WALLETS"] = "GET_WALLETS";
|
|
6
|
+
})(ACTIONS || (ACTIONS = {}));
|
|
7
|
+
const initialActionState = (initialValue) => Object.values(ACTIONS).reduce((acc, action) => {
|
|
8
|
+
acc[action] = initialValue;
|
|
9
|
+
return acc;
|
|
10
|
+
}, {});
|
|
11
|
+
export const useWalletStore = create()(immer((set, get) => ({
|
|
12
|
+
wallets: {},
|
|
13
|
+
loading: initialActionState(false),
|
|
14
|
+
error: initialActionState(null),
|
|
15
|
+
actions: {
|
|
16
|
+
initialiseWallets: (initialisers) => {
|
|
17
|
+
const ACTION = ACTIONS.GET_WALLETS;
|
|
18
|
+
set((state) => {
|
|
19
|
+
state.loading[ACTION] = true;
|
|
20
|
+
state.error[ACTION] = null;
|
|
21
|
+
});
|
|
22
|
+
try {
|
|
23
|
+
for (const initialiser of initialisers) {
|
|
24
|
+
const wallet = initialiser();
|
|
25
|
+
set((state) => {
|
|
26
|
+
if (Array.isArray(wallet)) {
|
|
27
|
+
wallet.forEach((w) => {
|
|
28
|
+
state.wallets[w.name] = w;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
else if (wallet) {
|
|
32
|
+
state.wallets[wallet.name] = wallet;
|
|
33
|
+
}
|
|
34
|
+
state.loading[ACTION] = false;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return get().wallets;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.error(error);
|
|
41
|
+
set((state) => {
|
|
42
|
+
state.error[ACTION] = {
|
|
43
|
+
id: ACTION,
|
|
44
|
+
title: "Wallet Configure Error",
|
|
45
|
+
message: "Failed to configure wallets",
|
|
46
|
+
};
|
|
47
|
+
state.loading[ACTION] = false;
|
|
48
|
+
});
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
clearError: (action) => {
|
|
53
|
+
set((state) => {
|
|
54
|
+
if (action) {
|
|
55
|
+
delete state.error[action];
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
Object.values(ACTIONS).forEach((key) => {
|
|
59
|
+
delete state.error[key];
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
clearLoading: (action) => {
|
|
65
|
+
set((state) => {
|
|
66
|
+
if (action) {
|
|
67
|
+
state.loading[action] = false;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
Object.values(ACTIONS).forEach((key) => {
|
|
71
|
+
state.loading[key] = false;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
})));
|
|
78
|
+
export const useWalletActions = () => useWalletStore((state) => state.actions);
|
|
79
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../../../src/components/wallet-selector/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAIjD,MAAM,CAAN,IAAY,OAEX;AAFD,WAAY,OAAO;IACjB,sCAA2B,CAAA;AAC7B,CAAC,EAFW,OAAO,KAAP,OAAO,QAElB;AAUD,MAAM,kBAAkB,GAAG,CAAI,YAAe,EAAE,EAAE,CAChD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAC3B,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;IACd,GAAG,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC;IAC3B,OAAO,GAAG,CAAC;AACb,CAAC,EACD,EAAwB,CACzB,CAAC;AAeJ,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gB,GAAG,GAAG,EAAE,CAAC,cAAc,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export class BaseError extends Error {
|
|
2
|
+
}
|
|
3
|
+
export class NotEnoughBalance extends BaseError {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
Object.defineProperty(this, "message", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true,
|
|
10
|
+
value: void 0
|
|
11
|
+
});
|
|
12
|
+
this.message = message;
|
|
13
|
+
this.name = 'NotEnoughBalance';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=exceptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../../../../../src/components/wallet-selector/util/exceptions.ts"],"names":[],"mappings":"AAAA,MAAM,OAAgB,SAAU,SAAQ,KAAK;CAAG;AAEhD,MAAM,OAAO,gBAAiB,SAAQ,SAAS;IAG7C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QAHR;;;;;WAAgB;QAIvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { StyledButton } from "../../../buttons/index.js";
|
|
4
|
+
import { Input } from "../../../inputs/index.js";
|
|
5
|
+
const AddressInput = ({ onConfirm, validate }) => {
|
|
6
|
+
const [address, setAddress] = useState("");
|
|
7
|
+
const [error, setError] = useState(null);
|
|
8
|
+
const handleAddressChange = (event) => {
|
|
9
|
+
setAddress(event.target.value);
|
|
10
|
+
if (validate) {
|
|
11
|
+
setError(validate(event.target.value));
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
return (_jsxs(_Fragment, { children: [_jsx(Input, { type: "text", placeholder: "Your address", value: address, onChange: handleAddressChange }), error && _jsx("p", { className: "mb-2 mt-3 text-sm text-alert-500", children: error }), _jsx(StyledButton, { variant: "primary", onClick: () => onConfirm(address), disabled: !!error, children: "Confirm" })] }));
|
|
15
|
+
};
|
|
16
|
+
export default AddressInput;
|
|
17
|
+
//# sourceMappingURL=addressInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addressInput.js","sourceRoot":"","sources":["../../../../../../src/components/wallet-selector/wallets/address/addressInput.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAOjD,MAAM,YAAY,GAAG,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAS,EAAE,EAAE;IACtD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC3C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC,CAAC;IACxD,MAAM,mBAAmB,GAAG,CAAC,KAA0C,EAAE,EAAE;QACzE,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/B,IAAI,QAAQ,EAAE,CAAC;YACb,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACzC,CAAC;IACH,CAAC,CAAC;IACF,OAAO,CACL,8BACE,KAAC,KAAK,IACJ,IAAI,EAAC,MAAM,EACX,WAAW,EAAC,cAAc,EAC1B,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,mBAAmB,GAC7B,EACD,KAAK,IAAI,YAAG,SAAS,EAAC,kCAAkC,YAAE,KAAK,GAAK,EACrE,KAAC,YAAY,IACX,OAAO,EAAE,SAAS,EAClB,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,EACjC,QAAQ,EAAE,CAAC,CAAC,KAAK,wBAGJ,IACd,CACJ,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import AddressInput from "./addressInput.js";
|
|
3
|
+
import { LinkIcon } from "../../../icons/link.js";
|
|
4
|
+
class AddressWalletInterface {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
Object.defineProperty(this, "name", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true,
|
|
10
|
+
value: void 0
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(this, "icon", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: void 0
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(this, "address", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: void 0
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(this, "installed", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
configurable: true,
|
|
27
|
+
writable: true,
|
|
28
|
+
value: true
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(this, "config", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
configurable: true,
|
|
33
|
+
writable: true,
|
|
34
|
+
value: void 0
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(this, "handleConfigureConfirm", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: true,
|
|
40
|
+
value: (callback, address) => {
|
|
41
|
+
// TODO: Validate?
|
|
42
|
+
this.address = address;
|
|
43
|
+
callback(this);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
this.name = "Send to other address";
|
|
47
|
+
this.icon = _jsx(LinkIcon, {});
|
|
48
|
+
this.address = null;
|
|
49
|
+
this.config = config;
|
|
50
|
+
}
|
|
51
|
+
async connect() {
|
|
52
|
+
return Promise.resolve(this.address);
|
|
53
|
+
}
|
|
54
|
+
async signMessage() {
|
|
55
|
+
return Promise.resolve(null);
|
|
56
|
+
}
|
|
57
|
+
async getAddress() {
|
|
58
|
+
return Promise.resolve(this.address);
|
|
59
|
+
}
|
|
60
|
+
async executeTransfer() {
|
|
61
|
+
return Promise.resolve(null);
|
|
62
|
+
}
|
|
63
|
+
async getBalance() {
|
|
64
|
+
return Promise.resolve({
|
|
65
|
+
uiAmount: null,
|
|
66
|
+
intAmount: null,
|
|
67
|
+
decimals: null,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
renderConfigureStep(callback) {
|
|
71
|
+
return (_jsx(AddressInput, { onConfirm: (address) => this.handleConfigureConfirm(callback, address), validate: this.config?.validate }));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export const AddressWallet = (config) => () => new AddressWalletInterface(config);
|
|
75
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/components/wallet-selector/wallets/address/index.tsx"],"names":[],"mappings":";AAAA,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAG7C,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAMlD,MAAM,sBAAsB;IAO1B,YAAY,MAAe;QAN3B;;;;;WAAa;QACb;;;;;WAAkC;QAClC;;;;;WAAuB;QACvB;;;;mBAAY,IAAI;WAAC;QACjB;;;;;WAAgB;QAiChB;;;;mBAAyB,CACvB,QAA2C,EAC3C,OAAe,EACf,EAAE;gBACF,kBAAkB;g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
+
import { AddressWallet } from "./address/index.js";
|
|
2
|
+
import { RecommendedWalletInterface } from "./recommended/index.js";
|
|
3
|
+
import { WagmiWallets } from "./wagmi/index.js";
|
|
4
|
+
export { AddressWallet, RecommendedWalletInterface, WagmiWallets };
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/components/wallet-selector/wallets/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,aAAa,EAAE,0BAA0B,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dev This is intended to be a placeholder for a recommended wallet.
|
|
3
|
+
*/
|
|
4
|
+
export class RecommendedWalletInterface {
|
|
5
|
+
constructor(name, url, icon, installed = false) {
|
|
6
|
+
Object.defineProperty(this, "name", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true,
|
|
10
|
+
value: ""
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(this, "icon", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: ""
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(this, "url", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: ""
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(this, "installed", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
configurable: true,
|
|
27
|
+
writable: true,
|
|
28
|
+
value: false
|
|
29
|
+
});
|
|
30
|
+
this.name = name;
|
|
31
|
+
this.url = url;
|
|
32
|
+
this.icon = icon;
|
|
33
|
+
this.installed = installed;
|
|
34
|
+
}
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
36
|
+
async connect() {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
40
|
+
async getBalance() {
|
|
41
|
+
return {
|
|
42
|
+
uiAmount: null,
|
|
43
|
+
intAmount: null,
|
|
44
|
+
decimals: null,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
48
|
+
async signMessage() {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
52
|
+
async signTransaction() {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
56
|
+
async getAddress() {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
60
|
+
async executeTransfer() {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/components/wallet-selector/wallets/recommended/index.tsx"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,OAAO,0BAA0B;IAMrC,YACE,IAAY,EACZ,GAAW,EACX,IAAqB,EACrB,SAAS,GAAG,KAAK;QATnB;;;;mBAAO,EAAE;WAAC;QACV;;;;mBAAiC,EAAE;WAAC;QACpC;;;;mBAAM,EAAE;WAAC;QACT;;;;mBAAqB,KAAK;WAAC;QAQzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,OAAO;QACX,OAAO,IAAI,CAAC;IACd,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,UAAU;QACd,OAAO;YACL,QAAQ,EAAE,IAAI;YACd,SAAS,EAAE,IAAI;YACf,QAAQ,EAAE,IAAI;SACf,CAAC;IACJ,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,WAAW;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,eAAe;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,UAAU;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,eAAe;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { connect, disconnect, getAccount, getBalance, getConnectors, getConnectorClient, sendTransaction, signMessage, waitForTransactionReceipt, writeContract, } from "@wagmi/core";
|
|
2
|
+
import { BrowserProvider, JsonRpcSigner } from "ethers";
|
|
3
|
+
import { erc20Abi, formatUnits, zeroAddress } from "viem";
|
|
4
|
+
import { readContract } from "viem/actions";
|
|
5
|
+
import { normaliseName } from "../../helper.js";
|
|
6
|
+
import { NotEnoughBalance } from "../../util/exceptions.js";
|
|
7
|
+
import usdtContractInterface from "./usdt-abi.json" with { type: "json" };
|
|
8
|
+
export const transferNativeCoin = (wagmiConfig, address, amount) => sendTransaction(wagmiConfig, {
|
|
9
|
+
to: address,
|
|
10
|
+
value: BigInt(amount),
|
|
11
|
+
}).catch((e) => {
|
|
12
|
+
console.log("Error", e);
|
|
13
|
+
if (e instanceof Error) {
|
|
14
|
+
if (e.message.includes("transaction exceeds the balance of the account")) {
|
|
15
|
+
throw new Error(`Wallet does not have enough balance to complete the transaction`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
throw e;
|
|
19
|
+
});
|
|
20
|
+
const getAbi = (currency) => {
|
|
21
|
+
if (currency === "USDT") {
|
|
22
|
+
return usdtContractInterface;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return erc20Abi;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const approveTokenTransfer = async (wagmiConfig, amount, spenderAddress, currencyAddress) => {
|
|
29
|
+
/**
|
|
30
|
+
* @dev
|
|
31
|
+
* USDT contract does not have a return value for approve function
|
|
32
|
+
* Viem enforces ERC-20 tokens to have an output of type boolean
|
|
33
|
+
* This causes the approval to fail for USDT
|
|
34
|
+
* As recommended by https://github.com/wevm/viem/issues/663#issuecomment-1581829721
|
|
35
|
+
* We are currently checking if the currency is USDT and modifies the ABI passed
|
|
36
|
+
*/
|
|
37
|
+
const currencyIsUSDT = currencyAddress === "0xdAC17F958D2ee523a2206206994597C13D831ec7";
|
|
38
|
+
const userAddress = getAccount(wagmiConfig).address;
|
|
39
|
+
// Transactions with the native token don't need approval
|
|
40
|
+
if (currencyAddress === zeroAddress || !userAddress) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
// Query the current allowance
|
|
45
|
+
const currentAllowance = await readContract(wagmiConfig.getClient(), {
|
|
46
|
+
address: currencyAddress,
|
|
47
|
+
abi: currencyIsUSDT ? usdtContractInterface : erc20Abi,
|
|
48
|
+
functionName: "allowance",
|
|
49
|
+
args: [userAddress, spenderAddress],
|
|
50
|
+
});
|
|
51
|
+
// If allowance is already sufficient, return early
|
|
52
|
+
if (BigInt(currentAllowance) >= BigInt(amount)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
// Otherwise, proceed with approving the new amount
|
|
56
|
+
const approvalTx = await writeContract(wagmiConfig, {
|
|
57
|
+
address: currencyAddress,
|
|
58
|
+
abi: currencyIsUSDT ? usdtContractInterface : erc20Abi,
|
|
59
|
+
functionName: "approve",
|
|
60
|
+
args: [spenderAddress, BigInt(amount)],
|
|
61
|
+
});
|
|
62
|
+
// wait for transaction confirmation
|
|
63
|
+
await waitForTransactionReceipt(wagmiConfig, {
|
|
64
|
+
hash: approvalTx,
|
|
65
|
+
confirmations: 1,
|
|
66
|
+
chainId: wagmiConfig.state.chainId,
|
|
67
|
+
});
|
|
68
|
+
return approvalTx;
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
console.log("Error", e);
|
|
72
|
+
if (e instanceof Error &&
|
|
73
|
+
e.message.includes("transfer amount exceeds balance")) {
|
|
74
|
+
throw new NotEnoughBalance("Wallet does not have enough balance to complete the transaction");
|
|
75
|
+
}
|
|
76
|
+
throw e;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
export const transferCoins = (wagmiConfig, address, amount, contractAddress, currency) => {
|
|
80
|
+
return writeContract(wagmiConfig, {
|
|
81
|
+
address: contractAddress,
|
|
82
|
+
abi: getAbi(currency),
|
|
83
|
+
functionName: "transfer",
|
|
84
|
+
args: [address, BigInt(amount)],
|
|
85
|
+
}).catch((e) => {
|
|
86
|
+
console.log("Error", e);
|
|
87
|
+
if (e instanceof Error &&
|
|
88
|
+
e.message.includes("transfer amount exceeds balance")) {
|
|
89
|
+
throw new NotEnoughBalance(`Wallet does not have enough ${currency} balance to complete the transaction`);
|
|
90
|
+
}
|
|
91
|
+
throw e;
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
export function clientToSigner(client) {
|
|
95
|
+
const { account, chain, transport } = client;
|
|
96
|
+
const network = {
|
|
97
|
+
chainId: chain.id,
|
|
98
|
+
name: chain.name,
|
|
99
|
+
ensAddress: chain.contracts?.ensRegistry?.address,
|
|
100
|
+
};
|
|
101
|
+
const provider = new BrowserProvider(transport, network);
|
|
102
|
+
const signer = new JsonRpcSigner(provider, account.address);
|
|
103
|
+
return signer;
|
|
104
|
+
}
|
|
105
|
+
class WagmiWalletInterface {
|
|
106
|
+
constructor(connector, wagmiConfig) {
|
|
107
|
+
Object.defineProperty(this, "connector", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
configurable: true,
|
|
110
|
+
writable: true,
|
|
111
|
+
value: void 0
|
|
112
|
+
});
|
|
113
|
+
Object.defineProperty(this, "name", {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
configurable: true,
|
|
116
|
+
writable: true,
|
|
117
|
+
value: void 0
|
|
118
|
+
});
|
|
119
|
+
Object.defineProperty(this, "icon", {
|
|
120
|
+
enumerable: true,
|
|
121
|
+
configurable: true,
|
|
122
|
+
writable: true,
|
|
123
|
+
value: void 0
|
|
124
|
+
});
|
|
125
|
+
Object.defineProperty(this, "installed", {
|
|
126
|
+
enumerable: true,
|
|
127
|
+
configurable: true,
|
|
128
|
+
writable: true,
|
|
129
|
+
value: true
|
|
130
|
+
});
|
|
131
|
+
Object.defineProperty(this, "wagmiConfig", {
|
|
132
|
+
enumerable: true,
|
|
133
|
+
configurable: true,
|
|
134
|
+
writable: true,
|
|
135
|
+
value: void 0
|
|
136
|
+
});
|
|
137
|
+
this.connector = connector;
|
|
138
|
+
this.name = connector.name;
|
|
139
|
+
this.icon = connector.icon;
|
|
140
|
+
this.wagmiConfig = wagmiConfig;
|
|
141
|
+
}
|
|
142
|
+
async connect(networkId) {
|
|
143
|
+
try {
|
|
144
|
+
await disconnect(this.wagmiConfig);
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
// Not connected
|
|
148
|
+
}
|
|
149
|
+
const result = await connect(this.wagmiConfig, {
|
|
150
|
+
chainId: networkId,
|
|
151
|
+
connector: this.connector,
|
|
152
|
+
});
|
|
153
|
+
return result.accounts[0];
|
|
154
|
+
}
|
|
155
|
+
async signMessage(message) {
|
|
156
|
+
return signMessage(this.wagmiConfig, { message });
|
|
157
|
+
}
|
|
158
|
+
async getAddress() {
|
|
159
|
+
return Promise.resolve(getAccount(this.wagmiConfig).address || null);
|
|
160
|
+
}
|
|
161
|
+
async approveTokenTransfer(amount, spenderAddress, currencyAddress) {
|
|
162
|
+
return approveTokenTransfer(this.wagmiConfig, amount, spenderAddress, currencyAddress);
|
|
163
|
+
}
|
|
164
|
+
async executeTransfer(transfer) {
|
|
165
|
+
if (transfer.evm?.implementationAddress === undefined) {
|
|
166
|
+
return transferNativeCoin(this.wagmiConfig, transfer.destinationAddress, transfer.amount);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
return transferCoins(this.wagmiConfig, transfer.destinationAddress, transfer.amount, transfer.evm.implementationAddress, transfer.evm.assetName);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
async getBalance(address, tokenAddress) {
|
|
173
|
+
const chainId = await this.connector.getChainId();
|
|
174
|
+
const balance = await getBalance(this.wagmiConfig, {
|
|
175
|
+
address: address,
|
|
176
|
+
token: tokenAddress,
|
|
177
|
+
chainId,
|
|
178
|
+
});
|
|
179
|
+
return {
|
|
180
|
+
uiAmount: formatUnits(balance.value, balance.decimals),
|
|
181
|
+
intAmount: balance.value,
|
|
182
|
+
decimals: balance.decimals,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
async getSigner() {
|
|
186
|
+
const chainId = await this.connector.getChainId();
|
|
187
|
+
const client = await getConnectorClient(this.wagmiConfig, { chainId });
|
|
188
|
+
return clientToSigner(client);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
export const WagmiWallets = (config, extraConfig) => () => {
|
|
192
|
+
const wallets = getConnectors(config).map((connector) => new WagmiWalletInterface(connector, config));
|
|
193
|
+
const recommendedWallets = extraConfig?.recommendedWallets || [];
|
|
194
|
+
const allowedWallets = extraConfig?.allowedWallets?.map(normaliseName);
|
|
195
|
+
const excludedWallets = extraConfig?.excludedWallets?.map(normaliseName);
|
|
196
|
+
const recommend = (recommendedWallets || []).filter((rw) => wallets.every((w) => normaliseName(w.name) !== normaliseName(rw.name)));
|
|
197
|
+
const allWallets = [...recommend, ...wallets];
|
|
198
|
+
const filteredWallets = allWallets.filter((w) => (!allowedWallets || allowedWallets.includes(normaliseName(w.name))) &&
|
|
199
|
+
(!excludedWallets || !excludedWallets.includes(normaliseName(w.name))));
|
|
200
|
+
filteredWallets.forEach((w) => {
|
|
201
|
+
if (extraConfig?.icons[w.name]) {
|
|
202
|
+
w.icon = extraConfig.icons[w.name];
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
if (allowedWallets) {
|
|
206
|
+
filteredWallets.sort((a, b) => allowedWallets.indexOf(normaliseName(a.name)) -
|
|
207
|
+
allowedWallets.indexOf(normaliseName(b.name)));
|
|
208
|
+
}
|
|
209
|
+
return filteredWallets;
|
|
210
|
+
};
|
|
211
|
+
//# sourceMappingURL=index.js.map
|