@1001-digital/layers.evm 0.0.6 → 0.0.8

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.
@@ -1,7 +1,12 @@
1
1
  <template>
2
- <slot :start="start" name="start"></slot>
3
-
4
- <Dialog v-model:open="open" :x-close="false" class="transaction-flow">
2
+ <slot :start="start" :step="step" :open="open" name="start"></slot>
3
+
4
+ <Dialog
5
+ v-model:open="open"
6
+ :x-close="canDismiss"
7
+ :click-outside="canDismiss"
8
+ class="transaction-flow"
9
+ >
5
10
  <slot name="before" />
6
11
 
7
12
  <h1 v-if="text.title[step]">{{ text.title[step] }}</h1>
@@ -13,7 +18,12 @@
13
18
 
14
19
  <slot :name="step" :cancel="cancel"></slot>
15
20
 
16
- <Button v-if="step === 'waiting'" :to="txLink" target="_blank" class="block-explorer">
21
+ <Button
22
+ v-if="step === 'waiting'"
23
+ :to="txLink"
24
+ target="_blank"
25
+ class="block-explorer"
26
+ >
17
27
  <Icon type="loader" class="spin" />
18
28
  <span>View on Block Explorer</span>
19
29
  </Button>
@@ -24,85 +34,95 @@
24
34
 
25
35
  <Actions v-if="step === 'confirm' || step === 'error'">
26
36
  <Button @click="cancel" class="secondary">Cancel</Button>
27
- <Button @click="() => initializeRequest()">{{ text.action[step] || 'Execute' }}</Button>
37
+ <Button @click="() => initializeRequest()">{{
38
+ text.action[step] || "Execute"
39
+ }}</Button>
28
40
  </Actions>
29
41
  </Dialog>
30
42
  </template>
31
43
 
32
44
  <script setup lang="ts">
33
- import { waitForTransactionReceipt, watchChainId } from '@wagmi/core'
34
- import type { Config } from '@wagmi/vue'
35
- import type { TransactionReceipt, Hash } from 'viem'
45
+ import { waitForTransactionReceipt, watchChainId } from "@wagmi/core";
46
+ import type { Config } from "@wagmi/vue";
47
+ import type { TransactionReceipt, Hash } from "viem";
36
48
 
37
49
  interface TextConfig {
38
- title: Record<string, string>
39
- lead: Record<string, string>
40
- action: Record<string, string>
50
+ title: Record<string, string>;
51
+ lead: Record<string, string>;
52
+ action: Record<string, string>;
41
53
  }
42
54
 
43
- const checkChain = useEnsureChainIdCheck()
44
-
45
- const { $wagmi } = useNuxtApp()
46
- const config = useRuntimeConfig()
47
-
48
- const props = withDefaults(defineProps<{
49
- text?: TextConfig
50
- request?: () => Promise<Hash>
51
- delayAfter?: number
52
- delayAutoclose?: number
53
- skipConfirmation?: boolean
54
- autoCloseSuccess?: boolean
55
- }>(), {
56
- text: () => ({
57
- title: {
58
- confirm: 'Confirm Transaction',
59
- },
60
- lead: {
61
- confirm: 'Please review and confirm this transaction.',
62
- },
63
- action: {
64
- confirm: 'Execute',
65
- },
66
- }),
67
- delayAfter: 2000,
68
- delayAutoclose: 2000,
69
- skipConfirmation: false,
70
- autoCloseSuccess: false,
71
- })
55
+ const checkChain = useEnsureChainIdCheck();
56
+
57
+ const { $wagmi } = useNuxtApp();
58
+ const config = useRuntimeConfig();
59
+
60
+ const props = withDefaults(
61
+ defineProps<{
62
+ text?: TextConfig;
63
+ request?: () => Promise<Hash>;
64
+ delayAfter?: number;
65
+ delayAutoclose?: number;
66
+ skipConfirmation?: boolean;
67
+ autoCloseSuccess?: boolean;
68
+ dismissable?: boolean;
69
+ }>(),
70
+ {
71
+ text: () => ({
72
+ title: {
73
+ confirm: "Confirm Transaction",
74
+ },
75
+ lead: {
76
+ confirm: "Please review and confirm this transaction.",
77
+ },
78
+ action: {
79
+ confirm: "Execute",
80
+ },
81
+ }),
82
+ delayAfter: 2000,
83
+ delayAutoclose: 2000,
84
+ skipConfirmation: false,
85
+ autoCloseSuccess: true,
86
+ dismissable: true,
87
+ },
88
+ );
72
89
 
