@dubsdotapp/expo 0.1.0
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 +158 -0
- package/dist/index.d.mts +577 -0
- package/dist/index.d.ts +577 -0
- package/dist/index.js +1364 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1318 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +57 -0
- package/src/client.ts +355 -0
- package/src/constants.ts +3 -0
- package/src/errors.ts +127 -0
- package/src/hooks/index.ts +12 -0
- package/src/hooks/useAuth.ts +180 -0
- package/src/hooks/useClaim.ts +64 -0
- package/src/hooks/useCreateGame.ts +78 -0
- package/src/hooks/useEvents.ts +34 -0
- package/src/hooks/useGame.ts +30 -0
- package/src/hooks/useGames.ts +31 -0
- package/src/hooks/useJoinGame.ts +78 -0
- package/src/hooks/useNetworkGames.ts +31 -0
- package/src/index.ts +83 -0
- package/src/provider.tsx +39 -0
- package/src/types.ts +340 -0
- package/src/ui/ConnectWalletScreen.tsx +145 -0
- package/src/ui/SettingsSheet.tsx +173 -0
- package/src/ui/UserProfileCard.tsx +90 -0
- package/src/ui/index.ts +8 -0
- package/src/ui/theme.ts +57 -0
- package/src/utils/transaction.ts +67 -0
- package/src/wallet/index.ts +3 -0
- package/src/wallet/mwa-adapter.ts +156 -0
- package/src/wallet/types.ts +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# @dubs/expo
|
|
2
|
+
|
|
3
|
+
React Native SDK for the [Dubs](https://dubs.fun) betting platform. Pure TypeScript — no native code.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx expo install @dubs/expo @solana/web3.js
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
For the built-in Mobile Wallet Adapter (optional):
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx expo install @solana-mobile/mobile-wallet-adapter-protocol-web3js
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
### 1. Set up the provider
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { DubsProvider, MwaWalletAdapter } from '@dubs/expo';
|
|
23
|
+
|
|
24
|
+
const wallet = new MwaWalletAdapter({
|
|
25
|
+
appIdentity: { name: 'My App' },
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export default function App() {
|
|
29
|
+
return (
|
|
30
|
+
<DubsProvider
|
|
31
|
+
apiKey="dubs_live_your_key_here"
|
|
32
|
+
rpcUrl="https://api.mainnet-beta.solana.com"
|
|
33
|
+
wallet={wallet}
|
|
34
|
+
>
|
|
35
|
+
<HomeScreen />
|
|
36
|
+
</DubsProvider>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 2. Browse events
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import { useEvents } from '@dubs/expo';
|
|
45
|
+
|
|
46
|
+
function EventsList() {
|
|
47
|
+
const { data, loading, error, refetch } = useEvents({ type: 'sports' });
|
|
48
|
+
|
|
49
|
+
if (loading) return <Text>Loading...</Text>;
|
|
50
|
+
if (error) return <Text>Error: {error.message}</Text>;
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<FlatList
|
|
54
|
+
data={data?.events}
|
|
55
|
+
renderItem={({ item }) => (
|
|
56
|
+
<Text>{item.title} — {item.startTime}</Text>
|
|
57
|
+
)}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 3. Create a bet
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
import { useCreateGame } from '@dubs/expo';
|
|
67
|
+
|
|
68
|
+
function CreateBet({ eventId }: { eventId: string }) {
|
|
69
|
+
const { execute, status, error } = useCreateGame();
|
|
70
|
+
|
|
71
|
+
const handleCreate = async () => {
|
|
72
|
+
const result = await execute({
|
|
73
|
+
id: eventId, // e.g. "sports:NBA:espn-nba-401..."
|
|
74
|
+
playerWallet: 'YOUR_WALLET',
|
|
75
|
+
teamChoice: 'home',
|
|
76
|
+
wagerAmount: 0.1, // SOL
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
console.log('Bet placed!', result.explorerUrl);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<View>
|
|
84
|
+
<Button title="Place Bet" onPress={handleCreate} disabled={status !== 'idle'} />
|
|
85
|
+
{status !== 'idle' && <Text>Status: {status}</Text>}
|
|
86
|
+
{error && <Text>Error: {error.message}</Text>}
|
|
87
|
+
</View>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Custom Wallet Adapter
|
|
93
|
+
|
|
94
|
+
If you're using Privy, Dynamic, or another wallet provider, implement the `WalletAdapter` interface:
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
import { DubsProvider } from '@dubs/expo';
|
|
98
|
+
import type { WalletAdapter } from '@dubs/expo';
|
|
99
|
+
import { Transaction, PublicKey } from '@solana/web3.js';
|
|
100
|
+
|
|
101
|
+
const myAdapter: WalletAdapter = {
|
|
102
|
+
publicKey: new PublicKey('...'),
|
|
103
|
+
connected: true,
|
|
104
|
+
signTransaction: async (tx: Transaction) => {
|
|
105
|
+
// Sign using your wallet provider
|
|
106
|
+
return signedTx;
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
<DubsProvider apiKey="..." wallet={myAdapter}>
|
|
111
|
+
<App />
|
|
112
|
+
</DubsProvider>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## API Reference
|
|
116
|
+
|
|
117
|
+
### Hooks
|
|
118
|
+
|
|
119
|
+
| Hook | Type | Description |
|
|
120
|
+
|------|------|-------------|
|
|
121
|
+
| `useEvents(params?)` | Query | Fetch upcoming events (sports + esports) |
|
|
122
|
+
| `useGame(gameId)` | Query | Single game detail |
|
|
123
|
+
| `useGames(params?)` | Query | List games with filters |
|
|
124
|
+
| `useCreateGame()` | Mutation | Full create lifecycle (build → sign → send → confirm) |
|
|
125
|
+
| `useJoinGame()` | Mutation | Full join lifecycle |
|
|
126
|
+
| `useClaim()` | Mutation | Full claim lifecycle |
|
|
127
|
+
|
|
128
|
+
### Mutation Status
|
|
129
|
+
|
|
130
|
+
Mutation hooks expose granular status:
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
'idle' → 'building' → 'signing' → 'confirming' → 'saving' → 'success'
|
|
134
|
+
↘ 'error'
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### DubsClient (headless)
|
|
138
|
+
|
|
139
|
+
For use outside React or for custom integrations:
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import { DubsClient } from '@dubs/expo';
|
|
143
|
+
|
|
144
|
+
const client = new DubsClient({ apiKey: 'dubs_live_...' });
|
|
145
|
+
|
|
146
|
+
const { events } = await client.getUpcomingEvents({ type: 'sports', game: 'nba' });
|
|
147
|
+
const game = await client.getGame('sport-123...');
|
|
148
|
+
const codes = client.getErrorCodesLocal();
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Event ID Format
|
|
152
|
+
|
|
153
|
+
- Sports: `sports:{LEAGUE}:{EVENT_ID}` (e.g. `sports:NBA:espn-nba-401...`)
|
|
154
|
+
- Esports: `esports:{MATCH_ID}` (e.g. `esports:1353988`)
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
MIT
|