Skip to content

Commit 1f9bd40

Browse files
committed
connect wallet button
1 parent fe9bc60 commit 1f9bd40

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Button } from '@radix-ui/themes';
2+
import { useConnectWallet } from '@web3-onboard/react';
3+
import { FC } from 'react';
4+
5+
export const ConnectWalletButton: FC = () => {
6+
const [{ wallet }, connectWallet, _] = useConnectWallet();
7+
8+
return (
9+
<Button
10+
onClick={async () => {
11+
if (wallet) return;
12+
await connectWallet();
13+
}}
14+
>
15+
Connect wallet
16+
</Button>
17+
);
18+
};

app/components/CreateOrder.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { useOrderEntry, useWithdraw } from '@orderly.network/hooks';
22
import { API, OrderEntity, OrderSide, OrderType } from '@orderly.network/types';
33
import { Separator } from '@radix-ui/themes';
4+
import { useConnectWallet } from '@web3-onboard/react';
45
import { FC, useState } from 'react';
56
import { Controller, FieldError, SubmitHandler, useForm } from 'react-hook-form';
67
import { match } from 'ts-pattern';
78

8-
import { Spinner, TokenInput } from '.';
9+
import { ConnectWalletButton, Spinner, TokenInput } from '.';
910

1011
import { getDecimalsFromTick, usdFormatter } from '~/utils';
1112

@@ -26,6 +27,7 @@ export const CreateOrder: FC<{
2627
type: 'Market'
2728
}
2829
});
30+
const [{ wallet }] = useConnectWallet();
2931
const { availableWithdraw } = useWithdraw();
3032
const { onSubmit, helper, maxQty, estLeverage, estLiqPrice } = useOrderEntry(
3133
{
@@ -184,10 +186,11 @@ export const CreateOrder: FC<{
184186
<button
185187
type="submit"
186188
disabled={loading}
187-
className="relative py-2 font-size-5 bg-[var(--accent-9)] hover:bg-[var(--accent-10)] border-rd-1 border-0"
189+
className={`relative py-2 font-size-5 bg-[var(--accent-9)] hover:bg-[var(--accent-10)] border-rd-1 border-0 ${wallet == null ? 'hidden' : ''}`}
188190
>
189191
{loading && <Spinner overlay={true} />} Create Order
190192
</button>
193+
{wallet == null && <ConnectWalletButton />}
191194
</form>
192195
);
193196
};

app/components/WalletConnection.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { Button, DropdownMenu } from '@radix-ui/themes';
33
import { useConnectWallet, useSetChain } from '@web3-onboard/react';
44
import { FC, useEffect } from 'react';
55

6+
import { ConnectWalletButton } from './ConnectWalletButton';
7+
68
export const WalletConnection: FC = () => {
79
const { account } = useAccount();
8-
const [{ wallet }, connectWallet, disconnectWallet] = useConnectWallet();
10+
const [{ wallet }, _, disconnectWallet] = useConnectWallet();
911
const [{ connectedChain }, setChain] = useSetChain();
1012

1113
useEffect(() => {
@@ -132,13 +134,6 @@ export const WalletConnection: FC = () => {
132134
</DropdownMenu.Content>
133135
</DropdownMenu.Root>
134136
) : (
135-
<Button
136-
onClick={async () => {
137-
if (wallet) return;
138-
await connectWallet();
139-
}}
140-
>
141-
Connect wallet
142-
</Button>
137+
<ConnectWalletButton />
143138
);
144139
};

app/components/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
export * from './AdvancedChart';
22
export * from './Assets';
3-
export * from './LightweightChart';
3+
export * from './ConnectWalletButton';
44
export * from './ClosePosition';
55
export * from './CreateOrder';
6+
export * from './LightweightChart';
67
export * from './NavBar';
78
export * from './Orderbook';
89
export * from './OrderlyConnect';

0 commit comments

Comments
 (0)