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

EVM Staking - Add wallet connect and show connected network #1818

Merged
merged 30 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
482ce71
chore: wrap tangle-dapp with webb provider
devpavan04 Nov 1, 2023
3fd8b07
fix: build issue when importing `@webb-tools/api-provider-environment…
AtelyPham Nov 2, 2023
4f2981a
ci: bump wagmi and viem to latest version
AtelyPham Nov 2, 2023
07b028c
chore: extract all providers into separate file on tange-dapp
AtelyPham Nov 2, 2023
2f890ed
fix: local storage is not defined errors
AtelyPham Nov 2, 2023
16f5c0a
chore: ignore the critical dependency warning from @webb-tools/utils
AtelyPham Nov 2, 2023
c29a36b
chore: install the @polkadot/util to fix the multiple version issue
AtelyPham Nov 2, 2023
4a99fe0
chore: revert local dependencies
AtelyPham Nov 2, 2023
0dad4b3
ci: bump webb.js to fix the next.js build errors
AtelyPham Nov 2, 2023
56dede4
chore: adds connect wallet functionality
devpavan04 Nov 3, 2023
b1127e1
chore: show connected network
devpavan04 Nov 7, 2023
0eb7c74
chore: update validator format balance
devpavan04 Nov 7, 2023
12fc9db
Merge branch 'develop' into PS/tangle-dapp-wallet-connection
devpavan04 Nov 7, 2023
bac35c2
commit
devpavan04 Nov 7, 2023
f436939
chore: remove use client from store in api-provider-env
devpavan04 Nov 7, 2023
557eae6
chore: remove unused variable
devpavan04 Nov 7, 2023
28c7851
fix: ci errors
devpavan04 Nov 7, 2023
9015b8d
chore: update documentation of generate note
devpavan04 Nov 8, 2023
0e3c5ef
chore: remove todo comment on wallet handleDisconnect
devpavan04 Nov 8, 2023
9d4d49d
chore: add webpack resolution
devpavan04 Nov 9, 2023
0df6fe5
chore: remove dest and src consts and move useConnectWallet to api-pr…
devpavan04 Nov 10, 2023
4062c87
chore: update ConnectWalletMobileButton component
devpavan04 Nov 10, 2023
8191812
fix: ci error
devpavan04 Nov 10, 2023
b3e4026
fix: ci error
devpavan04 Nov 10, 2023
e6943c2
fix: @nx/enforce-module-boundaries error in useConnectWallet
devpavan04 Nov 10, 2023
55bce37
chore: move walletModal to ui-components, update prop types
devpavan04 Nov 12, 2023
dacfc46
fix: forbidden non-null errors in stats-dapp
devpavan04 Nov 12, 2023
3f67f51
chore: code format
devpavan04 Nov 12, 2023
57e8251
fix: unused prop error
devpavan04 Nov 12, 2023
5f4ec2e
fix: same library should use relative import
AtelyPham Nov 13, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ function useDepositButtonProps({
destTypedIdNum,
destAnchorId,
fungible.symbol,
fungible.decimals,
amountBig
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ function useTransferButtonProps({
!!fungibleCfg.addresses.get(parseInt(note.note.targetChainId))
);

const fungibleDecimals = fungibleCfg.decimals;
const amountBig = BigInt(amount);

// Get the notes that will be spent for this withdraw
Expand Down Expand Up @@ -340,7 +339,6 @@ function useTransferButtonProps({
srcTypedChainId,
anchorId,
fungibleCfg.symbol,
fungibleDecimals,
changeAmount
)
: undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ function useWithdrawButtonProps({
srcTypedChainId,
anchorId,
fungibleCfg.symbol,
fungibleDecimals,
changeAmount
)
: undefined;
Expand Down
12 changes: 12 additions & 0 deletions apps/bridge-dapp/webpack.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,18 @@ function createWebpack(env, mode = 'production') {
new MiniCssExtractPlugin({
filename: '[name].[contenthash:8].css',
}),

/**
* Ignore the critical dependency warning for @webb-tools/utils
* as the library uses dynamic imports for the fixtures in fixtures.ts
*/
new webpack.ContextReplacementPlugin(
/\/@webb-tools\/utils\//,
(/** @type {{ dependencies: { critical: any; }[]; }} */ data) => {
delete data.dependencies[0].critical;
return data;
}
),
].concat(plugins),
resolve: {
alias: {
Expand Down
12 changes: 12 additions & 0 deletions apps/stats-dapp/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,18 @@ function createWebpackBase() {
new webpack.DefinePlugin({
...bridgeEnvVars,
}),

/**
* Ignore the critical dependency warning for @webb-tools/utils
* as the library uses dynamic imports for the fixtures in fixtures.ts
*/
new webpack.ContextReplacementPlugin(
/\/@webb-tools\/utils\//,
(/** @type {{ dependencies: { critical: any; }[]; }} */ data) => {
delete data.dependencies[0].critical;
return data;
}
),
]
.concat(plugins)
.filter(Boolean),
Expand Down
6 changes: 3 additions & 3 deletions apps/tangle-dapp/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import '@webb-tools/webb-ui-components/tailwind.css';

import NextThemeProvider from '@webb-tools/api-provider-environment/NextThemeProvider';
import { TANGLE_DAPP_URL } from '@webb-tools/webb-ui-components/constants';
import { Metadata } from 'next';
import type React from 'react';

import { Layout } from '../containers';
import Providers from './providers';

export const metadata: Metadata = {
title: {
Expand Down Expand Up @@ -49,9 +49,9 @@ export default function RootLayout({
return (
<html lang="en" suppressHydrationWarning>
<body className="flex h-screen bg-body">
<NextThemeProvider>
<Providers>
<Layout>{children}</Layout>
</NextThemeProvider>
</Providers>
</body>
</html>
);
Expand Down
36 changes: 36 additions & 0 deletions apps/tangle-dapp/app/providers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use client';

import {
AppEvent,
NextThemeProvider,
WebbProvider,
} from '@webb-tools/api-provider-environment';
import { WebbUIProvider } from '@webb-tools/webb-ui-components';
import NextAdapterApp from 'next-query-params/app';
import qs from 'query-string';
import type { PropsWithChildren } from 'react';
import { QueryParamProvider } from 'use-query-params';

const appEvent = new AppEvent();

const Providers = ({ children }: PropsWithChildren) => {
return (
<NextThemeProvider>
<WebbUIProvider hasErrorBoudary>
<WebbProvider appEvent={appEvent} applicationName="Tangle Dapp">
<QueryParamProvider
adapter={NextAdapterApp}
options={{
searchStringToObject: qs.parse,
objectToSearchString: qs.stringify,
}}
>
{children}
</QueryParamProvider>
</WebbProvider>
</WebbUIProvider>
</NextThemeProvider>
);
};

export default Providers;
31 changes: 31 additions & 0 deletions apps/tangle-dapp/components/ChainSelector/ChainSelector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use client';

import { useWebContext } from '@webb-tools/api-provider-environment/webb-context/webb-context';
import ChainButtonCmp from '@webb-tools/webb-ui-components/components/buttons/ChainButton';
import { useMemo } from 'react';

const ChainSelector = () => {
const { activeChain, activeAccount } = useWebContext();

const chain = useMemo(() => {
if (activeChain) {
return activeChain;
}
}, [activeChain]);

return (
<>
{activeAccount && chain && (
<ChainButtonCmp
chain={chain}
status="success"
placeholder={activeChain === null ? 'Unsupported Chain' : undefined}
textClassname="hidden lg:block"
disabled
/>
)}
</>
);
};

export default ChainSelector;
1 change: 1 addition & 0 deletions apps/tangle-dapp/components/ChainSelector/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as ChainSelector } from './ChainSelector';
149 changes: 149 additions & 0 deletions apps/tangle-dapp/components/WalletDropdown/WalletDropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
'use client';

import { Trigger as DropdownTrigger } from '@radix-ui/react-dropdown-menu';
import { Account } from '@webb-tools/abstract-api-provider';
import { useWebContext } from '@webb-tools/api-provider-environment';
import { ManagedWallet, WalletConfig } from '@webb-tools/dapp-config';
import { WebbError, WebbErrorCodes } from '@webb-tools/dapp-types';
import {
ExternalLinkLine,
LoginBoxLineIcon,
WalletLineIcon,
} from '@webb-tools/icons';
import { useWallets } from '@webb-tools/react-hooks';
import { isViemError, WebbWeb3Provider } from '@webb-tools/web3-api-provider';
import {
Button,
Dropdown,
DropdownBody,
KeyValueWithButton,
Typography,
useWebbUI,
WalletButton,
} from '@webb-tools/webb-ui-components';
import { FC, useCallback, useMemo } from 'react';

export const WalletDropdown: FC<{ account: Account; wallet: WalletConfig }> = ({
account,
wallet,
}) => {
const { activeApi, activeChain, inactivateApi } = useWebContext();

const { notificationApi } = useWebbUI();

// Get all managed wallets
const { wallets } = useWallets();

const currentManagedWallet = useMemo<ManagedWallet | undefined>(() => {
return wallets.find((w) => w.connected);
}, [wallets]);

// Calculate the account explorer url
const accountExplorerUrl = useMemo(() => {
if (!activeChain?.blockExplorers) return '#';

const url = activeChain.blockExplorers.default.url;

return new URL(`/address/${account.address}`, url).toString();
}, [activeChain, account]);

// Funciton to switch account within the connected wallet
const handleSwitchAccount = useCallback(async () => {
// Switch account only support on web3 provider
if (!activeApi || !(activeApi instanceof WebbWeb3Provider)) {
return;
}

try {
const walletClient = activeApi.walletClient;

await walletClient.requestPermissions({ eth_accounts: {} });
} catch (error) {
let message = WebbError.from(WebbErrorCodes.SwitchAccountFailed).message;

if (isViemError(error)) {
message = error.shortMessage;
}

notificationApi({ variant: 'error', message });
}
}, [activeApi, notificationApi]);

// Disconnect function
// TODO: The disconnect function does not work properly
drewstone marked this conversation as resolved.
Show resolved Hide resolved
const handleDisconnect = useCallback(async () => {
try {
if (currentManagedWallet && currentManagedWallet.canEndSession) {
currentManagedWallet.endSession();
}

await inactivateApi();
} catch {
const message = WebbError.getErrorMessage(
WebbErrorCodes.FailedToDisconnect
).message;

notificationApi({ variant: 'error', message });
}
}, [currentManagedWallet, inactivateApi, notificationApi]);

return (
<Dropdown>
<DropdownTrigger asChild>
<WalletButton
wallet={wallet}
address={account.address}
addressClassname="hidden lg:block"
/>
</DropdownTrigger>

<DropdownBody className="mt-6 w-[480px] p-4 space-y-4 dark:bg-mono-160">
<div className="flex items-center justify-between">
<div className="flex space-x-2">
{wallet.Logo}

<div>
<Typography variant="h5" fw="bold" className="capitalize">
{account.name || wallet.name}
</Typography>

<div className="flex items-center space-x-1">
<KeyValueWithButton
className="mt-0.5"
isHiddenLabel
keyValue={account.address}
size="sm"
labelVariant="body1"
valueVariant="body1"
/>

<a href={accountExplorerUrl} target="_blank" rel="noreferrer">
<ExternalLinkLine />
</a>
</div>
</div>
</div>
<div className="flex items-center justify-end space-x-2.5">
<Button
onClick={handleSwitchAccount}
leftIcon={<WalletLineIcon className="!fill-current" size="lg" />}
variant="link"
>
Switch
</Button>

<Button
onClick={handleDisconnect}
leftIcon={
<LoginBoxLineIcon className="!fill-current" size="lg" />
}
variant="link"
>
Disconnect
</Button>
</div>
</div>
</DropdownBody>
</Dropdown>
);
};
1 change: 1 addition & 0 deletions apps/tangle-dapp/components/WalletDropdown/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './WalletDropdown';
Loading
Loading