Skip to content

Commit

Permalink
fix(extension): #37: add loader to rpc validation
Browse files Browse the repository at this point in the history
  • Loading branch information
VanishMax committed Jun 24, 2024
1 parent 93cc701 commit 6653286
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FormEvent, useRef } from 'react';
import { SelectList } from '@repo/ui/components/ui/select-list';
import { Button } from '@repo/ui/components/ui/button';
import { Network } from 'lucide-react';
import { Network, Loader2 } from 'lucide-react';
import { useGrpcEndpointForm } from './use-grpc-endpoint-form';
import { ConfirmChangedChainIdDialog } from './confirm-changed-chain-id-dialog';
import { ChainIdOrError } from './chain-id-or-error';
Expand Down Expand Up @@ -29,6 +29,7 @@ export const GrpcEndpointForm = ({
rpcError,
isSubmitButtonEnabled,
isCustomGrpcEndpoint,
isValidationLoading,
} = useGrpcEndpointForm();
const customGrpcEndpointInput = useRef<HTMLInputElement | null>(null);

Expand Down Expand Up @@ -98,7 +99,7 @@ export const GrpcEndpointForm = ({
</div>

<Button variant='gradient' type='submit' disabled={!isSubmitButtonEnabled}>
{submitButtonLabel}
{isValidationLoading ? <Loader2 className='size-4 animate-spin' /> : submitButtonLabel}
</Button>
</form>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const useGrpcEndpointForm = () => {
const [grpcEndpointInput, setGrpcEndpointInput] = useState<string>('');
const [rpcError, setRpcError] = useState<string>();
const [isSubmitButtonEnabled, setIsSubmitButtonEnabled] = useState(false);
const [isValidationLoading, setIsValidationLoading] = useState(false);
const [confirmChangedChainIdPromise, setConfirmChangedChainIdPromise] = useState<
PromiseWithResolvers<void> | undefined
>();
Expand All @@ -56,6 +57,7 @@ export const useGrpcEndpointForm = () => {
if (!isValidUrl(grpcEndpointInput)) return;

try {
setIsValidationLoading(true);
const trialClient = createPromiseClient(
AppService,
createGrpcWebTransport({ baseUrl: grpcEndpointInput }),
Expand Down Expand Up @@ -83,6 +85,8 @@ export const useGrpcEndpointForm = () => {
} else {
setRpcError('Could not connect to endpoint: ' + String(e));
}
} finally {
setIsValidationLoading(false);
}
}, 400);
}, []);
Expand Down Expand Up @@ -150,5 +154,6 @@ export const useGrpcEndpointForm = () => {
onSubmit,
isSubmitButtonEnabled,
isCustomGrpcEndpoint,
isValidationLoading,
};
};

0 comments on commit 6653286

Please sign in to comment.