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

refactor: lib and services #511

Merged
merged 5 commits into from
Sep 4, 2023
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
3 changes: 3 additions & 0 deletions snapshots.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright 2022 @paritytech/contracts-ui authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

module.exports = {
__version: '12.17.2',
'Storage Types Contract': {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/helpers/callOptions.ts → src/lib/callOptions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2022 @paritytech/contracts-ui authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import { BN_ZERO } from './bn';
import { randomAsU8a } from './util';
import { BN_ZERO } from './bn';
import { UIStorageDeposit, ContractCallOutcome, BN, WeightV2, AbiParam, Registry } from 'types';

export function decodeStorageDeposit(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { TypeRegistry } from '@polkadot/types/create';
import { DEFAULT_DECIMALS } from '../constants';
import { DEFAULT_DECIMALS } from '../../constants';
import { ChainProperties, ApiPromise } from 'types';

const registry = new TypeRegistry();
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/contract.ts → src/services/chain/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: GPL-3.0-only

import { BlueprintPromise, CodePromise } from '@polkadot/api-contract';
import { isValidAddress, isValidCodeHash, isNumber } from './util';
import { transformUserInput } from './callOptions';
import { isValidAddress, isValidCodeHash, isNumber } from 'lib/util';
import { transformUserInput } from 'lib/callOptions';
import {
ApiPromise,
CodeBundleDocument,
Expand Down
8 changes: 1 addition & 7 deletions src/helpers/index.ts → src/services/chain/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
// Copyright 2022 @paritytech/contracts-ui authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

export * from './blockTime';
export * from './bn';
export * from './initValue';
export * from './callOptions';
export * from './util';
export * from './contract';
export * from './chainProps';
export * from './output';
export * from './contract';
File renamed without changes.
2 changes: 1 addition & 1 deletion src/types/db.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2022 @paritytech/contracts-ui authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import { Database, CodeBundleDocument, ContractDocument } from 'db';
import { Database, CodeBundleDocument, ContractDocument } from 'src/services/db';

export type { CodeBundleDocument, ContractDocument, Database };

Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/AwaitApis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isWeb3Injected } from '@polkadot/extension-dapp';
import { AccountsError, ExtensionError } from './common/AccountsError';
import { useApi, useDatabase } from 'ui/contexts';
import { Loader, ConnectionError } from 'ui/components/common';
import { isKeyringLoaded } from 'helpers';
import { isKeyringLoaded } from 'lib/util';

export function AwaitApis({ children }: HTMLAttributes<HTMLDivElement>): React.ReactElement {
const { accounts, api, endpoint, status, systemChainType } = useApi();
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/Transactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import { BellIcon, XIcon } from '@heroicons/react/outline';
import { NotificationIcon } from './common/NotificationIcon';
import { classes, isEmptyObj } from 'lib/util';
import type { QueuedTxOptions, TransactionsState } from 'types';
import { classes, isEmptyObj } from 'helpers';

export function Transactions({
dismiss,
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/account/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Identicon } from './Identicon';
import { classes, truncate } from 'helpers';
import { classes, truncate } from 'lib/util';
import { OrFalsy } from 'types';
import { useApi } from 'ui/contexts';

Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/account/Identicon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import copy from 'copy-to-clipboard';
import React, { useCallback } from 'react';
import { Tooltip } from 'react-tooltip';
import { Button } from '../common';
import { classes } from 'helpers';
import { classes } from 'lib/util';

export interface Props extends React.HTMLAttributes<HTMLImageElement> {
value?: string | null;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/account/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Account } from './Account';
import { createAccountOptions } from 'ui/util/dropdown';
import type { DropdownOption, DropdownProps, ValidFormField } from 'types';
import { useApi, useDatabase } from 'ui/contexts';
import { classes } from 'helpers';
import { classes } from 'lib/util';
import { useDbQuery } from 'ui/hooks';

type Props = ValidFormField<string> & Omit<DropdownProps<string>, 'options'>;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/common/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import React from 'react';
import { classes } from 'helpers';
import { classes } from 'lib/util';

type Variant = 'default' | 'primary' | 'plain' | 'negative';

Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/common/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { MouseEventHandler, useCallback, useRef, useState } from 'react';
import { DocumentDuplicateIcon } from '@heroicons/react/outline';
import { Tooltip } from 'react-tooltip';
import { Button } from './Button';
import { classes } from 'helpers';
import { classes } from 'lib/util';

interface Props extends React.HTMLAttributes<unknown> {
iconClassName?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/common/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import CreatableSelect from 'react-select/creatable';

import { CheckIcon, ChevronDownIcon } from '@heroicons/react/solid';
import { classes, isValidAddress } from 'helpers';
import { classes, isValidAddress } from 'lib/util';
import type { DropdownOption, DropdownProps } from 'types';

function isGroupedOptions<T>(
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/common/Error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { ExclamationCircleIcon } from '@heroicons/react/outline';
import { classes } from 'helpers';
import { classes } from 'lib/util';

type Props = React.HTMLProps<HTMLDivElement>;

Expand Down
11 changes: 6 additions & 5 deletions src/ui/components/common/HeaderButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import { useEffect, useState } from 'react';
import { ArrowCircleRightIcon, TrashIcon } from '@heroicons/react/outline';
import { Link, useNavigate } from 'react-router-dom';
import { getContractInfo } from 'services/chain';
import { ForgetContractModal } from 'ui/components/modal';
import { useApi, useDatabase } from 'ui/contexts';
import { getContractInfo, truncate } from 'helpers';
import { truncate } from 'lib/util';
import type { UIContract } from 'types';

interface Props {
Expand Down Expand Up @@ -39,22 +40,22 @@ export function HeaderButtons({ contract: { address, codeHash } }: Props) {
<div className="inline-flex h-8">
{isOnChain ? (
<Link to={`/instantiate/${codeHash}`}>
<button className="mr-2 flex h-full items-center rounded border px-3 font-semibold text-gray-600 hover:text-gray-400 dark:border-gray-700 dark:bg-elevation-1 dark:text-gray-300 dark:hover:bg-elevation-2">
<button className="flex items-center h-full px-3 mr-2 font-semibold text-gray-600 border rounded hover:text-gray-400 dark:border-gray-700 dark:bg-elevation-1 dark:text-gray-300 dark:hover:bg-elevation-2">
<ArrowCircleRightIcon
aria-hidden="true"
className="mr-1 w-4 justify-self-end dark:text-gray-500"
className="w-4 mr-1 justify-self-end dark:text-gray-500"
fontSize="1.5rem"
/>
Reinstantiate
</button>
</Link>
) : (
<p className="mr-3 flex items-center font-semibold text-red-400">{`Not found at ${truncate(
<p className="flex items-center mr-3 font-semibold text-red-400">{`Not found at ${truncate(
address,
)}`}</p>
)}
<button
className="flex h-full items-center rounded border px-3 font-semibold text-gray-600 hover:text-gray-400 dark:border-gray-700 dark:bg-elevation-1 dark:text-gray-300 dark:hover:bg-elevation-2"
className="flex items-center h-full px-3 font-semibold text-gray-600 border rounded hover:text-gray-400 dark:border-gray-700 dark:bg-elevation-1 dark:text-gray-300 dark:hover:bg-elevation-2"
onClick={() => {
setIsOpen(true);
}}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/common/NotificationIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { CheckIcon, ClockIcon, ExclamationCircleIcon } from '@heroicons/react/outline';
import { Spinner } from './Spinner';
import { TxStatus } from 'types';
import { classes } from 'helpers';
import { classes } from 'lib/util';

interface Props {
status?: TxStatus;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/common/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { CodeIcon } from '@heroicons/react/outline';
import { CodeBundleDocument, ContractDocument, VoidFn } from 'types';
import { classes } from 'helpers';
import { classes } from 'lib/util';

interface ItemProps extends React.HTMLAttributes<HTMLDivElement> {
name: React.ReactNode;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/common/SidePanel.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2022 @paritytech/contracts-ui authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import { classes } from 'helpers';
import { classes } from 'lib/util';

interface Props extends React.HTMLAttributes<HTMLDivElement> {
header: React.ReactNode;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/common/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2022 @paritytech/contracts-ui authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import { classes } from 'helpers';
import { classes } from 'lib/util';

interface Props extends React.HTMLAttributes<HTMLDivElement> {
strokeWidth?: number;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/common/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { Switch as HUISwitch } from '@headlessui/react';
import { classes } from 'helpers';
import { classes } from 'lib/util';
import { SimpleSpread } from 'types';

type Props = SimpleSpread<
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/common/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import type { SetState } from 'types';
import { classes } from 'helpers';
import { classes } from 'lib/util';

interface Tab {
id: string;
Expand Down
3 changes: 2 additions & 1 deletion src/ui/components/contract/ContractRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { Link } from 'react-router-dom';
import { Identicon } from '../account/Identicon';
import { ContractDocument } from 'types';
import { useApi } from 'ui/contexts';
import { getContractInfo, displayDate } from 'helpers';
import { displayDate } from 'lib/util';
import { getContractInfo } from 'services/chain';

interface Props {
contract: ContractDocument;
Expand Down
4 changes: 3 additions & 1 deletion src/ui/components/contract/DryRunResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import { AbiMessage } from '@polkadot/api-contract/types';
import { DryRunError } from './DryRunError';
import { OutcomeItem } from './OutcomeItem';
import { classes, decodeStorageDeposit, getDecodedOutput } from 'helpers';
import { classes } from 'lib/util';
import { ContractExecResult, Registry } from 'types';
import { useApi } from 'ui/contexts';
import { getDecodedOutput } from 'lib/output';
import { decodeStorageDeposit } from 'lib/callOptions';

interface Props {
outcome: ContractExecResult;
Expand Down
16 changes: 8 additions & 8 deletions src/ui/components/contract/Interact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ import {
import { AccountSelect } from 'ui/components/account';
import { Dropdown, Button, Buttons } from 'ui/components/common';
import { ArgumentForm, Form, FormField, OptionsForm } from 'ui/components/form';
import {
transformUserInput,
BN_ZERO,
getGasLimit,
getStorageDepositLimit,
decodeStorageDeposit,
getDecodedOutput,
} from 'helpers';
import { BN_ZERO } from 'lib/bn';
import { useApi, useTransactions } from 'ui/contexts';
import { useWeight, useBalance, useArgValues } from 'ui/hooks';
import { useStorageDepositLimit } from 'ui/hooks/useStorageDepositLimit';
import { createMessageOptions } from 'ui/util/dropdown';
import {
decodeStorageDeposit,
getGasLimit,
getStorageDepositLimit,
transformUserInput,
} from 'lib/callOptions';
import { getDecodedOutput } from 'lib/output';

interface Props {
contract: UIContract;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/form/ArgumentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ArgSignature } from '../message/ArgSignature';
import { Form, FormField } from './FormField';
import { findComponent } from './findComponent';
import { AbiParam, Registry, SetState } from 'types';
import { classes } from 'helpers';
import { classes } from 'lib/util';

interface Props extends React.HTMLAttributes<HTMLFormElement> {
args: AbiParam[];
Expand Down
3 changes: 2 additions & 1 deletion src/ui/components/form/Enum.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { useCallback, useState } from 'react';
import { Dropdown } from '../common/Dropdown';
import { ArgSignature } from '../message/ArgSignature';
import { FormField, getValidation } from './FormField';
import { isNumber, getInitValue } from 'helpers';
import { isNumber } from 'lib/util';
import { ArgComponentProps, OrFalsy, TypeDef } from 'types';
import { useApi } from 'ui/contexts';
import { getInitValue } from 'lib/initValue';

interface Props extends ArgComponentProps<Record<string, unknown>> {
components: React.ComponentType<ArgComponentProps<unknown>>[];
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/form/FormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { useMemo } from 'react';
import { Tooltip } from 'react-tooltip';
import type { Validation } from 'types';
import { classes } from 'helpers';
import { classes } from 'lib/util';

type ValidationState = 'error' | 'success' | 'warning' | null;

Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/form/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { SimpleSpread } from 'types';
import { classes } from 'helpers';
import { classes } from 'lib/util';

type Props = SimpleSpread<
React.InputHTMLAttributes<HTMLInputElement>,
Expand Down
3 changes: 2 additions & 1 deletion src/ui/components/form/InputBalance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import React, { useState } from 'react';
import BN from 'bn.js';

import { InputNumber } from './InputNumber';
import { BN_ZERO, classes, fromBalance, fromSats, toBalance } from 'helpers';
import { classes } from 'lib/util';
import { ApiPromise, OrFalsy, SimpleSpread } from 'types';
import { useApi } from 'ui/contexts';
import { BN_ZERO, fromBalance, fromSats, toBalance } from 'lib/bn';

type Props = SimpleSpread<
React.InputHTMLAttributes<HTMLInputElement>,
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/form/InputBytes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { hexToU8a } from '@polkadot/util';
import React, { useCallback, useMemo, useState } from 'react';
import { Input } from './Input';
import { classes } from 'helpers';
import { classes } from 'lib/util';
import { ArgComponentProps } from 'types';

type Props = ArgComponentProps<Uint8Array> & { length?: number };
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/form/InputHex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { useCallback, useState } from 'react';
import { Input } from './Input';
import { classes } from 'helpers';
import { classes } from 'lib/util';

interface Props {
onChange: (_: string) => void;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/form/InputNumber.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2022 @paritytech/contracts-ui authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import { classes } from 'helpers';
import { classes } from 'lib/util';

export function InputNumber({
children,
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/form/InputStorageDepositLimit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Meter, Switch } from '../common';
import { InputBalance } from './InputBalance';
import { getValidation } from './FormField';
import type { SimpleSpread, UseStorageDepositLimit } from 'types';
import { classes, isNull, isNumber } from 'helpers';
import { classes, isNull, isNumber } from 'lib/util';

type Props = SimpleSpread<
React.HTMLAttributes<HTMLDivElement>,
Expand Down
3 changes: 2 additions & 1 deletion src/ui/components/form/Option.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { Switch } from '../common/Switch';
import { Input } from './Input';
import { ArgComponentProps, OrFalsy, Registry, TypeDef } from 'types';
import { useApi } from 'ui/contexts';
import { getInitValue, NOOP } from 'helpers';
import { NOOP } from 'lib/util';
import { useToggle } from 'ui/hooks/useToggle';
import { getInitValue } from 'lib/initValue';

interface Props extends ArgComponentProps<unknown> {
component: React.ComponentType<ArgComponentProps<unknown>>;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/form/SubForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2022 @paritytech/contracts-ui authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import { classes } from 'helpers';
import { classes } from 'lib/util';

interface Props extends React.HTMLAttributes<HTMLDivElement> {
nestingNumber: number;
Expand Down
Loading