Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: web wallet composite #236

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8842243
feat: web wallet composite
leonardocbsr Sep 2, 2024
9333ef7
feature: components
leonardocbsr Sep 2, 2024
4222f76
feat: webwallet component
leonardocbsr Sep 5, 2024
79c9b97
chore: dark mode support
leonardocbsr Sep 6, 2024
5c7a4e7
chore: prevent auto focus
leonardocbsr Sep 6, 2024
5ffc446
chore: webwallet as a opt-in feat
leonardocbsr Sep 6, 2024
4a11ca8
Merge branch 'main' into feature/web-wallet-composite
leocourbassier Sep 6, 2024
ae0a86f
chore: make the webwallet look like fuels wallet
leonardocbsr Sep 6, 2024
d8f982e
chore: a few tweaks to the wallet
leonardocbsr Sep 6, 2024
f120616
doc: update changeset
leonardocbsr Sep 6, 2024
eaa5bb2
chore: refetch everything if connected again
leonardocbsr Sep 6, 2024
7efff84
chore: styles update
leonardocbsr Sep 13, 2024
1ceb2af
fix: change @fuels/ui package location
leonardocbsr Sep 13, 2024
137aea9
chore: update variant to outline
leonardocbsr Sep 13, 2024
593e681
Merge remote-tracking branch 'upstream/main' into feature/web-wallet-…
leonardocbsr Sep 13, 2024
c86683d
chore: a few tweaks to web wallet & cleanup
leonardocbsr Sep 18, 2024
10172a8
chore: bump @fuels/ui
leonardocbsr Sep 21, 2024
d3e6f82
Merge remote-tracking branch 'upstream/main' into feature/web-wallet-…
leonardocbsr Sep 21, 2024
7cf7357
chore: add fuels
leonardocbsr Sep 21, 2024
e021a8f
Merge remote-tracking branch 'upstream/main' into feature/web-wallet-…
leonardocbsr Sep 24, 2024
6c71f5e
Merge remote-tracking branch 'upstream/main' into feature/web-wallet-…
leonardocbsr Sep 25, 2024
738ecd0
Merge remote-tracking branch 'upstream/main' into feature/web-wallet-…
leonardocbsr Sep 26, 2024
804fbde
chore: reconcile with main branch
leonardocbsr Sep 26, 2024
1908271
Merge branch 'main' into feature/web-wallet-composite
leocourbassier Sep 26, 2024
8c7f51c
Merge branch 'main' into feature/web-wallet-composite
leocourbassier Sep 27, 2024
bb3c092
Merge remote-tracking branch 'upstream/main' into feature/web-wallet-…
leonardocbsr Sep 30, 2024
40de6f0
chore: reconcile with main branch
leonardocbsr Sep 30, 2024
ac4a2eb
Merge branch 'main' into feature/web-wallet-composite
leocourbassier Sep 30, 2024
8977940
Merge remote-tracking branch 'upstream/main' into feature/web-wallet-…
leonardocbsr Oct 1, 2024
a7366ff
chore: reconcile with main branch
leonardocbsr Oct 1, 2024
2d9a237
Merge branch 'main' into feature/web-wallet-composite
leocourbassier Oct 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/famous-falcons-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@fuel-connectors/fuel-development-wallet": minor
"@fuel-connectors/walletconnect-connector": minor
"@fuel-connectors/solana-connector": minor
"@fuel-connectors/evm-connector": minor
"@fuel-connectors/fuel-wallet": minor
---

Added/Modified connector's name so it'll appear correctly in the web wallet
5 changes: 5 additions & 0 deletions .changeset/little-crabs-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuels/react": minor
---

Added a new hook to fetch the current connected connector `useCurrentConnector`
5 changes: 5 additions & 0 deletions .changeset/poor-beers-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuels/react": minor
---

Added a component "WebWallet" to increase UX when using connectors
5 changes: 5 additions & 0 deletions .changeset/weak-pots-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"docs": minor
---

