Skip to content

Commit

Permalink
feat: don't show preselcted asset on payment form (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
troggy authored Oct 14, 2024
1 parent 98a9ad8 commit e85e2c5
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion i18n/locales/en/payment.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"not-enough-funds": "Not enough funds.",
"invalid-destination": "Expected a public key or stellar address.",
"invalid-price": "Invalid amount.",
"integer-memo-required": "Memo must be an integer."
"integer-memo-required": "Memo must be an integer.",
"asset-missing": "No asset selected."
}
}
3 changes: 2 additions & 1 deletion i18n/locales/es/payment.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"not-enough-funds": "Fondos insuficientes.",
"invalid-destination": "Se esperaba una llave pública o una dirección Stellar.",
"invalid-price": "Monto no válido.",
"integer-memo-required": "El Memo debe ser un número entero"
"integer-memo-required": "El Memo debe ser un número entero",
"asset-missing": "Ningún activo seleccionado."
}
}
3 changes: 2 additions & 1 deletion i18n/locales/it/payment.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"not-enough-funds": "Fondi insufficienti.",
"invalid-destination": "Attesa una chiave pubblica o un indirizzo stellare.",
"invalid-price": "Importo non valido.",
"integer-memo-required": "Il memo deve essere un numero intero."
"integer-memo-required": "Il memo deve essere un numero intero.",
"asset-missing": "Nessuna risorsa selezionata."
}
}
3 changes: 2 additions & 1 deletion i18n/locales/ru/payment.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"not-enough-funds": "Недостаточно средств.",
"invalid-destination": "Ожидается публичный ключ или stellar адрес.",
"invalid-price": "Неверная сумма.",
"integer-memo-required": "Заметка должна быть числом."
"integer-memo-required": "Заметка должна быть числом.",
"asset-missing": "Не выбран актив."
}
}
3 changes: 2 additions & 1 deletion src/Generic/lib/stellar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ export function getAssetsFromBalances(balances: BalanceLine[]) {
)
}

export function findMatchingBalanceLine(balances: AccountData["balances"], asset: Asset): BalanceLine | undefined {
export function findMatchingBalanceLine(balances: AccountData["balances"], asset?: Asset): BalanceLine | undefined {
if (!asset) return undefined
return balances.find((balance): balance is BalanceLine => balancelineToAsset(balance).equals(asset))
}

Expand Down
5 changes: 4 additions & 1 deletion src/Payment/components/PaymentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const PaymentForm = React.memo(function PaymentForm(props: PaymentFormProps) {
const form = useForm<PaymentFormValues>({
defaultValues: {
amount: "",
asset: Asset.native(),
asset: undefined,
destination: "",
memoValue: ""
}
Expand Down Expand Up @@ -216,6 +216,9 @@ const PaymentForm = React.memo(function PaymentForm(props: PaymentFormProps) {
inputRef={form.register({
required: t<string>("payment.validation.no-price"),
validate: value => {
if (!form.getValues()["asset"]) {
return t<string>("payment.validation.asset-missing")
}
if (!isValidAmount(value) || FormBigNumber(value).eq(0)) {
return t<string>("payment.validation.invalid-price")
} else if (FormBigNumber(value).gt(spendableBalance)) {
Expand Down

0 comments on commit e85e2c5

Please sign in to comment.