24
24
<script lang="ts" setup>
25
25
import { ref , onMounted } from ' vue'
26
26
import { UndefinedOr , whenDefined , whenDefinedAll } from ' @devprotocol/util-ts'
27
- import { bytes32Hex , ClubsOffering , i18nFactory } from ' @devprotocol/clubs-core'
27
+ import {
28
+ bytes32Hex ,
29
+ ClubsOffering ,
30
+ i18nFactory ,
31
+ Signal ,
32
+ } from ' @devprotocol/clubs-core'
28
33
import { Strings } from ' ./i18n'
29
34
import { Signer } from ' ethers'
30
35
import { PluginId } from ' ./constants'
31
36
import { IconBouncingArrowRight } from ' @devprotocol/clubs-core/ui/vue'
37
+ import type { connection as ConnectionType } from ' @devprotocol/clubs-core/connection'
32
38
33
39
const props = defineProps <{
34
40
payload: ClubsOffering [' payload' ]
@@ -43,12 +49,16 @@ const completed = ref(false)
43
49
const error = ref <string | undefined >(undefined )
44
50
const i18nBase = i18nFactory (Strings )
45
51
const i18n = ref (i18nBase ([' en' ]))
52
+ const clubsConnection = ref <ReturnType <typeof ConnectionType >>()
46
53
const message = ` Add Cart: ${bytes32Hex (props .payload )} `
47
54
48
55
let signer: Signer | undefined
49
56
50
57
const onClick = async () => {
51
58
loading .value = true
59
+ if (! signer ) {
60
+ return clubsConnection .value ?.signal .next (Signal .SignInRequest )
61
+ }
52
62
const signature = await signer ?.signMessage (message )
53
63
const url = new URL (` ${props .base }/api/${PluginId }/cart ` )
54
64
@@ -81,6 +91,8 @@ onMounted(async () => {
81
91
i18n .value = i18nBase (navigator .languages )
82
92
const { connection } = await import (' @devprotocol/clubs-core/connection' )
83
93
94
+ clubsConnection .value = connection ()
95
+
84
96
connection ().account .subscribe (async (acc ) => {
85
97
account .value = acc
86
98
})
0 commit comments