Added a new section on the docs for the hook `useCurrentConnector`
6 changes: 3 additions & 3 deletions examples/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
"@wagmi/core": "2.13.4",
"clsx": "2.1.1",
"fuels": "0.94.8",
"react": "18.3.1",
"react-dom": "18.3.1"
"react": "18.2.0",
"react-dom": "18.2.0"
LuizAsFight marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"@tanstack/react-query-devtools": "5.35.1",
"@types/react": "18.3.1",
"@types/react": "18.2.54",
LuizAsFight marked this conversation as resolved.
Show resolved Hide resolved
"@types/react-dom": "18.3.0",
"@vitejs/plugin-react": "4.2.1",
"autoprefixer": "10.4.19",
Expand Down
9 changes: 7 additions & 2 deletions examples/react-app/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ const FUEL_CONFIG = {
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<QueryClientProvider client={queryClient}>
<FuelProvider theme="dark" networks={NETWORKS} fuelConfig={FUEL_CONFIG}>
<FuelProvider
theme="dark"
networks={NETWORKS}
fuelConfig={FUEL_CONFIG}
showWebWallet
>
<Toast.Provider>
<App />
<Toast.Viewport
Expand All @@ -82,7 +87,7 @@ ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<ScreenSizeIndicator />
</FuelProvider>

<ReactQueryDevtools initialIsOpen={false} />
<ReactQueryDevtools initialIsOpen={false} buttonPosition="bottom-left" />
</QueryClientProvider>
</React.StrictMode>,
);
2 changes: 1 addition & 1 deletion examples/react-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"devDependencies": {
"@tanstack/react-query-devtools": "5.35.1",
"@types/node": "20.12.11",
"@types/react": "18.3.1",
"@types/react": "18.2.54",
LuizAsFight marked this conversation as resolved.
Show resolved Hide resolved
"@types/react-dom": "18.3.0",
"typescript": "5.4.5"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { FuelWalletConnector } from '@fuel-connectors/fuel-wallet';
import type { ConnectorMetadata } from 'fuels';

export class FuelWalletDevelopmentConnector extends FuelWalletConnector {
name = 'Fuel Wallet Development';
metadata: ConnectorMetadata = {
image: '/connectors/fuel-wallet-dev.svg',
install: {
Expand Down
2 changes: 1 addition & 1 deletion packages/fuel-wallet/src/FuelWalletConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
} from './types';

export class FuelWalletConnector extends FuelConnector {
name = '';
name = 'Fuel Wallet';
connected = false;
installed = false;
external = false;
Expand Down
21 changes: 15 additions & 6 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
}
}
},
"files": ["dist"],
"scripts": {
"build": "pnpm ts:check && tsup",
"build:watch": "tsup --watch",
Expand All @@ -31,17 +32,25 @@
"react": ">=18.0.0"
},
"dependencies": {
"@radix-ui/react-dialog": "1.1.1",
"events": "3.3.0"
"@fuels/ui": "0.1.2",
"@tabler/icons-react": "2.47.0",
"events": "^3.3.0",
"tailwind-variants": "0.1.20"
},
"devDependencies": {
"@tanstack/react-query": "5.35.1",
"@types/react": "18.3.1",
"compare-versions": "6.1.0",
"@types/react": "18.2.54",
"compare-versions": "^6.1.0",
"fuels": "0.94.8",
"react": "18.3.1",
"react": "^18.2.0",
"styled-components": "6.1.12",
"tailwindcss": "3.4.4",
"@radix-ui/react-dialog": "1.1.1",
"events": "3.3.0",
"tsup": "7.3.0",
"tsx": "4.9.3",
"typescript": "5.4.5"
"typescript": "5.4.5",
"postcss": "8.4.35",
"postcss-import": "16.0.1"
}
}
8 changes: 8 additions & 0 deletions packages/react/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
plugins: {
'postcss-import': {},
'tailwindcss/nesting': {},
tailwindcss: {},
autoprefixer: {},
},
};
1 change: 1 addition & 0 deletions packages/react/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from './useBalance';
export * from './useChain';
export * from './useConnect';
export * from './useContractRead';
export * from './useCurrentConnector';
export * from './useConnectors';
export * from './useDisconnect';
export * from './useIsConnected';
Expand Down
4 changes: 4 additions & 0 deletions packages/react/src/providers/FuelProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { NetworkConfig, UIConfig } from '../types';
import { BridgeDialog } from '../ui/Connect/components/Bridge/BridgeDialog';
import { NetworkDialog } from '../ui/Connect/components/Network/NetworkDialog';
import { useNetworkConfigs } from '../ui/Connect/hooks/useNetworkConfigs';
import { WebWallet } from '../ui/WebWallet';
import { FuelHooksProvider } from './FuelHooksProvider';
import { FuelUIProvider, type FuelUIProviderProps } from './FuelUIProvider';

Expand All @@ -15,6 +16,7 @@ export { useConnectUI } from './FuelUIProvider';

