Skip to content

Commit

Permalink
Refactor hooks compatability
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitayutanov committed Jan 30, 2024
1 parent 6f32058 commit 6332651
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ type Props = {
name: string;
label: string;
inputLabel: string;
value?: string;
direction?: InputProps['direction'];
gap?: InputProps['gap'];
children?: ReactNode;
};

const LabeledCheckbox = ({ name, label, inputLabel, value, direction = 'x', gap, children }: Props) => {
const LabeledCheckbox = ({ name, label, inputLabel, direction = 'x', gap, children }: Props) => {
const { register } = useFormContext();

return (
<InputWrapper size="normal" id={name} direction={direction} gap={gap} label={label} className={styles.inputWrapper}>
<div className={styles.checkboxWrapper}>
<Checkbox label={inputLabel} value={value} {...register(name)} />
<Checkbox label={inputLabel} {...register(name)} />

{children}
</div>
Expand Down
3 changes: 2 additions & 1 deletion utils/gear-hooks/src/hooks/api/useSendMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { web3FromSource } from '@polkadot/extension-dapp';
import { EventRecord } from '@polkadot/types/interfaces';
import { AnyJson, IKeyringPair, ISubmittableResult } from '@polkadot/types/types';
import { HexString } from '@polkadot/util/types';
import { SubmittableExtrinsic } from '@polkadot/api/types';
import { useContext } from 'react';

import { AccountContext, AlertContext, ApiContext } from 'context';
import { DEFAULT_ERROR_OPTIONS, DEFAULT_SUCCESS_OPTIONS } from 'consts';
import { getExtrinsicFailedMessage } from 'utils';
import { SubmittableExtrinsic } from '@polkadot/api/types';

type UseSendMessageOptions = {
disableAlerts?: boolean;
Expand Down
11 changes: 3 additions & 8 deletions utils/gear-hooks/src/hooks/api/voucher/use-voucher-status.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { useContext } from 'react';

import { ApiContext } from 'context';

import { useApproxBlockTimestamp } from '../block';

function useVoucherStatus(expirationBlock: number | undefined) {
const { isV110Runtime } = useContext(ApiContext);
const { blockTimestamp, isBlockTimestampReady } = useApproxBlockTimestamp(expirationBlock);

const expirationTimestamp = isV110Runtime ? blockTimestamp : undefined;
const isVoucherStatusReady = isV110Runtime ? isBlockTimestampReady : true;
const isVoucherActive = isV110Runtime ? !!expirationTimestamp && expirationTimestamp > Date.now() : true;
const expirationTimestamp = blockTimestamp;
const isVoucherStatusReady = isBlockTimestampReady;
const isVoucherActive = !!expirationTimestamp && expirationTimestamp > Date.now();

return { expirationTimestamp, isVoucherStatusReady, isVoucherActive };
}
Expand Down

0 comments on commit 6332651

Please sign in to comment.