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: Select camera #2737

Merged
merged 7 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
77 changes: 40 additions & 37 deletions src/renderer/entities/operations/ui/SignatorySelector.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { type BN } from '@polkadot/util';
import { useMemo } from 'react';

import { type Account, type Asset } from '@/shared/core';
import { type Account, type Asset, type ID } from '@/shared/core';
import { useI18n } from '@/shared/i18n';
import { toAddress } from '@/shared/lib/utils';
import { InputHint, Select } from '@/shared/ui';
import { type DropdownOption } from '@/shared/ui/types';
import { InputHint } from '@/shared/ui';
import { Address } from '@/shared/ui-entities';
import { Field, Select } from '@/shared/ui-kit';
import { AssetBalance } from '@/entities/asset';
import { AccountAddress, accountUtils } from '@/entities/wallet';
import { accountUtils } from '@/entities/wallet';

type Props = {
signatory?: Account | null;
Expand All @@ -30,42 +30,45 @@ export const SignatorySelector = ({
}: Props) => {
const { t } = useI18n();

const options = useMemo(
() =>
signatories.map<DropdownOption>(({ signer, balance }) => {
const isShard = accountUtils.isShardAccount(signer);
const address = toAddress(signer.accountId, { prefix: addressPrefix });
const selectSigner = (signerId: ID) => {
const selectedSigner = signatories.find(({ signer }) => signer.id === signerId);
if (!selectedSigner) return;

return {
id: signer.id.toString(),
value: signer,
element: (
<div className="flex w-full items-center justify-between">
<AccountAddress
size={20}
type="short"
address={address}
name={isShard ? address : signer.name}
canCopy={false}
/>
<AssetBalance value={balance.toString()} asset={asset} />
</div>
),
};
}, []),
[signatories],
);
onChange(selectedSigner.signer);
};

return (
<div className="flex flex-col gap-y-2">
<Select
label={t('proxy.addProxy.signatoryLabel')}
placeholder={t('proxy.addProxy.signatoryPlaceholder')}
selectedId={signatory?.id?.toString()}
options={options}
invalid={hasError}
onChange={({ value }) => onChange(value)}
/>
<Field text={t('proxy.addProxy.signatoryLabel')}>
<Select
placeholder={t('proxy.addProxy.signatoryPlaceholder')}
value={signatory?.id.toString() ?? null}
invalid={hasError}
onChange={(value) => selectSigner(Number(value))}
>
{signatories.map(({ signer, balance }) => {
const isShard = accountUtils.isShardAccount(signer);
const address = toAddress(signer.accountId, { prefix: addressPrefix });

return (
<Select.Item key={signer.id} value={signer.id.toString()}>
<div className="flex w-full items-center justify-between">
<Address
showIcon
hideAddress
variant="short"
iconSize={20}
address={address}
title={isShard ? address : signer.name}
canCopy={false}
/>
<AssetBalance value={balance.toString()} asset={asset} />
</div>
</Select.Item>
);
})}
</Select>
</Field>
<InputHint variant="error" active={hasError}>
{errorText}
</InputHint>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { useEffect, useState } from 'react';
import { type HexString } from '@/shared/core';
import { useI18n } from '@/shared/i18n';
import { ValidationErrors, cnTw } from '@/shared/lib/utils';
import { Button, CaptionText, Countdown, FootnoteText, Select, Shimmering, SmallTitleText } from '@/shared/ui';
import { type DropdownOption, type DropdownResult } from '@/shared/ui/types';
import { Button, CaptionText, Countdown, FootnoteText, Shimmering, SmallTitleText } from '@/shared/ui';
import { Select } from '@/shared/ui-kit';
import { CameraAccessErrors, CameraError, WhiteTextButtonStyle } from '../common/constants';
import { type ErrorObject, type Progress, QrError, type VideoInput } from '../common/types';

Expand Down Expand Up @@ -42,8 +42,8 @@ export const QrReaderWrapper = ({ className, onResult, countdown, validationErro
const [progress, setProgress] = useState<Progress>();
const [isSuccess, setIsSuccess] = useState<boolean>(false);

const [activeCamera, setActiveCamera] = useState<DropdownResult<string>>();
const [availableCameras, setAvailableCameras] = useState<DropdownOption<string>[]>([]);
const [activeCamera, setActiveCamera] = useState<string>();
const [availableCameras, setAvailableCameras] = useState<Record<'title' | 'value', string>[]>([]);

useEffect(() => {
if (validationError) {
Expand All @@ -54,18 +54,15 @@ export const QrReaderWrapper = ({ className, onResult, countdown, validationErro
const isCameraOn = !(error && CameraAccessErrors.includes(error));

const onCameraList = (cameras: VideoInput[]) => {
const formattedCameras = cameras.map((camera, index) => ({
//eslint-disable-next-line i18next/no-literal-string
element: `${index + 1}. ${camera.label}`,
const formattedCameras = cameras.map((camera) => ({
title: camera.label,
value: camera.id,
id: camera.id,
}));

setAvailableCameras(formattedCameras);

if (formattedCameras.length > 1) {
// if multiple cameras are available we set first one as active
setActiveCamera(formattedCameras[0]);
if (formattedCameras.length > 0) {
setActiveCamera(formattedCameras[0].value);
setIsLoading(false);
}
};
Expand Down Expand Up @@ -113,7 +110,7 @@ export const QrReaderWrapper = ({ className, onResult, countdown, validationErro
error === CameraError.INVALID_ERROR && 'blur-[13px]',
className,
),
cameraId: activeCamera?.value,
cameraId: activeCamera,
onStart: () => setIsLoading(false),
onCameraList,
onError,
Expand Down Expand Up @@ -160,16 +157,20 @@ export const QrReaderWrapper = ({ className, onResult, countdown, validationErro
)}
</div>

<div className="mb-4 h-8.5">
{availableCameras && availableCameras.length > 1 && (
<div className="mb-4 w-[208px]">
{availableCameras.length > 1 && (
<Select
theme="dark"
placeholder={t('onboarding.paritySigner.selectCameraLabel')}
selectedId={activeCamera?.id}
options={availableCameras}
className="w-[208px]"
value={activeCamera ?? null}
onChange={setActiveCamera}
/>
>
{availableCameras.map((camera, index) => (
<Select.Item key={camera.value} value={camera.value}>
{`${index + 1}. ${camera.title}`}
</Select.Item>
))}
</Select>
)}
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const VotingConfirmation = ({ fee, account, wallets, chain, asset, vote,
</span>
</Box>

<TransactionDetails wallets={wallets} chain={chain} initiator={[account]}>
<TransactionDetails wallets={wallets} chain={chain} initiator={[account]} signatory={null}>
<DetailRow label={t('fellowship.voting.confirmation.vote')}>{t(`fellowship.voting.${vote}`)}</DetailRow>
<Separator className="border-filter-border" />
<DetailRow label={t('fellowship.voting.confirmation.fee')}>{formatAsset(fee, asset)}</DetailRow>
Expand Down
7 changes: 6 additions & 1 deletion src/renderer/features/fellowship-voting/model/voting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ const signPayloadCreated = createEvent<SigningPayload | null>();

sample({
clock: sign,
source: { transactions: $wrappedTx, account: votingStatusModel.$votingAccount, chain: $chain },
source: {
transactions: $wrappedTx,
account: votingStatusModel.$votingAccount,
chain: $chain,
},
fn: ({ transactions, account, chain }) => {
if (nullable(transactions) || nullable(account) || nullable(chain)) {
return null;
Expand All @@ -76,6 +80,7 @@ sample({
chain,
account,
transaction: transactions.wrappedTx,
signatory: null,
};
},
target: signPayloadCreated,
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/features/governance/types/structs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export type UnlockFormData = {
shards: AccountWithClaim[];
amount: string;
proxiedAccount?: ProxiedAccount & ClaimData;
signatory?: Account;
signatory: Account | null;
chain: Chain;
asset: Asset;
totalLock: BN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ export type SigningPayload = {
chain: Chain;
account: Account;
transaction: Transaction;
signatory?: Account;
signatory: Account | null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { ExtrinsicResult, SubmitStep } from '../lib/types';
type Input = {
chain: Chain;
account: Account;
signatory?: Account;
coreTxs: Transaction[];
wrappedTxs: Transaction[];
multisigTxs: Transaction[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Input = {
id?: number;
chain: Chain;
account: Account;
signatory?: Account;
signatory: Account | null;
proxyType: ProxyType;
delegate: Address;
transaction: Transaction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Input = {
chain: Chain;
account: Account;
proxiedAccount?: ProxiedAccount;
signatory?: Account;
signatory: Account | null;

proxyDeposit: string;
fee: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Input = {

shards: Account[];
proxiedAccount?: ProxiedAccount;
signatory?: Account;
signatory: Account | null;
amount: string;

fee: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Input = {
shards: Account[];
validators: Validator[];
proxiedAccount?: ProxiedAccount;
signatory?: Account;
signatory: Account | null;
amount: string;
destination: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Input = {
balance: string;

proxiedAccount?: ProxiedAccount;
signatory?: Account;
signatory: Account | null;

fee: string;
totalFee: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Input = {
balance: string;

proxiedAccount?: ProxiedAccount;
signatory?: Account;
signatory: Account | null;

fee: string;
totalFee: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Input = {
shards: Account[];
validators: Validator[];
proxiedAccount?: ProxiedAccount;
signatory?: Account;
signatory: Account | null;

fee: string;
totalFee: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Input = {

shards: Account[];
proxiedAccount?: ProxiedAccount;
signatory?: Account;
signatory: Account | null;
destination?: string;

fee: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const Confirmation = ({ id = 0, secondaryActionButton, hideSignButton }:
chain={confirm.meta.chain}
wallets={wallets}
initiator={[confirm.accounts.initiator]}
signatory={confirm.accounts.signer || undefined}
signatory={confirm.accounts.signer}
>
{votingPower && amount && conviction ? (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const Confirmation = ({ id = 0, secondaryActionButton, hideSignButton, on
chain={confirm.meta.chain}
wallets={wallets}
initiator={[confirm.accounts.initiator]}
signatory={confirm.accounts.signer || undefined}
signatory={confirm.accounts.signer}
proxied={confirm.accounts.proxy || undefined}
>
<DetailRow label={t('governance.vote.field.decision')}>{t(`governance.referendum.${decision}`)}</DetailRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { walletModel, walletUtils } from '@/entities/wallet';

type Input = {
id?: number;
signatory?: Account;
signatory: Account | null;
transaction: Transaction;
delegate: Address;
proxyType: ProxyType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { walletModel, walletUtils } from '@/entities/wallet';

type Input = {
id?: number;
signatory?: Account;
signatory: Account | null;
transaction: Transaction;
spawner: AccountId;
proxyType: ProxyType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Input = {
asset: Asset;
shards: Account[];
proxiedAccount?: ProxiedAccount;
signatory?: Account;
signatory: Account | null;
amount: string;

fee: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type Input = {
balance: string;

proxiedAccount?: ProxiedAccount;
signatory?: Account;
signatory: Account | null;

fee: string;
totalFee: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Input = {
asset: Asset;
account: Account;
proxiedAccount?: ProxiedAccount;
signatory?: Account;
signatory: Account | null;
amount: string;
destination: Address;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Input = {
asset: Asset;
shards: Account[];
proxiedAccount?: ProxiedAccount;
signatory?: Account;
signatory: Account | null;
amount: string;

fee: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Input = {
asset: Asset;
shards: Account[];
proxiedAccount?: ProxiedAccount;
signatory?: Account;
signatory: Account | null;
amount: string;

fee: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { walletUtils } from '@/entities/wallet';
export type ConfirmInfo = {
id?: number;
account: Account;
signatory?: Account;
signatory: Account | null;
chain: Chain;
wrappedTransactions: WrappedTransactions;
};
Expand Down
Loading
Loading