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: add request validation #275

Merged
merged 5 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/strange-horses-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-connectors/walletconnect-connector": minor
---

Request message signature to validate access before connecting to applications
3 changes: 3 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
},
"complexity": {
"noForEach": "off"
},
"suspicious": {
"noAsyncPromiseExecutor": "off"
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions examples/react-app/src/components/balance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ const BalanceSkeleton = () => (
);

export default function Balance({ isSigning }: Props) {
const { refetchWallet, balance, address } = useWallet();
const { refetchBalance, balance, address } = useWallet();

useEffect(() => {
const interval = setInterval(() => refetchWallet(), 5000);
const interval = setInterval(() => refetchBalance(), 5000);
return () => clearInterval(interval);
}, [refetchWallet]);
}, [refetchBalance]);

return (
<Feature title="Balance">
Expand Down
2 changes: 0 additions & 2 deletions packages/common/src/PredicateConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import {
FuelConnectorEventTypes,
type JsonAbi,
type Network,
OutputType,
type SelectNetworkArguments,
type TransactionRequestLike,
TransactionResponse,
type Version,
ZeroBytes32,
bn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useEffect, useState } from 'react';
import { useConnectUI } from '../../../../providers/FuelUIProvider';
import { ConnectorIcon } from '../ConnectorIcon';

import { Spinner } from '../Spinner/Spinner';
import {
ConnectorButton,
ConnectorContent,
Expand Down Expand Up @@ -44,6 +45,8 @@ export function Connector({ className, connector, theme }: ConnectorProps) {
ping();
}, [connector, connect, setError]);

const actionText = action || 'Install';

return (
<div className={className}>
<ConnectorImage>
Expand All @@ -56,15 +59,15 @@ export function Connector({ className, connector, theme }: ConnectorProps) {
</ConnectorImage>
<ConnectorContent>
<ConnectorTitle>{connector.name}</ConnectorTitle>
<ConnectorDescription>
{isLoading ? 'Loading...' : description}
</ConnectorDescription>
<ConnectorDescription>{description}</ConnectorDescription>
</ConnectorContent>
{!isLoading && (
<ConnectorButton href={link} target="_blank">
{action || 'Install'}
</ConnectorButton>
)}
<ConnectorButton href={link} target="_blank" aria-disabled={isLoading}>
{isLoading ? (
<Spinner size={26} color="var(--fuel-loader-background)" />
) : (
actionText
)}
</ConnectorButton>
</div>
);
}
24 changes: 24 additions & 0 deletions packages/react/src/ui/Connect/components/Spinner/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import styled, { keyframes } from 'styled-components';

interface SpinnerProps {
size: number;
color: string;
}

const spinAnimation = keyframes`
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
`;

export const Spinner = styled.div<SpinnerProps>`
height: ${({ size }) => size}px;
width: ${({ size }) => size}px;
border: 4px solid rgba(0, 0, 0, 0.1);
border-top-color: ${({ color }) => color};
border-radius: 50%;
animation: ${spinAnimation} 1s infinite linear;
`;
2 changes: 1 addition & 1 deletion packages/react/src/ui/Connect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function Connect() {
<BackIcon size={32} onClick={back} data-connector={!!connector} />
<DialogMain>
{connector ? (
<Connector connector={connector} />
<Connector connector={connector} theme={theme} />
) : (
<Connectors />
)}
Expand Down
Loading
Loading