-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: wip setup for immutable records according to designs
- Loading branch information
1 parent
8f22363
commit 492c9e8
Showing
31 changed files
with
1,551 additions
and
9 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
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,13 @@ | ||
import { globalStyle, style } from '@vanilla-extract/css'; | ||
|
||
export const bodyClass = style([ | ||
{ | ||
margin: '0', | ||
background: '#1E1726', | ||
height: '100vh', | ||
}, | ||
]); | ||
|
||
globalStyle('*', { | ||
boxSizing: 'border-box', | ||
}); |
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
9 changes: 9 additions & 0 deletions
9
packages/apps/immutable-records/src/components/Accounts/Accounts.css.ts
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,9 @@ | ||
import { sprinkles } from '@kadena/react-ui/theme'; | ||
|
||
import { style } from '@vanilla-extract/css'; | ||
|
||
export const container = style([ | ||
sprinkles({ | ||
marginY: '$4', | ||
}), | ||
]); |
144 changes: 144 additions & 0 deletions
144
packages/apps/immutable-records/src/components/Accounts/Accounts.tsx
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,144 @@ | ||
'use client'; | ||
|
||
import { Option, Select } from '@kadena/react-ui'; | ||
|
||
import { container } from './Accounts.css'; | ||
|
||
import { useWalletConnect } from '@/hooks/connect.hook'; | ||
import type { BalanceItem } from '@/services/chainweb/chainweb'; | ||
import { getBalance } from '@/services/chainweb/chainweb'; | ||
import type { KadenaAccount } from '@/services/connect/connect.client'; | ||
import type { FC } from 'react'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
const KadenaAccountBalance: FC<{ | ||
account: KadenaAccount; | ||
network: string; | ||
chain: string; | ||
}> = ({ account, network, chain }) => { | ||
const [balance, setBalance] = useState<string | null>(null); | ||
|
||
useEffect(() => { | ||
console.log(`fetch balance ${account.name}, ${network}, ${chain}`); | ||
getBalance(account.name, network, chain as BalanceItem['chain']) | ||
.then((balance) => { | ||
setBalance(balance.balance); | ||
}) | ||
.catch((e) => {}); | ||
}, [account.name, chain, network]); | ||
|
||
return <span>{balance ?? 'loading...'}</span>; | ||
}; | ||
|
||
const KadenaAccounts: FC<{ | ||
selected: string | null; | ||
accounts: Record<string, KadenaAccount[] | undefined>; | ||
}> = ({ selected, accounts }) => { | ||
if (!selected) { | ||
return <span>No accounts selected</span>; | ||
} | ||
// console.log('test', accounts, selected); | ||
if (!accounts[selected]) { | ||
return <span>Loading accounts...</span>; | ||
} | ||
|
||
const network = 'testnet04'; | ||
|
||
return ( | ||
<div className={container}> | ||
<table> | ||
<thead> | ||
<tr> | ||
<td>account</td> | ||
<td>balance</td> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{accounts[selected]?.map((account) => ( | ||
<tr key={account.name}> | ||
<td>{account.name}</td> | ||
{account.chains.map((chain) => ( | ||
<td key={`account-${account.name}-${chain}`}> | ||
<KadenaAccountBalance | ||
account={account} | ||
network={network} | ||
chain={chain} | ||
/> | ||
</td> | ||
))} | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
); | ||
}; | ||
|
||
export const Accounts: FC = () => { | ||
const { | ||
sessionTopic, | ||
accounts, | ||
kadenaAccounts, | ||
fetchKadenaAccounts, | ||
setNetwork, | ||
networks, | ||
network, | ||
} = useWalletConnect(); | ||
|
||
const [selectedAccount, setSelectedAccount] = useState<string>(''); | ||
const hasSession = !!sessionTopic; | ||
|
||
// Select first network and account on load | ||
useEffect(() => { | ||
if (!selectedAccount) { | ||
setSelectedAccount(accounts[0]); | ||
} | ||
}, [selectedAccount, accounts]); | ||
|
||
useEffect(() => { | ||
if (network && selectedAccount) { | ||
fetchKadenaAccounts(selectedAccount).catch((e) => {}); | ||
} | ||
}, [fetchKadenaAccounts, network, selectedAccount]); | ||
|
||
return ( | ||
<div> | ||
<h3>Select account</h3> | ||
{!hasSession ? ( | ||
'Not connected to wallet' | ||
) : ( | ||
<div style={{ display: 'flex' }}> | ||
<Select | ||
id="network" | ||
ariaLabel="network" | ||
value={network ?? ''} | ||
onChange={(e) => setNetwork(e.target.value)} | ||
> | ||
{networks.map((network) => ( | ||
<Option key={network} value={network}> | ||
{network} | ||
</Option> | ||
))} | ||
</Select> | ||
<Select | ||
id="account" | ||
ariaLabel="account" | ||
value={selectedAccount} | ||
onChange={(e) => setSelectedAccount(e.target.value)} | ||
> | ||
{accounts.map((account) => ( | ||
<Option key={account} value={account}> | ||
{account} | ||
</Option> | ||
))} | ||
</Select> | ||
</div> | ||
)} | ||
|
||
<div className={container}> | ||
<h3>Selected accounts</h3> | ||
<KadenaAccounts selected={selectedAccount} accounts={kadenaAccounts} /> | ||
</div> | ||
</div> | ||
); | ||
}; |
25 changes: 25 additions & 0 deletions
25
packages/apps/immutable-records/src/components/BackgroundGrid/BackgroundGrid.css.ts
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,25 @@ | ||
import { globalStyle, style } from '@vanilla-extract/css'; | ||
|
||
export const container = style([ | ||
{ | ||
position: 'absolute', | ||
width: '100%', | ||
height: '100%', | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignContent: 'space-around', | ||
justifyContent: 'center', | ||
flexWrap: 'wrap', | ||
overflow: 'hidden', | ||
}, | ||
]); | ||
|
||
globalStyle(`${container} > div`, { | ||
flexBasis: '2.5%', | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
fontSize: '24px', | ||
fontWeight: 'bold', | ||
color: '#33263f', | ||
}); |
11 changes: 11 additions & 0 deletions
11
packages/apps/immutable-records/src/components/BackgroundGrid/BackgroundGrid.tsx
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,11 @@ | ||
import { container } from './BackgroundGrid.css'; | ||
|
||
export const BackgroundGrid = () => { | ||
return ( | ||
<div className={container}> | ||
{Array.from({ length: 800 }, (_, i) => i).map((i) => ( | ||
<div key={i}>+</div> | ||
))} | ||
</div> | ||
); | ||
}; |
21 changes: 21 additions & 0 deletions
21
packages/apps/immutable-records/src/components/Bid/Bid.tsx
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,21 @@ | ||
import type { FC } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
|
||
interface BidForm { | ||
amount: number; | ||
} | ||
|
||
export const Bid: FC = () => { | ||
const form = useForm({ | ||
defaultValues: { | ||
amount: 0, | ||
} as BidForm, | ||
}); | ||
|
||
return ( | ||
<form> | ||
<input type="number" {...form.register('amount')} /> | ||
<button type="submit">Bid</button> | ||
</form> | ||
); | ||
}; |
33 changes: 33 additions & 0 deletions
33
packages/apps/immutable-records/src/components/Connect/Connect.css.ts
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,33 @@ | ||
import { sprinkles } from '@kadena/react-ui/theme'; | ||
|
||
import { globalStyle, style } from '@vanilla-extract/css'; | ||
|
||
export const container = style([sprinkles({})]); | ||
|
||
export const debugContainerButton = style([ | ||
sprinkles({ | ||
marginTop: '$2', | ||
}), | ||
]); | ||
|
||
export const debugContainer = style([ | ||
sprinkles({ | ||
marginY: '$2', | ||
backgroundColor: '$gray40', | ||
borderColor: '$gray60', | ||
borderStyle: 'solid', | ||
borderWidth: '$md', | ||
padding: '$2', | ||
}), | ||
{ | ||
display: 'inline-block', | ||
}, | ||
]); | ||
|
||
export const tooltipContainer = style({}); | ||
|
||
globalStyle(`${tooltipContainer} div`, { | ||
zIndex: 2, | ||
backgroundColor: '#e88e00', | ||
borderColor: '#e88e00', | ||
}); |
Oops, something went wrong.