Skip to content

Commit

Permalink
WIP Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
bone-house committed Sep 1, 2023
1 parent 68ed405 commit 654f47f
Show file tree
Hide file tree
Showing 124 changed files with 8,363 additions and 4,109 deletions.
4 changes: 2 additions & 2 deletions apps/basic/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useWallet } from '@solana/wallet-adapter-react'
import { GambaConnectButton } from 'gamba-react-ui'
import { WalletMultiButton } from '@solana/wallet-adapter-react-ui'
import React from 'react'
import DoubleOrNothing from './DoubleOrNothing'

Expand All @@ -9,7 +9,7 @@ export function App() {
return (
<>
<header>
<GambaConnectButton />
<WalletMultiButton />
</header>
<div className="content">
{!connected ? (
Expand Down
61 changes: 22 additions & 39 deletions apps/basic/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,34 @@
import { ConnectionProvider, WalletProvider } from '@solana/wallet-adapter-react'
import { WalletModalProvider } from '@solana/wallet-adapter-react-ui'
import { GambaUi } from 'gamba-react-ui'
import { Gamba } from 'gamba/react'
import { GambaProvider } from 'gamba/react'
import React from 'react'
import ReactDOM from 'react-dom/client'
import { ToastContainer, toast } from 'react-toastify'
import 'react-toastify/dist/ReactToastify.css'
import { App } from './App'

import '@solana/wallet-adapter-react-ui/styles.css'
import 'react-toastify/dist/ReactToastify.css'
import './styles.css'

const root = ReactDOM.createRoot(document.getElementById('root')!)

root.render(
<Gamba
creator="DwRFGbjKbsEhUMe5at3qWvH7i8dAJyhhwdnFoZMnLVRV"
connection={{
endpoint: import.meta.env.GAMBA_SOLANA_RPC,
config: {
wsEndpoint: import.meta.env.GAMBA_SOLANA_RPC_WS,
commitment: 'processed',
},
}}
<ConnectionProvider
endpoint={import.meta.env.GAMBA_SOLANA_RPC}
config={{ wsEndpoint: import.meta.env.GAMBA_SOLANA_RPC_WS, commitment: 'processed' }}
>
<GambaUi
onError={(err) => toast(err.message, { type: 'error' })}
>
<ToastContainer />
<App />
</GambaUi>
</Gamba>,
<WalletProvider autoConnect wallets={[]}>
<WalletModalProvider>
<ToastContainer />
<GambaProvider creator="DwRFGbjKbsEhUMe5at3qWvH7i8dAJyhhwdnFoZMnLVRV">
<GambaUi
onError={(err) => toast(err.message, { type: 'error' })}
>
<App />
</GambaUi>
</GambaProvider>
</WalletModalProvider>
</WalletProvider>
</ConnectionProvider>,
)

// IF YOU NEED TO USE YOUR OWN PROVIDERS FOR CONNECTION / WALLET:
// root.render(
// <ConnectionProvider
// endpoint={import.meta.env.GAMBA_SOLANA_RPC}
// config={{ wsEndpoint: import.meta.env.GAMBA_SOLANA_RPC_WS, commitment: 'processed' }}
// >
// <WalletProvider autoConnect wallets={[]}>
// <WalletModalProvider>
// <ToastContainer />
// <GambaProvider creator="DwRFGbjKbsEhUMe5at3qWvH7i8dAJyhhwdnFoZMnLVRV">
// <GambaUi
// onError={(err) => toast(err.message, { type: 'error' })}
// >
// <App />
// </GambaUi>
// </GambaProvider>
// </WalletModalProvider>
// </WalletProvider>
// </ConnectionProvider>,
// )
2 changes: 1 addition & 1 deletion apps/basic/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineConfig(() => ({
envPrefix: ENV_PREFIX,
assetsInclude: ['**/*.glb'],
server: {
port: 5000,
port: 7779,
host: true,
},
define: { 'process.env.ANCHOR_BROWSER': true },
Expand Down
9 changes: 7 additions & 2 deletions apps/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,23 @@
"dependencies": {
"@react-three/drei": "^9.65.5",
"@react-three/fiber": "^8.12.2",
"@solana/wallet-adapter-base": "^0.9.22",
"@solana/wallet-adapter-react": "^0.15.32",
"@solana/wallet-adapter-react-ui": "^0.9.31",
"@solana/wallet-adapter-solflare": "^0.6.26",
"@solana/wallet-adapter-wallets": "^0.19.18",
"assert": "^2.0.0",
"gamba": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.8.0",
"react-qr-code": "^2.0.12",
"react-router-dom": "^6.10.0",
"react-toastify": "^9.1.3",
"styled-components": "^5.3.11",
"three": "^0.151.3",
"tone": "^14.7.77",
"url": "^0.11.1",
"zustand": "^4.3.7"
"url": "^0.11.1"
},
"devDependencies": {
"@types/react": "^18.0.28",
Expand Down
78 changes: 75 additions & 3 deletions apps/demo/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,87 @@
import { useWallet } from '@solana/wallet-adapter-react'
import { WalletMultiButton } from '@solana/wallet-adapter-react-ui'
import { GambaError, useGamba, useGambaError } from 'gamba/react'
import { Button, Modal } from 'gamba/react-ui'
import React from 'react'
import { Route, Routes } from 'react-router-dom'
import { ToastContainer } from 'react-toastify'
import 'react-toastify/dist/ReactToastify.css'
import View from './View'
import ScrollToTop from './components/ScrollToTop'
import { GambaError2 } from 'gamba'

function Guide({ onDone, onCancel }: {onDone: () => void, onCancel: () => void}) {
const wallet = useWallet()
const [creating, setCreating] = React.useState(false)
const [initUser, setInitUser] = React.useState(false)
const gamba = useGamba()

const create = async () => {
try {
setCreating(true)
const req = await gamba.createAccount()
await req.result()
setInitUser(true)
// await gamba._client.user.waitForState((state) => {
// if (state.decoded?.status.playing) {
// return true
// }
// })
onDone()
} finally {
setCreating(false)
setInitUser(false)
}
}

return (
<Modal onClose={onCancel}>
{!wallet.connected ? (
<WalletMultiButton />
) : (
<>
{initUser ? (
'Initializing user!'
) : (
<>
Create an account to continue playing.<br />
This only needs to be done once.
<Button loading={creating} pulse onClick={create}>
Create account!
</Button>
</>
)}
</>
)}
</Modal>
)
}

export function App() {
const [error, setError] = React.useState<GambaError2>()

useGambaError(
(err) => {
if (err.message === GambaError.PLAY_BEFORE_INITIALIZED) {
err.handle()
setError(err)
}
},
)

return (
<>
<ToastContainer />
<ScrollToTop />
{error && (
<Guide
onDone={() => {
error.resolve()
setError(undefined)
}}
onCancel={() => {
error.reject()
setError(undefined)
}}
/>
)}
<Routes>
<Route
path="/:shortName?"
Expand Down
60 changes: 56 additions & 4 deletions apps/demo/src/View.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,73 @@
import { GameView, RecentPlays } from 'gamba/react-ui'
import { useGamba } from 'gamba/react'
import { GambaConnectButton, GameBundle, GameView } from 'gamba/react-ui'
import React, { useMemo } from 'react'
import QRCode from 'react-qr-code'
import { useParams } from 'react-router-dom'
import { Header } from './components/Header'
import styled from 'styled-components'
import { Card } from './components/Card'
import { Footer } from './components/Footer'
import { ClaimButton, Header, RedeemBonusButton } from './components/Header'
import { RecentPlays } from './components/RecentPlays'
import { Slider } from './components/Slider'
import { GAMES } from './games'
import { Section } from './styles'

const StyledFrame = styled.div<{$viewHeight: number}>`
height: 100vh;
height: -webkit-fill-available;
@media (min-height: 800px) {
height: ${({ $viewHeight }) => $viewHeight}vh;
}
position: relative;
transition: height .2s ease;
`

function Frame({ game }: {game?: GameBundle}) {
const gamba = useGamba()
return (
<StyledFrame $viewHeight={game ? 75 : 50}>
{game && <GameView game={game} />}
{!game && (
<Section style={{ height: '100%' }}>
<div style={{ textAlign: 'center', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
<div>
<QRCode value={gamba.wallet.publicKey.toBase58()} />
<br />
<RedeemBonusButton />
<ClaimButton />
</div>
</div>
</Section>
)}
</StyledFrame>
)
}

export default function View() {
const { shortName } = useParams()
const game = useMemo(() => GAMES.find((x) => x.short_name === shortName) ?? GAMES[0], [shortName])
const game = useMemo(() => GAMES.find((x) => x.short_name === shortName), [shortName])

return (
<>
<Header />
<GameView game={game} />
<Frame game={game} />
<Section>
<Slider title={<h2>Casino Games</h2>}>
{GAMES.map((game) => (
<Card key={game.short_name} to={'/' + game.short_name} logo={game.image} backgroundColor={game.theme_color}>
{game.name}
</Card>
))}
</Slider>
</Section>
<Section>
<h2>Recent Plays</h2>
<RecentPlays />
</Section>
<Section>
<Footer />
</Section>
<GambaConnectButton />
</>
)
}
3 changes: 3 additions & 0 deletions apps/demo/src/bomb.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 654f47f

Please sign in to comment.