73
90
  const emit = defineEmits<{
74
- complete: [receipt: TransactionReceipt]
75
- cancel: []
76
- }>()
91
+ complete: [receipt: TransactionReceipt];
92
+ cancel: [];
93
+ }>();
77
94
 
78
- const open = ref(false)
95
+ const open = ref(false);
79
96
 
80
- const switchChain = ref(false)
97
+ const switchChain = ref(false);
81
98
  watchChainId($wagmi as Config, {
82
99
  async onChange() {
83
- if (!switchChain.value) return
100
+ if (!switchChain.value) return;
84
101
 
85
102
  if (await checkChain()) {
86
- switchChain.value = false
87
- initializeRequest()
103
+ switchChain.value = false;
104
+ initializeRequest();
88
105
  } else {
89
- switchChain.value = true
106
+ switchChain.value = true;
90
107
  }
91
108
  },
92
- })
109
+ });
93
110
 
94
- const cachedRequest = ref(props.request)
95
- watch(() => props.request, () => {
96
- cachedRequest.value = props.request
97
- })
111
+ const cachedRequest = ref(props.request);
112
+ watch(
113
+ () => props.request,
114
+ () => {
115
+ cachedRequest.value = props.request;
116
+ },
117
+ );
98
118
 
99
- const requesting = ref(false)
100
- const waiting = ref(false)
101
- const complete = ref(false)
102
- const error = ref('')
103
- const tx = ref<Hash | null>(null)
104
- const receipt = ref<TransactionReceipt | null>(null)
105
- const txLink = computed(() => `${config.public.blockExplorer}/tx/${tx.value}`)
119
+ const requesting = ref(false);
120
+ const waiting = ref(false);
121
+ const complete = ref(false);
122
+ const error = ref("");
123
+ const tx = ref<Hash | null>(null);
124
+ const receipt = ref<TransactionReceipt | null>(null);
125
+ const txLink = computed(() => `${config.public.blockExplorer}/tx/${tx.value}`);
106
126
 
107
127
  const step = computed(() => {
108
128
  if (
@@ -112,96 +132,100 @@ const step = computed(() => {
112
132
  !waiting.value &&
113
133
  !complete.value
114
134
  ) {
115
- return 'confirm'
135
+ return "confirm";
116
136
  }
117
137
 
118
138
  if (switchChain.value) {
119
- return 'chain'
139
+ return "chain";
120
140
  }
121
141
 
122
142
  if (requesting.value) {
123
- return 'requesting'
143
+ return "requesting";
124
144
  }
125
145
 
126
146
  if (waiting.value) {
127
- return 'waiting'
147
+ return "waiting";
128
148
  }
129
149
 
130
150
  if (complete.value) {
131
- return 'complete'
151
+ return "complete";
132
152
  }
133
153
 
134
- return 'error'
135
- })
154
+ return "error";
155
+ });
156
+
157
+ const canDismiss = computed(
158
+ () => props.dismissable && step.value !== "requesting",
159
+ );
136
160
 