type FuelProviderProps = {
ui?: boolean;
showWebWallet?: boolean;
LuizAsFight marked this conversation as resolved.
Show resolved Hide resolved
uiConfig?: UIConfig;
fuelConfig?: FuelConfig;
networks?: Array<NetworkConfig>;
Expand All @@ -26,6 +28,7 @@ export function FuelProvider({
fuelConfig,
uiConfig: _uiConfig,
ui = true,
showWebWallet = false,
networks: _networks,
}: FuelProviderProps) {
const theme = _theme || 'light';
Expand All @@ -49,6 +52,7 @@ export function FuelProvider({
uiConfig={uiConfig}
>
<Connect />
{showWebWallet && <WebWallet />}
{networks != null && <NetworkDialog theme={theme} />}
{uiConfig.suggestBridge && <BridgeDialog theme={theme} />}
{children}
Expand Down
10 changes: 7 additions & 3 deletions packages/react/src/providers/FuelUIProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {
useState,
} from 'react';

import { useConnect } from '../hooks/useConnect';
import { useConnectors } from '../hooks/useConnectors';

import { Theme, type ThemeProps } from '@fuels/ui';
import { NATIVE_CONNECTORS } from '../config';
import { useIsConnected } from '../hooks';
import { useConnect } from '../hooks/useConnect';
import { useConnectors } from '../hooks/useConnectors';
import type { UIConfig } from '../types';
import { isNativeConnector } from '../utils';

Expand Down Expand Up @@ -174,6 +174,10 @@ export function FuelUIProvider({
return isLoadingConnectors || hasLoadedConnectors;
}, [connectors, isLoadingConnectors, fuelConfig]);

const _dsTheme: ThemeProps = {
hasBackground: false,
appearance: theme === 'dark' ? 'dark' : 'light',
};
const handleConnect = useCallback(() => {
setConnector(null);
setError(null);
Expand Down
32 changes: 32 additions & 0 deletions packages/react/src/ui/WebWallet/components/Anchor/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Button } from '@fuels/ui';
import { IconWallet } from '@tabler/icons-react';
import React from 'react';

export interface AnchorProps {
address: string;
onClick?: () => void;
isLoading: boolean;
isConnected: boolean;
}

const AnchorComponent = (
{ address, onClick, isLoading, isConnected }: AnchorProps,
ref: React.ForwardedRef<HTMLButtonElement> | null,
) => {
return (
<Button
radius="full"
onClick={onClick}
leftIcon={IconWallet}
size={'2'}
isLoading={isLoading && isConnected}
disabled={!isConnected}
ref={ref}
color="gray"
>
{address && isConnected ? address : 'Connect your wallet'}
</Button>
);
};

export const Anchor = React.forwardRef(AnchorComponent);
86 changes: 86 additions & 0 deletions packages/react/src/ui/WebWallet/components/Assets/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {
Card,
EntityItem,
EntityItemInfo,
EntityItemSlot,
HStack,
Icon,
Text,
Tooltip,
VStack,
} from '@fuels/ui';
import { IconCoins } from '@tabler/icons-react';
import { useBalanceFormat } from '../../hooks/useBalanceFormat';
import type { IAssetsBalance } from '../../types';
import { AvatarGenerated } from '../AvatarGenerated';

export interface AssetsProps {
assets: IAssetsBalance[];
hideAmount: boolean;
}

export const Assets = ({ assets, hideAmount }: AssetsProps) => {
return (
<VStack
gap={{
md: '3',
initial: '2',
}}
>
<HStack gap="1" align="center">
<Icon icon={IconCoins} />
<Text
size={{
md: '3',
initial: '1',
}}
weight="medium"
>
Assets
</Text>
</HStack>
<VStack gap="1">
{assets.map((asset) => {
const { formattedBalance, formattedBalanceFull } = useBalanceFormat(
asset.amount,
asset.decimals,
);
const valueOrHidden = hideAmount ? '•'.repeat(5) : formattedBalance;
const tokenOrId = asset.symbol === 'UNK' ? asset.id : asset.symbol;

return (
<Card key={asset.id} variant="classic" p={'4'}>
<HStack align="center" justify="between">
<EntityItem key={asset.id}>
<EntityItemSlot>
<AvatarGenerated
size="2"
src={asset.icon}
hash={asset.id}
/>
</EntityItemSlot>
<EntityItemInfo
id={tokenOrId}
title={
(
<Text size="2" color="gray" highContrast>
{asset.name}
</Text>
) as string & React.ReactElement
}
/>
</EntityItem>

<Tooltip content={formattedBalanceFull}>
<Text size="2" weight="regular" color="gray" highContrast>
{valueOrHidden}
</Text>
</Tooltip>
</HStack>
</Card>
);
})}
</VStack>
</VStack>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Avatar, type AvatarProps } from '@fuels/ui';
import { useGenerateBackground } from '../../hooks/useGenerateBackground';

export type AvatarGeneratedProps = { hash: string } & Omit<
AvatarProps,
'fallback'
>;

const GeneratedFallback = ({ hash }: { hash: string }) => {
return (
<div
className="h-full w-full rounded-full"
style={{
background: useGenerateBackground(hash),
}}
/>
);
};

export const AvatarGenerated = ({ hash, ...props }: AvatarGeneratedProps) => {
return (
<Avatar {...props} size="4" fallback={<GeneratedFallback hash={hash} />} />
);
};
Loading
Loading