Skip to content

Commit

Permalink
Add image fees in calling context
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis committed Nov 2, 2023
1 parent 11fa9e4 commit 17b39d9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 8 additions & 1 deletion components/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,14 @@ export function Form ({
const onSubmitInner = useCallback(async (values, ...args) => {
try {
if (onSubmit) {
const options = await onSubmit(values, ...args)
// extract cost from formik fields
// (cost may also be set in a formik field named 'amount')
let cost = values?.cost || values?.amount
// add potential image fees which are set in a different field
// to differentiate between fees (in receipts for example)
cost += (values?.imageFeesInfo?.totalFees || 0)

const options = await onSubmit(cost, values, ...args)
if (!storageKeyPrefix || options?.keepLocalStorage) return
clearLocalStorage(values)
}
Expand Down
6 changes: 1 addition & 5 deletions components/invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,7 @@ export const useInvoiceable = (onSubmit, options = defaultOptions) => {

// this function will be called before the Form's onSubmit handler is called
// and the form must include `cost` or `amount` as a value
const onSubmitWrapper = useCallback(async (formValues, ...submitArgs) => {
let { cost, imageFeesInfo, amount } = formValues
cost ??= amount
if (imageFeesInfo?.totalFees) cost += imageFeesInfo.totalFees

const onSubmitWrapper = useCallback(async (cost, formValues, ...submitArgs) => {
// action only allowed if logged in
if (!me && options.requireSession) {
throw new Error('you must be logged in')
Expand Down

0 comments on commit 17b39d9

Please sign in to comment.