-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(subscriptions): Basic frontend working with Hold subscriptions
- Loading branch information
1 parent
7958888
commit f977946
Showing
12 changed files
with
170 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# Use the testnet in development | ||
# ALEPH_API_URL=https://api.twentysix.testnet.network | ||
|
||
# APIs | ||
LTAI_SUBSCRIPTIONS_API_URL=http://localhost:8000 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { boot } from 'quasar/wrappers'; | ||
import { client } from 'src/apis/subscriptions/services.gen'; | ||
|
||
export default boot(() => { | ||
client.setConfig({ | ||
baseURL: process.env.LTAI_SUBSCRIPTIONS_API_URL, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<template> | ||
<section class="max-sm:tw-mx-4 sm:tw-mx-10 tw-my-5"> | ||
<q-linear-progress v-if="!subscriptionsStore.isLoaded" indeterminate /> | ||
<p v-else-if="subscriptionsStore.subscriptions.length === 0">No subscriptions</p> | ||
<div v-for="subscription of subscriptionsStore.subscriptions" v-else :key="subscription.id"> | ||
<p>{{ subscription.type }} {{ subscription.provider }}</p> | ||
</div> | ||
|
||
<q-btn | ||
class="border-primary-highlight" | ||
no-caps | ||
rounded | ||
text-color="dark-mode-text" | ||
unelevated | ||
@click="subscriptionsStore.holdSubscribe('standard')" | ||
> | ||
New standard hold subscription | ||
</q-btn> | ||
</section> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { onMounted } from 'vue'; | ||
import { useAccount } from '@wagmi/vue'; | ||
import { useRouter } from 'vue-router'; | ||
import { useQuasar } from 'quasar'; | ||
import { useSubscriptionStore } from 'stores/subscription'; | ||
const $q = useQuasar(); | ||
const router = useRouter(); | ||
const account = useAccount(); | ||
const subscriptionsStore = useSubscriptionStore(); | ||
onMounted(async () => { | ||
if (!account.isConnected.value) { | ||
$q.notify({ message: 'Account not connected', color: 'negative' }); | ||
await router.push({ path: '/' }); | ||
return; | ||
} | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { defineStore } from 'pinia'; | ||
import { | ||
BaseSubscription, | ||
getUserSubscriptionsSubscriptionsGet, | ||
holdSubscriptionMessagesHoldMessageGet, | ||
subscribeHoldSubscriptionPost, | ||
SubscriptionType, | ||
} from 'src/apis/subscriptions'; | ||
import { getAccount, signMessage } from '@wagmi/core'; | ||
import { config } from 'src/config/wagmi'; | ||
|
||
type SubscriptionState = { | ||
subscriptions: BaseSubscription[]; | ||
isLoaded: boolean; | ||
}; | ||
|
||
export const useSubscriptionStore = defineStore('subscriptions', { | ||
state: (): SubscriptionState => ({ | ||
subscriptions: [], | ||
isLoaded: false, | ||
}), | ||
actions: { | ||
async load() { | ||
const account = getAccount(config); | ||
const address = account.address; | ||
|
||
if (address === undefined) { | ||
return; | ||
} | ||
|
||
const response = await getUserSubscriptionsSubscriptionsGet({ query: { address } }); | ||
|
||
this.subscriptions = response.data?.subscriptions ?? []; | ||
this.isLoaded = true; | ||
}, | ||
|
||
async holdSubscribe(subscriptionType: SubscriptionType) { | ||
const account = getAccount(config); | ||
const address = account.address; | ||
|
||
if (address === undefined) { | ||
return; | ||
} | ||
|
||
const messagesResponse = await holdSubscriptionMessagesHoldMessageGet({ | ||
query: { subscription_type: subscriptionType }, | ||
}); | ||
|
||
if (messagesResponse.data === undefined) { | ||
throw new Error( | ||
messagesResponse.error.detail?.toString() ?? 'Unable to fetch the message to sign to subscribe', | ||
); | ||
} | ||
|
||
const messageToSign = messagesResponse.data.subscribe_message; | ||
const hash = await signMessage(config, { message: messageToSign }); | ||
|
||
const subscriptionResponse = await subscribeHoldSubscriptionPost({ | ||
body: { | ||
signature: hash, | ||
type: 'standard', | ||
account: { chain: 'base', address }, | ||
}, | ||
}); | ||
// TODO: handle errors and success | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters