Skip to content

Commit

Permalink
Merge branch 'main' into json-code-wrap
Browse files Browse the repository at this point in the history
  • Loading branch information
quietbits authored Dec 18, 2024
2 parents dd339b2 + 8140c41 commit 4d9ba0b
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 22 deletions.
26 changes: 25 additions & 1 deletion src/components/FormElements/AssetPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type AssetPickerProps = {
includeNative?: boolean;
includeLiquidityPoolShares?: boolean;
includeSingleLiquidityPoolShare?: boolean;
disabled?: boolean;
};

export const AssetPicker = ({
Expand All @@ -54,6 +55,7 @@ export const AssetPicker = ({
includeNative = true,
includeLiquidityPoolShares,
includeSingleLiquidityPoolShare,
disabled,
}: AssetPickerProps) => {
let options: AssetObject[] = [];

Expand Down Expand Up @@ -168,6 +170,7 @@ export const AssetPicker = ({
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
onChange({ ...poolShareValue, pool_share: e.target.value });
}}
disabled={disabled}
/>
);
}
Expand All @@ -192,6 +195,7 @@ export const AssetPicker = ({
},
error: assetError?.issuer || "",
}}
disabled={disabled}
/>
);
};
Expand All @@ -217,6 +221,18 @@ export const AssetPicker = ({
}}
options={options}
fitContent={fitContent}
disabledOptions={
disabled
? [
"native",
"credit_alphanum4",
"credit_alphanum12",
"pool_share",
"liquidity_pool_shares",
"issued",
]
: []
}
/>

<ExpandBox
Expand Down Expand Up @@ -254,9 +270,15 @@ type AssetPickerFieldsProps = {
error: string;
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
};
disabled?: boolean;
};

const AssetPickerFields = ({ id, code, issuer }: AssetPickerFieldsProps) => (
const AssetPickerFields = ({
id,
code,
issuer,
disabled,
}: AssetPickerFieldsProps) => (
<div className="RadioPicker__inset">
<Input
id={`${id}-code`}
Expand All @@ -265,6 +287,7 @@ const AssetPickerFields = ({ id, code, issuer }: AssetPickerFieldsProps) => (
value={code.value}
onChange={code.onChange}
error={code.error}
disabled={disabled}
/>
<PubKeyPicker
id={`${id}-issuer`}
Expand All @@ -273,6 +296,7 @@ const AssetPickerFields = ({ id, code, issuer }: AssetPickerFieldsProps) => (
value={issuer.value}
onChange={issuer.onChange}
error={issuer.error}
disabled={disabled}
/>
</div>
);
3 changes: 3 additions & 0 deletions src/components/FormElements/ConfigSettingIdPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ type ConfigSettingIdPickerProps = {
value: string | undefined;
onChange: (value: ConfigSettingIdType | undefined) => void;
error: string | undefined;
disabled?: boolean;
};

export const ConfigSettingIdPicker = ({
id,
value,
onChange,
disabled,
}: ConfigSettingIdPickerProps) => {
const configSettingType: { id: ConfigSettingIdType; label: string }[] = [
{
Expand Down Expand Up @@ -91,6 +93,7 @@ export const ConfigSettingIdPicker = ({
onChange(undefined);
}
}}
disabled={disabled}
>
<option value="">Select Config Setting ID</option>

Expand Down
5 changes: 5 additions & 0 deletions src/components/FormElements/LiquidityPoolShares.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ type LiquidityPoolSharesProps = {
value: AssetPoolShareObjectValue;
error: AssetPoolShareError | undefined;
onChange: (val: AssetPoolShareObjectValue | undefined) => void;
disabled?: boolean;
};

export const LiquidityPoolShares = ({
id,
value,
error,
onChange,
disabled,
}: LiquidityPoolSharesProps) => {
const getAssetValue = (
val:
Expand Down Expand Up @@ -52,6 +54,7 @@ export const LiquidityPoolShares = ({
onChange={(val) => {
onChange({ ...value, asset_a: getAssetValue(val) });
}}
disabled={disabled}
/>

<AssetPicker
Expand All @@ -63,6 +66,7 @@ export const LiquidityPoolShares = ({
onChange={(val) => {
onChange({ ...value, asset_b: getAssetValue(val) });
}}
disabled={disabled}
/>

<PositiveIntPicker
Expand All @@ -76,6 +80,7 @@ export const LiquidityPoolShares = ({
// Do nothing
}}
readOnly
disabled={disabled}
/>
</Box>
);
Expand Down
3 changes: 3 additions & 0 deletions src/components/FormElements/PubKeyPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface PubKeyPickerProps extends Omit<InputProps, "fieldSize"> {
labelSuffix?: string | React.ReactNode;
placeholder?: string;
readOnly?: boolean;
disabled?: boolean;
value: string;
error: string | undefined;
onChange?: (e: React.ChangeEvent<any>) => void;
Expand All @@ -22,6 +23,7 @@ export const PubKeyPicker = ({
value,
error,
readOnly,
disabled,
onChange,
...props
}: PubKeyPickerProps) => (
Expand All @@ -34,6 +36,7 @@ export const PubKeyPicker = ({
value={value}
error={error}
readOnly={readOnly}
disabled={disabled}
onChange={onChange}
{...props}
/>
Expand Down
3 changes: 3 additions & 0 deletions src/components/FormElements/TextPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface TextPickerProps extends Omit<InputProps, "fieldSize"> {
placeholder?: string;
error?: string | undefined;
readOnly?: boolean;
disabled?: boolean;
autocomplete?: React.HTMLInputAutoCompleteAttribute;
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
}
Expand All @@ -23,6 +24,7 @@ export const TextPicker = ({
error,
onChange,
readOnly,
disabled,
autocomplete,
...props
}: TextPickerProps) => (
Expand All @@ -35,6 +37,7 @@ export const TextPicker = ({
error={error}
onChange={onChange}
readOnly={readOnly}
disabled={disabled}
autoComplete={autocomplete}
{...props}
/>
Expand Down
62 changes: 41 additions & 21 deletions src/components/FormElements/XdrLedgerKeyPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export const XdrLedgerKeyPicker = ({
const [selectedLedgerKey, setSelectedLedgerKey] =
useState<LedgerKeyFieldsType | null>(null);

const [isXdrInputActive, setIsXdrInputActive] = useState(true);
const [formError, setFormError] = useState<AnyObject>({});
const [ledgerKeyXdrJsonString, setLedgerKeyJsonString] = useState<string>("");
const [ledgerKeyXdrError, setLedgerKeyXdrError] = useState<string>("");
Expand Down Expand Up @@ -347,6 +348,7 @@ export const XdrLedgerKeyPicker = ({
);
},
isRequired: true,
disabled: isXdrInputActive,
});
}

Expand All @@ -358,6 +360,7 @@ export const XdrLedgerKeyPicker = ({
handleChange(selectedConfigSetting, selectedConfigSetting);
},
isRequired: true,
disabled: isXdrInputActive,
});
}

Expand All @@ -368,14 +371,15 @@ export const XdrLedgerKeyPicker = ({
handleChange(e.target.value, e.target.value);
},
isRequired: true,
disabled: isXdrInputActive,
});
}
return null;
});
};

return (
<Box gap="sm">
<Box gap="lg" addlClassName="XdrLedgerKeyPicker">
<XdrPicker
id="ledger-key-xdr"
label="Ledger Key XDR"
Expand All @@ -385,30 +389,46 @@ export const XdrLedgerKeyPicker = ({
onChange(e.target.value);
validateLedgerKeyXdr(e.target.value);
}}
disabled={!isXdrInputActive}
/>

<Select
id="ledgerkey"
fieldSize="md"
label="Ledger Key"
value={selectedLedgerKey?.id}
onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {
reset();

const selectedVal = e.target.value;
setSelectedLedgerKey(selectedVal ? getKeyType(selectedVal)! : null);
<Button
size="md"
variant="tertiary"
icon={<Icon.SwitchVertical01 />}
type="button"
onClick={() => {
setIsXdrInputActive(!isXdrInputActive);
}}
>
<option value="">Select a key</option>

{ledgerKeyFields.map((f) => (
<option key={f.id} value={f.id}>
{f.label}
</option>
))}
</Select>
<>{renderLedgerKeyTemplate()}</>
<>{rightElement}</>
Switch input
</Button>

<Box gap="sm">
<Select
id="ledgerkey"
fieldSize="md"
label="Ledger Key"
value={selectedLedgerKey?.id}
onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {
reset();

const selectedVal = e.target.value;
setSelectedLedgerKey(selectedVal ? getKeyType(selectedVal)! : null);
}}
disabled={isXdrInputActive}
>
<option value="">Select a key</option>

{ledgerKeyFields.map((f) => (
<option key={f.id} value={f.id}>
{f.label}
</option>
))}
</Select>
<>{renderLedgerKeyTemplate()}</>
<>{rightElement}</>
</Box>
</Box>
);
};
Expand Down
Loading

0 comments on commit 4d9ba0b

Please sign in to comment.