-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
525 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React from "react"; | ||
import { MemoType, MemoValue } from "@stellar/stellar-sdk"; | ||
import { Input } from "@stellar/design-system"; | ||
|
||
import { RadioPicker } from "@/components/RadioPicker"; | ||
import { ExpandBox } from "@/components/ExpandBox"; | ||
|
||
type MemoPickerValue = { type: MemoType; value: MemoValue | undefined }; | ||
|
||
type MemoPickerProps = { | ||
id: string; | ||
value: MemoPickerValue | undefined; | ||
onChange: ( | ||
optionId: string | undefined, | ||
optionValue?: MemoPickerValue, | ||
) => void; | ||
labelSuffix?: string | React.ReactNode; | ||
error: string | undefined; | ||
}; | ||
|
||
export const MemoPicker = ({ | ||
id, | ||
value, | ||
onChange, | ||
labelSuffix, | ||
error, | ||
}: MemoPickerProps) => { | ||
const memoValuePlaceholder = (type?: MemoType) => { | ||
if (!type) { | ||
return ""; | ||
} | ||
|
||
switch (type) { | ||
case "id": | ||
return "Unsigned 64-bit integer"; | ||
case "hash": | ||
case "return": | ||
return "32-byte hash in hexadecimal format (64 [0-9a-f] characters)"; | ||
case "text": | ||
return "UTF-8 string of up to 28 bytes"; | ||
case "none": | ||
default: | ||
return ""; | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="RadioPicker__inset"> | ||
<RadioPicker | ||
id={id} | ||
selectedOption={value?.type} | ||
label="Memo" | ||
labelSuffix={labelSuffix} | ||
onChange={onChange} | ||
options={[ | ||
{ id: "none", label: "None", value: { type: "none", value: "" } }, | ||
{ id: "text", label: "Text", value: { type: "text", value: "" } }, | ||
{ id: "id", label: "ID", value: { type: "id", value: "" } }, | ||
{ id: "hash", label: "Hash", value: { type: "hash", value: "" } }, | ||
{ | ||
id: "return", | ||
label: "Return", | ||
value: { type: "return", value: "" }, | ||
}, | ||
]} | ||
/> | ||
|
||
<ExpandBox | ||
isExpanded={Boolean(value?.type && value.type !== "none")} | ||
offsetTop="sm" | ||
> | ||
<Input | ||
fieldSize="md" | ||
id="memo_value" | ||
placeholder={memoValuePlaceholder(value?.type)} | ||
value={value?.value?.toString() || ""} | ||
onChange={(e) => { | ||
if (value?.type) { | ||
onChange(value.type, { type: value.type, value: e.target.value }); | ||
} | ||
}} | ||
error={error} | ||
/> | ||
</ExpandBox> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { Box } from "@/components/layout/Box"; | ||
import { SdsLink } from "@/components/SdsLink"; | ||
import { InputSideElement } from "@/components/InputSideElement"; | ||
import { PositiveIntPicker } from "./PositiveIntPicker"; | ||
|
||
type TimeBoundValue = { min: string; max: string }; | ||
|
||
type TimeBoundsPickerProps = { | ||
value: TimeBoundValue | undefined; | ||
labelSuffix?: string | React.ReactNode; | ||
onChange: (value: TimeBoundValue) => void; | ||
error: { min: string | false; max: string | false } | undefined; | ||
}; | ||
|
||
export const TimeBoundsPicker = ({ | ||
value = { min: "", max: "" }, | ||
labelSuffix, | ||
onChange, | ||
error, | ||
}: TimeBoundsPickerProps) => { | ||
return ( | ||
<Box gap="sm"> | ||
<> | ||
<Box gap="xs"> | ||
<> | ||
<PositiveIntPicker | ||
id="timebounds-min" | ||
label="Time Bounds" | ||
labelSuffix={labelSuffix} | ||
placeholder="Lower time bound unix timestamp. Ex: 1479151713" | ||
value={value.min} | ||
error={error?.min ? `Lower time bound: ${error.min}` : ""} | ||
onChange={(e) => { | ||
onChange({ ...value, min: e.target.value }); | ||
}} | ||
/> | ||
<PositiveIntPicker | ||
id="timebounds-max" | ||
label="" | ||
placeholder="Upper time bound unix timestamp. Ex: 1479151713" | ||
value={value.max} | ||
error={error?.max ? `Upper time bound: ${error.max}` : ""} | ||
onChange={(e) => { | ||
onChange({ ...value, max: e.target.value }); | ||
}} | ||
rightElement={ | ||
<InputSideElement | ||
variant="button" | ||
placement="right" | ||
onClick={() => { | ||
onChange({ | ||
...value, | ||
max: ( | ||
Math.ceil(new Date().getTime() / 1000) + | ||
5 * 60 | ||
).toString(), | ||
}); | ||
}} | ||
> | ||
Set to 5 min from now | ||
</InputSideElement> | ||
} | ||
/> | ||
</> | ||
</Box> | ||
<Box gap="xs" addlClassName="FieldNote FieldNote--note FieldNote--md"> | ||
<> | ||
<div> | ||
Enter{" "} | ||
<SdsLink href="http://www.epochconverter.com/"> | ||
unix timestamp | ||
</SdsLink>{" "} | ||
values of time bounds when this transaction will be valid. | ||
</div> | ||
|
||
<div> | ||
For regular transactions, it is highly recommended to set the | ||
upper time bound to get a{" "} | ||
<SdsLink href="https://github.com/stellar/stellar-core/issues/1811"> | ||
final result | ||
</SdsLink>{" "} | ||
of a transaction in a defined time. | ||
</div> | ||
</> | ||
</Box> | ||
</> | ||
</Box> | ||
); | ||
}; |
Oops, something went wrong.