Skip to content

Commit cfb4b1e

Browse files
committed
update dapp styling
1 parent 0445b13 commit cfb4b1e

20 files changed

+464
-155
lines changed

packages/create-typink/templates/default/contracts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"type": "module",
99
"dependencies": {
1010
"dedot": "^0.6.1",
11-
"typink": "0.0.1-alpha.3"
11+
"typink": "0.0.1-alpha.4"
1212
}
1313
}

packages/create-typink/templates/default/ui/package.json.template.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"react-dom": "^18.3.1",
3131
"react-toastify": "^9.1.3",
3232
"react-use": "^17.6.0",
33-
"typink": "0.0.1-alpha.3"
33+
"typink": "0.0.1-alpha.4"
3434
},
3535
"devDependencies": {
3636
"@dedot/chaintypes": "^0.44.0",
1.03 KB
Loading
913 Bytes
Loading

packages/create-typink/templates/default/ui/public/typink-pink.svg

Lines changed: 83 additions & 0 deletions
Loading
3.19 KB
Loading
2.59 KB
Loading
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import { Box, Flex } from '@chakra-ui/react';
2+
import MainBoard from '@/components/MainBoard.tsx';
23
import BalanceInsufficientAlert from '@/components/shared/BalanceInsufficientAlert.tsx';
34
import MainFooter from '@/components/shared/MainFooter';
45
import MainHeader from '@/components/shared/MainHeader';
5-
import MainBoard from '@/components/MainBoard.tsx';
6+
import TypinkIntroduction from '@/components/shared/TypinkIntroduction.tsx';
67

7-
function App() {
8+
export default function App() {
89
return (
910
<Flex direction='column' minHeight='100vh'>
1011
<MainHeader />
11-
<Box maxWidth='container.lg' mx='auto' my={4} px={4} flex={1} w='full'>
12-
<BalanceInsufficientAlert />
12+
<Box maxWidth='container.lg' mx='auto' my={12} px={4} flex={1} w='full'>
13+
<TypinkIntroduction />
1314

1415
<Box mt={8} mx={{ base: 0, md: 32 }}>
16+
<BalanceInsufficientAlert />
1517
<MainBoard />
1618
</Box>
1719
</Box>
1820
<MainFooter />
1921
</Flex>
2022
);
2123
}
22-
23-
export default App;

packages/create-typink/templates/default/ui/src/components/MainBoard.tsx.template.ejs

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,42 @@ import PendingText from '@/components/shared/PendingText.tsx';
66
import { useApp } from '@/providers/AppProvider.tsx';
77
import { shortenAddress } from '@/utils/string.ts';
88
import { txToaster } from '@/utils/txToaster.tsx';
9-
import { useBalance, useContractQuery, useContractTx, useTypink, useWatchContractEvent } from 'typink';
9+
import { useContractQuery, useContractTx, useWatchContractEvent } from 'typink';
1010
1111
export default function GreetBoard() {
12-
const { connectedAccount } = useTypink();
1312
const { greeterContract: contract } = useApp();
1413
const [message, setMessage] = useState('');
1514
const setMessageTx = useContractTx(contract, 'setMessage');
16-
const balance = useBalance(connectedAccount?.address);
1715
1816
const { data: greet, isLoading } = useContractQuery({
1917
contract,
2018
fn: 'greet',
2119
watch: true,
2220
});
2321
24-
const handleUpdateGreeting = async () => {
25-
if (!contract || !message) return;
26-
27-
if (!connectedAccount) {
28-
toast.info('Please connect to your wallet');
29-
return;
30-
}
22+
const handleUpdateGreeting = async (e: any) => {
23+
e?.preventDefault();
3124
32-
if (balance?.free === 0n) {
33-
toast.error('Balance insufficient to make transaction.');
34-
return;
35-
}
25+
if (!contract || !message) return;
3626
37-
const toaster = txToaster('Signing transaction...');
27+
const toaster = txToaster();
3828
3929
try {
4030
await setMessageTx.signAndSend({
4131
args: [message],
42-
callback: ({ status }) => {
32+
callback: (result) => {
33+
const { status } = result;
4334
console.log(status);
4435
4536
if (status.type === 'BestChainBlockIncluded') {
4637
setMessage('');
4738
}
4839
49-
toaster.updateTxStatus(status);
40+
toaster.onTxProgress(result);
5041
},
5142
});
5243
} catch (e: any) {
53-
console.error(e, e.message);
54-
toaster.onError(e);
44+
toaster.onTxError(e);
5545
}
5646
};
5747
@@ -92,16 +82,19 @@ export default function GreetBoard() {
9282
9383
return (
9484
<Box>
95-
<Heading size='md'>Greeter Contract</Heading>
85+
<Heading size='md' mb={2}>
86+
Sample Greeter Contract
87+
</Heading>
88+
<Text>Send a greeting message to the world!</Text>
9689
<Flex my={4} gap={2}>
97-
<Text>Greeting Message:</Text>
90+
<Text>Message:</Text>
9891
<PendingText fontWeight='600' isLoading={isLoading} color='primary.500'>
9992
{greet}
10093
</PendingText>
10194
</Flex>
102-
<form>
95+
<form onSubmit={handleUpdateGreeting}>
10396
<FormControl>
104-
<FormLabel>Update greeting message:</FormLabel>
97+
<FormLabel>Update message:</FormLabel>
10598
<Input
10699
type='input'
107100
maxLength={50}
@@ -111,12 +104,7 @@ export default function GreetBoard() {
111104
/>
112105
<FormHelperText>Max 50 characters</FormHelperText>
113106
</FormControl>
114-
<Button
115-
size='sm'
116-
mt={4}
117-
isDisabled={!message}
118-
isLoading={setMessageTx.inBestBlockProgress}
119-
onClick={handleUpdateGreeting}>
107+
<Button type='submit' size='sm' mt={4} isDisabled={!message} isLoading={setMessageTx.inBestBlockProgress}>
120108
Update Greeting
121109
</Button>
122110
</form>
@@ -171,23 +159,24 @@ export default function Psp22Board() {
171159
const mintNewToken = async () => {
172160
if (!tokenDecimal) return;
173161
174-
const toaster = txToaster('Signing transaction...');
162+
const toaster = txToaster();
175163
try {
176164
await mintTx.signAndSend({
177165
args: [BigInt(100 * Math.pow(10, tokenDecimal))],
178-
callback: ({ status }) => {
166+
callback: (result) => {
167+
const { status } = result;
179168
console.log(status);
180169
181170
if (status.type === 'BestChainBlockIncluded') {
182171
refreshTotalSupply();
183172
}
184173
185-
toaster.updateTxStatus(status);
174+
toaster.onTxProgress(result);
186175
},
187176
});
188177
} catch (e: any) {
189178
console.error(e);
190-
toaster.onError(e);
179+
toaster.onTxError(e);
191180
}
192181
};
193182

packages/create-typink/templates/default/ui/src/components/shared/AccountSelection.tsx.template.ejs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Box, Button, Flex, Menu, MenuButton, MenuDivider, MenuItem, MenuList, T
33
import { useEffect, useMemo } from 'react';
44
import { useWalletConnector } from '@/providers/WalletConnectorProvider.tsx';
55
import { shortenAddress } from '@/utils/string.ts';
6+
import { ChevronDownIcon } from '@chakra-ui/icons';
67
import { formatBalance, useBalances, useTypink } from 'typink';
78
89
function ConnectedWallet() {
@@ -43,7 +44,7 @@ export default function AccountSelection() {
4344
return (
4445
<Box>
4546
<Menu autoSelect={false}>
46-
<MenuButton as={Button} variant='outline'>
47+
<MenuButton as={Button} variant='outline' rightIcon={<ChevronDownIcon boxSize='5' />}>
4748
<Flex align='center' gap={2}>
4849
<Text fontWeight='semi-bold' fontSize='md'>
4950
{name}
@@ -87,6 +88,7 @@ import { Box, Button, Flex, Menu, MenuButton, MenuDivider, MenuItem, MenuList, T
8788
import { useEffect, useMemo } from 'react';
8889
import { useWalletConnector } from '@/providers/WalletConnectorProvider.tsx';
8990
import { shortenAddress } from '@/utils/string.ts';
91+
import { ChevronDownIcon } from '@chakra-ui/icons';
9092
import { formatBalance, useBalances, useTypink } from 'typink';
9193
9294
function ConnectedWallet() {
@@ -131,7 +133,7 @@ export default function AccountSelection() {
131133
return (
132134
<Box>
133135
<Menu autoSelect={false}>
134-
<MenuButton as={Button} variant='outline'>
136+
<MenuButton as={Button} variant='outline' rightIcon={<ChevronDownIcon boxSize='5' />}>
135137
<Flex align='center' gap={2}>
136138
<Text fontWeight='semi-bold' fontSize='md'>
137139
{name}
@@ -175,6 +177,7 @@ import { Box, Button, Flex, Menu, MenuButton, MenuDivider, MenuItem, MenuList, T
175177
import { useEffect, useMemo } from 'react';
176178
import WalletSelection, { ButtonStyle } from '@/components/shared/WalletSelection.tsx';
177179
import { shortenAddress } from '@/utils/string.ts';
180+
import { ChevronDownIcon } from '@chakra-ui/icons';
178181
import { formatBalance, useBalances, useTypink } from 'typink';
179182
180183
function ConnectedWallet() {
@@ -212,12 +215,12 @@ export default function AccountSelection() {
212215
return (
213216
<Box>
214217
<Menu autoSelect={false}>
215-
<MenuButton as={Button} variant='outline'>
218+
<MenuButton as={Button} variant='outline' rightIcon={<ChevronDownIcon boxSize='5' />}>
216219
<Flex align='center' gap={2}>
217220
<Text fontWeight='semi-bold' fontSize='md'>
218221
{name}
219222
</Text>
220-
<Text fontSize='sm' fontWeight='400'>
223+
<Text fontSize='sm' fontWeight='400' display={{ base: 'none', md: 'inline' }}>
221224
({shortenAddress(address)})
222225
</Text>
223226
</Flex>
@@ -241,6 +244,11 @@ export default function AccountSelection() {
241244
</MenuItem>
242245
))}
243246
<MenuDivider />
247+
<WalletSelection
248+
buttonStyle={ButtonStyle.MENU_ITEM}
249+
buttonLabel='Switch Wallet'
250+
buttonProps={{ color: 'primary.500' }}
251+
/>
244252
<MenuItem onClick={disconnect} color='red.500'>
245253
Sign Out
246254
</MenuItem>

0 commit comments

Comments
 (0)