Skip to content

Commit bb17187

Browse files
committed
fix v0.0.3
1 parent c499b22 commit bb17187

File tree

5 files changed

+129
-87
lines changed

5 files changed

+129
-87
lines changed

dist/vue-web3-auth.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as Chains from '@wagmi/core/chains';
44
import type { ComputedRef } from 'vue';
55
import type { Plugin as Plugin_2 } from 'vue';
66
import type { ThemeCtrlState } from '@web3modal/core';
7+
import type { TransactionReceipt } from 'viem';
78

89
export declare function $off(event: Events, callback: (...args: any) => void): void;
910

@@ -166,4 +167,22 @@ export declare function shortAddressFilter(value?: string): string;
166167

167168
export declare function switchChain(newChain: Chain): Promise<void>;
168169

170+
declare type WriteContract = {
171+
chainId?: number;
172+
address: `0x${string}`;
173+
abi: any;
174+
functionName: string;
175+
args?: any[];
176+
account?: `0x${string}`;
177+
gas?: bigint;
178+
gasPrice?: bigint;
179+
maxFeePerGas?: bigint;
180+
maxPriorityFeePerGas?: bigint;
181+
nonce?: number;
182+
value?: bigint;
183+
confirmations?: number;
184+
};
185+
186+
export declare function writeContract(data: WriteContract): Promise<TransactionReceipt>;
187+
169188
export { }

dist/vue-web3-auth.js