137
161
  const initializeRequest = async (request = cachedRequest.value) => {
138
- cachedRequest.value = request
139
- complete.value = false
140
- open.value = true
141
- error.value = ''
142
- tx.value = null
143
- receipt.value = null
162
+ cachedRequest.value = request;
163
+ complete.value = false;
164
+ open.value = true;
165
+ error.value = "";
166
+ tx.value = null;
167
+ receipt.value = null;
144
168
 
145
169
  if (!(await checkChain())) {
146
- switchChain.value = true
147
- return
170
+ switchChain.value = true;
171
+ return;
148
172
  } else {
149
- switchChain.value = false
173
+ switchChain.value = false;
150
174
  }
151
175
 
152
- if (requesting.value) return
176
+ if (requesting.value) return;
153
177
 
154
178
  try {
155
- requesting.value = true
156
- tx.value = await request!()
157
- requesting.value = false
158
- waiting.value = true
179
+ requesting.value = true;
180
+ tx.value = await request!();
181
+ requesting.value = false;
182
+ waiting.value = true;
159
183
  const [receiptObject] = await Promise.all([
160
184
  waitForTransactionReceipt($wagmi as Config, { hash: tx.value }),
161
- ])
162
- await delay(props.delayAfter)
163
- receipt.value = receiptObject
164
- emit('complete', receiptObject)
165
- complete.value = true
185
+ ]);
186
+ await delay(props.delayAfter);
187
+ receipt.value = receiptObject;
188
+ emit("complete", receiptObject);
189
+ complete.value = true;
166
190
  } catch (e: unknown) {
167
- const err = e as { cause?: { code?: number }; shortMessage?: string }
191
+ const err = e as { cause?: { code?: number }; shortMessage?: string };
168
192
  if (err?.cause?.code === 4001) {
169
- open.value = false
193
+ open.value = false;
170
194
  } else {
171
- error.value = err.shortMessage || 'Error submitting transaction request.'
195
+ error.value = err.shortMessage || "Error submitting transaction request.";
172
196
  }
173
- console.log(e)
197
+ console.log(e);
174
198
  }
175
199
 
176
- requesting.value = false
177
- waiting.value = false
200
+ requesting.value = false;
201
+ waiting.value = false;
178
202
 
179
- if (props.autoCloseSuccess && step.value === 'complete') {
180
- await delay(props.delayAutoclose)
181
- open.value = false
182
- await delay(300)
203
+ if (props.autoCloseSuccess && step.value === "complete") {
204
+ await delay(props.delayAutoclose);
205
+ open.value = false;
206
+ await delay(300);
183
207
  }
184
208
 
185
- return receipt.value
186
- }
209
+ return receipt.value;
210
+ };
187
211
 
188
212
  const start = () => {
189
213
  if (props.skipConfirmation && !open.value) {
190
- initializeRequest()
214
+ initializeRequest();
191
215
  }
192
216
 
193
- open.value = true
194
- }
217
+ open.value = true;
218
+ };
195
219
 
196
220
  const cancel = () => {
197
- open.value = false
221
+ open.value = false;
198
222
 
199
- emit('cancel')
200
- }
223
+ emit("cancel");
224
+ };
201
225
 
202
226
  defineExpose({
203
227
  initializeRequest,
204
- })
228
+ });
205
229
  </script>
206
230
 
207
231
  <style>
package/package.json CHANGED
@@ -1,28 +1,28 @@
1
1
  {
2
2
  "name": "@1001-digital/layers.evm",
3
3
  "type": "module",
4
- "version": "0.0.6",
4
+ "version": "0.0.8",
5
5
  "main": "./nuxt.config.ts",
6
6
  "devDependencies": {
7
7
  "@nuxt/eslint": "latest",
8
8
  "@types/node": "^24.10.4",
9
9
  "eslint": "^9.39.2",
10
- "nuxt": "^4.2.2",
10
+ "nuxt": "^4.3.0",
11
11
  "typescript": "^5.9.3",
12
12
  "vue": "latest",
13
- "@1001-digital/layers.base": "^0.0.13"
13
+ "@1001-digital/layers.base": "^0.0.17"
14
14
  },
15
15
  "peerDependencies": {
16
- "@1001-digital/layers.base": "^0.0.13"
16
+ "@1001-digital/layers.base": "^0.0.17"
17
17
  },
18
18
  "dependencies": {
19
19
  "@types/qrcode": "^1.5.6",
20
- "@metamask/sdk": "~0.33.1",
21
- "@tanstack/vue-query": "^5.92.1",
22
- "@wagmi/vue": "^0.4.3",
23
- "@walletconnect/ethereum-provider": "~2.21.1",
20
+ "@metamask/sdk": "~0.34.0",
21
+ "@tanstack/vue-query": "^5.92.9",
22
+ "@wagmi/vue": "^0.4.15",
23
+ "@walletconnect/ethereum-provider": "~2.23.4",
24
24
  "qrcode": "^1.5.4",
25
- "viem": "~2.42.1"
25
+ "viem": "~2.45.1"
26
26
  },
27
27
  "scripts": {
28
28
  "dev": "nuxi dev .playground",