Skip to content

Commit

Permalink
Merge pull request #424 from Chia-Network/fix-connect-regex
Browse files Browse the repository at this point in the history
connect modal and tokenization modal fixes
  • Loading branch information
wwills2 authored Jan 14, 2025
2 parents 7a4e498 + 1f7e203 commit 3a6b760
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 29 deletions.
1 change: 0 additions & 1 deletion src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ function App() {
if (event.origin === window.origin) {
const message = event.data;
if (message?.selectedLocale && message.selectedLocale !== appStore.locale) {
console.log('selected locale', message.selectedLocale);
dispatch(setLocale(message.selectedLocale));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/blocks/forms/ConnectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const validationSchema = yup.object({
.required('Server Address is required')
.matches(
// eslint-disable-next-line no-useless-escape
/^(https?:\/\/(www\.)?)?([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}|localhost|[a-z0-9]+)(:[0-9]{1,5})?(\/.*)?$/,
/^(https?:\/\/(www\.)?)?([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}|localhost|[a-z0-9]+|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(:[0-9]{1,5})?(\/.*)?$/,
'Please enter a valid server address',
),
apiKey: yup.string(),
Expand Down
13 changes: 7 additions & 6 deletions src/renderer/components/blocks/forms/CreateTokenForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface FormProps extends React.RefAttributes<CreateTokenFormRef> {
}

export interface CreateTokenFormRef {
submitForm: () => Promise<any>;
submitForm: () => Promise<string | undefined>;
}

const CreateTokenForm: React.FC<FormProps> = forwardRef<CreateTokenFormRef, FormProps>(({ data }, ref) => {
Expand All @@ -28,8 +28,9 @@ const CreateTokenForm: React.FC<FormProps> = forwardRef<CreateTokenFormRef, Form
if (formik) {
const errors = await formik.validateForm(formik.values);
formik.setTouched(Object.keys(errors).reduce((acc, key) => ({ ...acc, [key]: true }), {}));

return [errors, formik.values];
if (formik.values?.walletAddress) {
return formik.values.walletAddress;
}
}
}
},
Expand All @@ -48,9 +49,9 @@ const CreateTokenForm: React.FC<FormProps> = forwardRef<CreateTokenFormRef, Form
name="walletAddress"
type="picklist"
options={
data?.map((d) => ({
label: d.name || '',
value: d.walletAddress || '',
data?.map((addressData) => ({
label: addressData.name || '',
value: addressData.walletAddress || '',
})) || []
}
freeform={true}
Expand Down
35 changes: 15 additions & 20 deletions src/renderer/components/blocks/modals/CreateTokenModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useGetAddressBookQuery, useGetProjectQuery, useGetUnitQuery, useTokeniz
import { Alert } from 'flowbite-react';
import { HiInformationCircle } from 'react-icons/hi';
import { useWildCardUrlHash } from '@/hooks';
import { isEmpty } from 'lodash';

interface UpsertModalProps {
onTokenizationSuccess: () => void;
Expand All @@ -17,6 +16,7 @@ const CreateTokenModal: React.FC<UpsertModalProps> = ({ onClose, onTokenizationS
const urlHashValues: string[] = tokenizeUrlFragment?.replace('tokenize-', '')?.split('^');
const warehouseUnitId = urlHashValues?.length >= 1 ? urlHashValues[0] : '';
const warehouseProjectId = urlHashValues?.length >= 2 ? urlHashValues[1] : '';
const [tokenizationProcessing, setTokenizationProcessing] = useState<boolean>(false);

const [showTokenizationFailure, setShowTokenizationFailure] = useState<boolean>(false);
const { data: unit, isLoading: unitLoading } = useGetUnitQuery(
Expand All @@ -42,8 +42,15 @@ const CreateTokenModal: React.FC<UpsertModalProps> = ({ onClose, onTokenizationS
unit?.unitBlockEnd &&
unit?.unitCount;

const onSubmitTokenization = async (walletAddress: string) => {
const onSubmitTokenization = async () => {
setShowTokenizationFailure(false);
setTokenizationProcessing(true);

const walletAddress = await createTokenFormRef.current?.submitForm();
if (!walletAddress) {
setTokenizationProcessing(false);
return;
}

if (unit && project && requiredFieldsPresent) {
const submitData = {
Expand All @@ -66,24 +73,8 @@ const CreateTokenModal: React.FC<UpsertModalProps> = ({ onClose, onTokenizationS
} else {
setShowTokenizationFailure(true);
}
};

const handleSubmit = () => {
createTokenFormRef.current
?.submitForm()
.then(async ([errors, values]) => {
if (!isEmpty(errors)) {
console.error('Form submission error:', errors);
return;
}

if (values) {
onSubmitTokenization(values.walletAddress);
}
})
.catch((error) => {
console.error('Form submission error:', error);
});
setTokenizationProcessing(false);
};

const modalBody = () => {
Expand Down Expand Up @@ -194,7 +185,11 @@ const CreateTokenModal: React.FC<UpsertModalProps> = ({ onClose, onTokenizationS
<CreateTokenForm ref={createTokenFormRef} data={addressBookData?.data} />
</div>
<div className="flex">
<Button onClick={handleSubmit}>Create Token</Button>
<Button onClick={onSubmitTokenization} isProcessing={tokenizationProcessing}>
<p className="capitalize">
<FormattedMessage id="create-token" />
</p>
</Button>
</div>
</div>
);
Expand Down
1 change: 0 additions & 1 deletion src/renderer/translations/tokens/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
"not-available-in-core-registry-mode": "not available in core registry mode",
"cannot-connect-to-registry-api-with-current-settings": "Cannot connect to registry API with current settings",
"please-disconnect-to-edit-the-api-url-and-api-key": "Please disconnect to edit the API URL and API key",

"address-book": "address book",
"add-address": "add address",
"project-developer": "Project Developer",
Expand Down

0 comments on commit 3a6b760

Please sign in to comment.