@trifle/trifle-hub 1.0.25 → 1.0.26
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.
- package/README.md +197 -0
- package/dist/index.es.js +318 -303
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# TrifleHub Documentation
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
Install the TrifleHub plugin using npm or yarn:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Using npm
|
|
9
|
+
npm install @trifle/hub
|
|
10
|
+
|
|
11
|
+
# Using yarn
|
|
12
|
+
yarn add @trifle/hub
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Configuration and Setup
|
|
16
|
+
|
|
17
|
+
Import and register the TrifleHub plugin in your Vue application:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import { createApp } from 'vue'
|
|
21
|
+
import App from './App.vue'
|
|
22
|
+
import TrifleHubVuePlugin from '@trifle/hub'
|
|
23
|
+
|
|
24
|
+
const app = createApp(App)
|
|
25
|
+
|
|
26
|
+
// Configure and install the TrifleHub plugin
|
|
27
|
+
app.use(TrifleHubVuePlugin, {
|
|
28
|
+
// Required: ReOWN AppKit configuration
|
|
29
|
+
reownConfig: {
|
|
30
|
+
appId: 'your-app-id'
|
|
31
|
+
// Other ReOWN AppKit configuration options
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
// Optional: Backend URL (defaults to 'https://bot-staging.trifle.life')
|
|
35
|
+
backendUrl: 'https://bot-staging.trifle.life',
|
|
36
|
+
|
|
37
|
+
// Optional: Set the default page to show when the hub is opened for the first time
|
|
38
|
+
defaultPage: 'games' // or any valid page key (e.g., 'welcome', 'account', etc.)
|
|
39
|
+
|
|
40
|
+
// Optional: For development use, you can hook into an existing Pinia instance
|
|
41
|
+
devHookPiniaInstance: existingPiniaInstance
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
app.mount('#app')
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**About `defaultPage`:**
|
|
48
|
+
|
|
49
|
+
- The `defaultPage` option allows you to specify which page should be shown the first time a user opens the hub (if no page is set in the route or sessionStorage).
|
|
50
|
+
- If not specified, it defaults to `'welcome'`.
|
|
51
|
+
- Valid values are any of the page keys defined in your hub (e.g., `'games'`, `'leaderboard'`, `'account'`, etc.).
|
|
52
|
+
|
|
53
|
+
Add the TrifleHub component to your app layout:
|
|
54
|
+
|
|
55
|
+
```vue
|
|
56
|
+
<template>
|
|
57
|
+
<div id="app">
|
|
58
|
+
<!-- Your app content -->
|
|
59
|
+
<TrifleHub position="bottom-left" />
|
|
60
|
+
</div>
|
|
61
|
+
</template>
|
|
62
|
+
|
|
63
|
+
<script setup>
|
|
64
|
+
// The component is registered globally
|
|
65
|
+
</script>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Available Provide/Inject Resources
|
|
69
|
+
|
|
70
|
+
The TrifleHub plugin provides several resources via Vue's provide/inject system:
|
|
71
|
+
|
|
72
|
+
| Injection Key | Type | Description |
|
|
73
|
+
| -------------------------- | ------ | ------------------------------------------- |
|
|
74
|
+
| `'TrifleHub/wagmiConfig'` | Object | Wagmi configuration for wallet interactions |
|
|
75
|
+
| `'TrifleHub/appKit'` | Object | ReOWN AppKit instance |
|
|
76
|
+
| `'TrifleHub/store'` | Object | Authentication store (Pinia) |
|
|
77
|
+
| `'trifleHubInternalPinia'` | Object | Internal Pinia instance |
|
|
78
|
+
| `'TrifleHub/defaultPage'` | String | The default page key for the hub |
|
|
79
|
+
|
|
80
|
+
### TrifleHub Component Resources
|
|
81
|
+
|
|
82
|
+
These are provided by the TrifleHub component when it's mounted:
|
|
83
|
+
|
|
84
|
+
| Injection Key | Type | Description |
|
|
85
|
+
| ------------------------------------ | ------------------------- | -------------------------------------------------- |
|
|
86
|
+
| `'hub'` | Object | Hub controller with the following properties: |
|
|
87
|
+
| `hubOpen` | Ref<boolean> | Reactive state for hub visibility |
|
|
88
|
+
| `openHub(page?)` | Function | Open the hub, optionally to a specific page |
|
|
89
|
+
| `closeHub()` | Function | Close the hub |
|
|
90
|
+
| `'account'` | Object | Account information with the following properties: |
|
|
91
|
+
| `address` | ComputedRef<string\|null> | Current wallet address |
|
|
92
|
+
| `chainId` | ComputedRef<number\|null> | Current chain ID |
|
|
93
|
+
| `isConnected` | ComputedRef<boolean> | Whether wallet is connected |
|
|
94
|
+
| `isConnecting` | ComputedRef<boolean> | Whether wallet is connecting |
|
|
95
|
+
| `'accountModal'` | Object | Wallet interaction methods: |
|
|
96
|
+
| `disconnect()` | Function | Disconnect the wallet |
|
|
97
|
+
| `openAccountModal()` | Function | Open the wallet connection modal |
|
|
98
|
+
| `enforceConnection()` | Function | Ensure wallet is connected |
|
|
99
|
+
| `signDiscordId(message)` | Function | Sign a message for Discord auth |
|
|
100
|
+
|
|
101
|
+
## Page Navigation
|
|
102
|
+
|
|
103
|
+
TrifleHub provides a simple navigation system through the injected `hub` object. You can use this to open specific pages or close the hub.
|
|
104
|
+
|
|
105
|
+
### Available Pages
|
|
106
|
+
|
|
107
|
+
The following pages are available for navigation:
|
|
108
|
+
|
|
109
|
+
- `welcome` - Welcome page (not shown in menu)
|
|
110
|
+
- `games` - Games page
|
|
111
|
+
- `leaderboard` - Leaderboard page
|
|
112
|
+
- `earn` - Earn page
|
|
113
|
+
- `account` - Account page
|
|
114
|
+
- `theme` - Theme settings (not shown in menu)
|
|
115
|
+
|
|
116
|
+
### Navigating Between Pages
|
|
117
|
+
|
|
118
|
+
You can navigate between pages using the `hub` object:
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
// In a Vue component
|
|
122
|
+
import { inject } from 'vue'
|
|
123
|
+
|
|
124
|
+
export default {
|
|
125
|
+
setup() {
|
|
126
|
+
// Get the hub controller
|
|
127
|
+
const hub = inject('hub')
|
|
128
|
+
|
|
129
|
+
// Function to open a specific page
|
|
130
|
+
const openAccountPage = () => {
|
|
131
|
+
hub.openHub('account')
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Function to close the hub
|
|
135
|
+
const closeHub = () => {
|
|
136
|
+
hub.closeHub()
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return { openAccountPage, closeHub }
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Auth Store Methods
|
|
145
|
+
|
|
146
|
+
The authentication store (`inject('TrifleHub/store')`) provides several methods for managing user authentication:
|
|
147
|
+
|
|
148
|
+
| Method | Description |
|
|
149
|
+
| --------------------------------- | ------------------------------------------ |
|
|
150
|
+
| `connectDiscord()` | Initiate Discord authentication |
|
|
151
|
+
| `connectWallet()` | Connect to a wallet |
|
|
152
|
+
| `authenticateWithWallet(address)` | Authenticate with a connected wallet |
|
|
153
|
+
| `disconnect()` | Disconnect all authentication methods |
|
|
154
|
+
| `updateUsername(newUsername)` | Update the user's username |
|
|
155
|
+
| `fetchUserStatus()` | Get the latest user status from the server |
|
|
156
|
+
|
|
157
|
+
## Example Usage
|
|
158
|
+
|
|
159
|
+
Here's a complete example of a component that interacts with TrifleHub:
|
|
160
|
+
|
|
161
|
+
```vue
|
|
162
|
+
<template>
|
|
163
|
+
<div>
|
|
164
|
+
<button @click="openAccountPage">Open Account</button>
|
|
165
|
+
<button @click="openLeaderboard">Open Leaderboard</button>
|
|
166
|
+
<button @click="closeHub">Close Hub</button>
|
|
167
|
+
</div>
|
|
168
|
+
</template>
|
|
169
|
+
|
|
170
|
+
<script>
|
|
171
|
+
import { inject } from 'vue'
|
|
172
|
+
|
|
173
|
+
export default {
|
|
174
|
+
setup() {
|
|
175
|
+
const hub = inject('hub')
|
|
176
|
+
|
|
177
|
+
const openAccountPage = () => {
|
|
178
|
+
hub.openHub('account')
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const openLeaderboard = () => {
|
|
182
|
+
hub.openHub('leaderboard')
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const closeHub = () => {
|
|
186
|
+
hub.closeHub()
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
openAccountPage,
|
|
191
|
+
openLeaderboard,
|
|
192
|
+
closeHub
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
</script>
|
|
197
|
+
```
|