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(wallet): multi chain frontend extras #413

Draft
wants to merge 1 commit into
base: multi-chain-support
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions apps/wallet/src/components/accounts/TransferForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
:readonly="isViewMode"
type="text"
:prepend-icon="mdiSend"
:rules="[requiredRule]"
:rules="[requiredRule, addressValidator]"
data-test-id="transfer-form-destination-address"
/>
<VTextField
Expand Down Expand Up @@ -48,7 +48,7 @@ import { computed, ref, toRefs, watch } from 'vue';
import { VForm, VTextField } from 'vuetify/components';
import { Account, Asset, Transfer } from '~/generated/station/station.did';
import { VFormValidation } from '~/types/helper.types';
import { requiredRule, validTokenAmount } from '~/utils/form.utils';
import { requiredRule, validAddress, validTokenAmount } from '~/utils/form.utils';
import { amountToBigInt, formatBalance } from '~/utils/helper.utils';

export type TransferFormProps = {
Expand Down Expand Up @@ -87,6 +87,8 @@ const emit = defineEmits<{
const model = computed(() => props.modelValue.value);
watch(model.value, newValue => emit('update:modelValue', newValue), { deep: true });

const addressValidator = computed(() => validAddress(input.asset.blockchain));

const amountInput = ref<HTMLInputElement | null>(null);
const amount = ref<string | undefined>(undefined);
watch(
Expand Down
1 change: 1 addition & 0 deletions apps/wallet/src/locales/en.locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ export default {
numberRange: 'This field must be between {min} and {max}.',
invalidDecimalPlaces: 'This field must have a maximum of {decimals} decimal places.',
isHex: 'This field must be a valid hexadecimal value.',
validAddress: 'This field must be a valid address.',
},
},
navigation: {
Expand Down
1 change: 1 addition & 0 deletions apps/wallet/src/locales/fr.locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ export default {
numberRange: 'Le champ doit contenir une valeur valide entre {min} et {max}.',
invalidDecimalPlaces: 'Ce champ doit contenir un maximum de {decimals} décimales.',
isHex: 'Ce champ doit contenir une valeur hexadécimale valide.',
validAddress: 'Ce champ doit contenir une adresse valide.',
},
},
navigation: {
Expand Down
1 change: 1 addition & 0 deletions apps/wallet/src/locales/pt.locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ export default {
numberRange: 'Este campo deve estar entre {min} e {max}.',
invalidDecimalPlaces: 'Este campo deve ter no máximo {decimals} casas decimais.',
isHex: 'Este campo deve conter um valor hexadecimal válido.',
validAddress: 'Este campo deve conter um endereço válido.',
},
},
navigation: {
Expand Down
23 changes: 23 additions & 0 deletions apps/wallet/src/utils/form.utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Principal } from '@dfinity/principal';
import isUUID from 'validator/es/lib/isUUID';
import { i18n } from '~/plugins/i18n.plugin';
import { detectAddressFormat } from './asset.utils';

export const requiredRule = (value: unknown): string | boolean => {
if (value === null || value === undefined || value === '') {
Expand Down Expand Up @@ -241,3 +242,25 @@ export const validEmail = (value: unknown): string | boolean => {

return true;
};

export const validAddress =
(blockchain: string) =>
(value: unknown): string | boolean => {
const hasValue = !!value;
if (!hasValue) {
// this rule only applies if there is a value
return true;
}

if (typeof value !== 'string') {
return i18n.global.t('forms.rules.validAddress');
}

try {
if (detectAddressFormat(blockchain, value) !== undefined) {
return true;
}
} catch {}

return i18n.global.t('forms.rules.validAddress');
};
Loading