Lines changed: 106 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import * as P from "@wagmi/core/chains";
2-
import { reactive as m, computed as w, ref as k, watch as C, toRaw as h } from "vue";
3-
import { disconnect as M, configureChains as v, createConfig as $, watchNetwork as I, watchAccount as E, readContract as S, multicall as x } from "@wagmi/core";
4-
import { w3mProvider as U, w3mConnectors as D, EthereumClient as N } from "@web3modal/ethereum";
5-
import { Web3Modal as _ } from "@web3modal/html";
6-
import j from "js-event-bus";
7-
var A = {
1+
import * as J from "@wagmi/core/chains";
2+
import { reactive as m, computed as k, ref as M, watch as g, toRaw as h } from "vue";
3+
import { disconnect as v, configureChains as $, createConfig as I, watchNetwork as E, watchAccount as x, readContract as N, writeContract as S, waitForTransaction as U, multicall as D } from "@wagmi/core";
4+
import { w3mProvider as F, w3mConnectors as _, EthereumClient as j } from "@web3modal/ethereum";
5+
import { Web3Modal as P } from "@web3modal/html";
6+
import A from "js-event-bus";
7+
var H = {
88
id: 1,
99
network: "homestead",
1010
name: "Ethereum",
@@ -49,10 +49,10 @@ var A = {
4949
}
5050
}
5151
};
52-
const F = A, n = m({
52+
const V = H, t = m({
5353
autoInit: !0,
5454
projectId: "",
55-
chains: [F],
55+
chains: [V],
5656
autoConnect: !0,
5757
disconnectUnknownChain: !0,
5858
reconnectToChain: !0,
@@ -62,51 +62,51 @@ const F = A, n = m({
6262
themeVariables: {}
6363
}
6464
});
65-
function H(e) {
66-
"autoInit" in e && (n.autoInit = e.autoInit), "projectId" in e && (n.projectId = e.projectId), "chains" in e && (n.chains = e.chains), "autoConnect" in e && (n.autoConnect = e.autoConnect), "disconnectUnknownChain" in e && (n.disconnectUnknownChain = e.disconnectUnknownChain), "reconnectToChain" in e && (n.reconnectToChain = e.reconnectToChain), "logEnabled" in e && (n.logEnabled = e.logEnabled), "web3modalOptions" in e && ("themeMode" in e.web3modalOptions && (n.web3modalOptions.themeMode = e.web3modalOptions.themeMode), "themeVariables" in e.web3modalOptions && (n.web3modalOptions.themeVariables = e.web3modalOptions.themeVariables));
65+
function G(e) {
66+
"autoInit" in e && (t.autoInit = e.autoInit), "projectId" in e && (t.projectId = e.projectId), "chains" in e && (t.chains = e.chains), "autoConnect" in e && (t.autoConnect = e.autoConnect), "disconnectUnknownChain" in e && (t.disconnectUnknownChain = e.disconnectUnknownChain), "reconnectToChain" in e && (t.reconnectToChain = e.reconnectToChain), "logEnabled" in e && (t.logEnabled = e.logEnabled), "web3modalOptions" in e && ("themeMode" in e.web3modalOptions && (t.web3modalOptions.themeMode = e.web3modalOptions.themeMode), "themeVariables" in e.web3modalOptions && (t.web3modalOptions.themeVariables = e.web3modalOptions.themeVariables));
6767
}
6868
const c = m({
6969
bufferChain: null,
7070
currentChain: null
71-
}), V = w(() => c.currentChain ? c.currentChain : n.chains[0]);
72-
function Y() {
73-
return n.chains;
71+
}), f = k(() => c.currentChain ? c.currentChain : t.chains[0]);
72+
function O() {
73+
return t.chains;
7474
}
75-
async function Z(e) {
76-
var t;
77-
o.value || b(), await ((t = g.client) == null ? void 0 : t.switchNetwork({ chainId: e.id }));
75+
async function B(e) {
76+
var n;
77+
o.value || b(), await ((n = w.client) == null ? void 0 : n.switchNetwork({ chainId: e.id }));
7878
}
79-
async function O() {
79+
async function ee() {
8080
var e;
8181
o.value || b(), await ((e = o.value) == null ? void 0 : e.openModal({
8282
route: "SelectNetwork"
8383
}));
8484
}
85-
function l(...e) {
86-
n.logEnabled && console.log("[WC]", ...e);
85+
function r(...e) {
86+
t.logEnabled && console.log("[WC]", ...e);
8787
}
8888
var s = /* @__PURE__ */ ((e) => (e.Connected = "connected", e.Disconnected = "disconnect", e.ChainSwitched = "chain_switched", e.UnknownChain = "unknown_chain", e.ModalStateChanged = "modal_state_changed", e))(s || {});
89-
const f = new j();
90-
function r(e, ...t) {
91-
e === s.Connected || e === s.Disconnected ? (c.currentChain = c.bufferChain, d.currentAccount = d.bufferAccount) : e === s.ChainSwitched && (c.currentChain = c.bufferChain), f.emit(e, null, ...t);
89+
const T = new A();
90+
function l(e, ...n) {
91+
e === s.Connected || e === s.Disconnected ? (c.currentChain = c.bufferChain, d.currentAccount = d.bufferAccount) : e === s.ChainSwitched && (c.currentChain = c.bufferChain), T.emit(e, null, ...n);
9292
}
93-
function B(e, t) {
94-
f.on(e, t), n.logEnabled && l(`Subscribe for ${e} event.`);
93+
function ne(e, n) {
94+
T.on(e, n), t.logEnabled && r(`Subscribe for ${e} event.`);
9595
}
96-
function ee(e, t) {
97-
f.detach(e, t), n.logEnabled && l(`Unsubscribe for ${e} event.`);
96+
function te(e, n) {
97+
T.detach(e, n), t.logEnabled && r(`Unsubscribe for ${e} event.`);
9898
}
99-
const o = k(null);
99+
const o = M(null);
100100
function W(e) {
101-
var t;
102-
o.value = new _(
101+
var n;
102+
o.value = new P(
103103
{
104-
projectId: n.projectId,
105-
...(n == null ? void 0 : n.web3modalOptions) || []
104+
projectId: t.projectId,
105+
...(t == null ? void 0 : t.web3modalOptions) || []
106106
},
107107
e
108-
), (t = o.value) == null || t.subscribeModal(({ open: a }) => {
109-
r(s.ModalStateChanged, a);
108+
), (n = o.value) == null || n.subscribeModal(({ open: a }) => {
109+
l(s.ModalStateChanged, a);
110110
});
111111
}
112112
const d = m({
@@ -118,15 +118,15 @@ const d = m({
118118
shortAddress: void 0
119119
});
120120
async function L() {
121-
await M();
121+
await v();
122122
}
123-
async function te(e) {
124-
var t, a;
125-
o.value || b(), e instanceof Event && (e = n.chains[0]), (t = o.value) == null || t.setDefaultChain(e || n.chains[0]), await ((a = o.value) == null ? void 0 : a.openModal({
123+
async function ae(e) {
124+
var n, a;
125+
o.value || b(), e instanceof Event && (e = t.chains[0]), (n = o.value) == null || n.setDefaultChain(e || t.chains[0]), await ((a = o.value) == null ? void 0 : a.openModal({
126126
route: "ConnectWallet"
127127
}));
128128
}
129-
async function ne() {
129+
async function ie() {
130130
var e;
131131
o.value || b(), await ((e = o.value) == null ? void 0 : e.openModal({
132132
route: "Account"
@@ -135,57 +135,57 @@ async function ne() {
135135
function R(e = "") {
136136
return `${e.slice(0, 5)}...${e.slice(-4)}`;
137137
}
138-
C(() => d.currentAccount, (e) => {
138+
g(() => d.currentAccount, (e) => {
139139
e ? (u.connected = !0, u.address = e.address, u.shortAddress = R(e.address)) : (u.connected = !1, u.address = void 0, u.shortAddress = void 0);
140140
});
141-
let T;
142-
const g = m({
141+
let C;
142+
const w = m({
143143
client: null
144144
});
145145
function y(e) {
146146
return String(e).toLowerCase();
147147
}
148-
async function z([e, t], [a, i]) {
149-
if (n.disconnectUnknownChain && (!a && n.disconnectUnknownChain || a) && t && !n.chains.some((p) => p.id === t.id)) {
150-
await L(), i && (r(s.Disconnected), l(`account ${e.address} disconnected from ${y(i.name)} chain.`)), r(s.UnknownChain, { chain: t }), l("switched to unsupported chain.");
148+
async function z([e, n], [a, i]) {
149+
if (t.disconnectUnknownChain && (!a && t.disconnectUnknownChain || a) && n && !t.chains.some((p) => p.id === n.id)) {
150+
await L(), i && (l(s.Disconnected), r(`account ${e.address} disconnected from ${y(i.name)} chain.`)), l(s.UnknownChain, { chain: n }), r("switched to unsupported chain.");
151151
return;
152152
}
153-
(a == null ? void 0 : a.address) !== (e == null ? void 0 : e.address) && !(i != null && i.unsupported) && (a && (r(s.Disconnected), l(`account ${a.address} disconnected from ${y(i.name)} chain.`)), e && (r(s.Connected, { chain: c.bufferChain, account: d.bufferAccount }), l(`account ${e.address} connected to ${y(t.name)} chain.`))), i && t && i.id !== t.id && (n.reconnectToChain ? (r(s.Disconnected), l(`account ${a.address} disconnected from ${y(i.name)} chain.`), r(s.Connected, { chain: c.bufferChain, account: d.bufferAccount }), l(`account ${e.address} connected to ${y(t.name)} chain.`)) : (r(s.ChainSwitched, { chain: t }), l(`account ${e.address} switched to ${y(t.name)} chain.`)));
153+
(a == null ? void 0 : a.address) !== (e == null ? void 0 : e.address) && !(i != null && i.unsupported) && (a && (l(s.Disconnected), r(`account ${a.address} disconnected from ${y(i.name)} chain.`)), e && (l(s.Connected, { chain: c.bufferChain, account: d.bufferAccount }), r(`account ${e.address} connected to ${y(n.name)} chain.`))), i && n && i.id !== n.id && (t.reconnectToChain ? (l(s.Disconnected), r(`account ${a.address} disconnected from ${y(i.name)} chain.`), l(s.Connected, { chain: c.bufferChain, account: d.bufferAccount }), r(`account ${e.address} connected to ${y(n.name)} chain.`)) : (l(s.ChainSwitched, { chain: n }), r(`account ${e.address} switched to ${y(n.name)} chain.`)));
154154
}
155-
function G([e, t], [a, i]) {
156-
clearTimeout(T), T = setTimeout(z, 200, [e, t], [a, i]);
155+
function q([e, n], [a, i]) {
156+
clearTimeout(C), C = setTimeout(z, 200, [e, n], [a, i]);
157157
}
158158
function b() {
159159
if (o.value)
160160
return;
161-
const { publicClient: e } = v(h(n.chains), [U({ projectId: n.projectId })]), t = $({
162-
autoConnect: n.autoConnect,
163-
connectors: D({
164-
projectId: n.projectId,
161+
const { publicClient: e } = $(h(t.chains), [F({ projectId: t.projectId })]), n = I({
162+
autoConnect: t.autoConnect,
163+
connectors: _({
164+
projectId: t.projectId,
165165
version: 2,
166-
chains: h(n.chains)
166+
chains: h(t.chains)
167167
}),
168168
publicClient: e
169169
});
170-
I((i) => {
170+
E((i) => {
171171
var p;
172172
(p = i.chain) != null && p.unsupported && (i.chain.name = "Unsupported"), c.bufferChain = i.chain || null;
173-
}), E((i) => {
173+
}), x((i) => {
174174
d.bufferAccount = i.address ? i : null;
175-
}), C([() => d.bufferAccount, () => c.bufferChain], G);
176-
const a = new N(t, h(n.chains));
177-
g.client = a, W(a);
175+
}), g([() => d.bufferAccount, () => c.bufferChain], q);
176+
const a = new j(n, h(t.chains));
177+
w.client = a, W(a);
178178
}
179-
function ae(e) {
179+
function se(e) {
180180
return {
181181
install() {
182-
H(e), b();
182+
G(e), b();
183183
}
184184
};
185185
}
186-
async function ie(e) {
187-
return S({
188-
chainId: e.chainId || V.value.id,
186+
async function oe(e) {
187+
return N({
188+
chainId: e.chainId || f.value.id,
189189
address: e.address,
190190
abi: e.abi,
191191
functionName: e.functionName,
@@ -195,28 +195,49 @@ async function ie(e) {
195195
blockTag: e.blockTag
196196
});
197197
}
198-
async function se(e) {
199-
const t = [];
198+
async function ce(e) {
199+
const { hash: n } = await S({
200+
chainId: e.chainId || f.value.id,
201+
address: e.address,
202+
abi: e.abi,
203+
functionName: e.functionName,
204+
args: e.args || [],
205+
account: e.account || u.address,
206+
gas: e.gas,
207+
gasPrice: e.gasPrice,
208+
maxFeePerGas: e.maxFeePerGas,
209+
maxPriorityFeePerGas: e.maxPriorityFeePerGas,
210+
nonce: e.nonce,
211+
value: e.value
212+
});
213+
return U({
214+
chainId: e.chainId || f.value.id,
215+
hash: n,
216+
confirmations: e.confirmations || 1
217+
});
218+
}
219+
async function re(e) {
220+
const n = [];
200221
return e.calls.forEach((a) => {
201222
a.calls.forEach(([i, p]) => {
202-
t.push({
223+
n.push({
203224
address: a.contractAddress,
204225
abi: a.abi,
205226
functionName: i,
206227
args: p
207228
});
208229
});
209-
}), await x({
230+
}), await D({
210231
chainId: e.chainId,
211-
contracts: t,
232+
contracts: n,
212233
multicallAddress: e.multicallAddress,
213234
blockTag: e.blockTag,
214235
blockNumber: e.blockNumber,
215236
batchSize: e.batchSize,
216237
allowFailure: e.allowFailure
217238
});
218239
}
219-
const oe = [
240+
const le = [
220241
{
221242
inputs: [
222243
{ internalType: "string", name: "name_", type: "string" },
@@ -410,7 +431,7 @@ const oe = [
410431
stateMutability: "nonpayable",
411432
type: "function"
412433
}
413-
], ce = [
434+
], ue = [
414435
{
415436
inputs: [
416437
{
@@ -552,22 +573,23 @@ const oe = [
552573
}
553574
];
554575
export {
555-
ee as $off,
556-
B as $on,
557-
P as Chains,
576+
te as $off,
577+
ne as $on,
578+
J as Chains,
558579
s as Events,
559580
u as account,
560-
ne as accountDetails,
561-
V as chain,
562-
te as connect,
563-
ae as createWeb3Auth,
581+
ie as accountDetails,
582+
f as chain,
583+
ae as connect,
584+
se as createWeb3Auth,
564585
L as disconnect,
565-
oe as erc20ABI,
566-
Y as getAvailableChains,
567-
se as multicall,
568-
ce as multicallABI,
569-
ie as readContract,
570-
O as selectChain,
586+
le as erc20ABI,
587+
O as getAvailableChains,
588+
re as multicall,
589+
ue as multicallABI,
590+
oe as readContract,
591+
ee as selectChain,
571592
R as shortAddressFilter,
572-
Z as switchChain
593+
B as switchChain,
594+
ce as writeContract
573595
};

0 commit comments

Comments
 (0)