Skip to content

Commit 4013bd1

Browse files
committed
refactor: reorganize imports and enhance signer check in CartButton component
1 parent fea3dd1 commit 4013bd1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/CartButton.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@
2424
<script lang="ts" setup>
2525
import { ref, onMounted } from 'vue'
2626
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'
2833
import { Strings } from './i18n'
2934
import { Signer } from 'ethers'
3035
import { PluginId } from './constants'
3136
import { IconBouncingArrowRight } from '@devprotocol/clubs-core/ui/vue'
37+
import type { connection as ConnectionType } from '@devprotocol/clubs-core/connection'
3238
3339
const props = defineProps<{
3440
payload: ClubsOffering['payload']
@@ -43,12 +49,16 @@ const completed = ref(false)
4349
const error = ref<string | undefined>(undefined)
4450
const i18nBase = i18nFactory(Strings)
4551
const i18n = ref(i18nBase(['en']))
52+
const clubsConnection = ref<ReturnType<typeof ConnectionType>>()
4653
const message = `Add Cart: ${bytes32Hex(props.payload)}`
4754
4855
let signer: Signer | undefined
4956
5057
const onClick = async () => {
5158
loading.value = true
59+
if (!signer) {
60+
return clubsConnection.value?.signal.next(Signal.SignInRequest)
61+
}
5262
const signature = await signer?.signMessage(message)
5363
const url = new URL(`${props.base}/api/${PluginId}/cart`)
5464
@@ -81,6 +91,8 @@ onMounted(async () => {
8191
i18n.value = i18nBase(navigator.languages)
8292
const { connection } = await import('@devprotocol/clubs-core/connection')
8393
94+
clubsConnection.value = connection()
95+
8496
connection().account.subscribe(async (acc) => {
8597
account.value = acc
8698
})

0 commit comments

Comments
 (0)