-
Notifications
You must be signed in to change notification settings - Fork 19
feat: transaction text prop #471
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,9 +48,10 @@ export interface WidgetContainerProps | |
| disableAltpayment?: boolean | ||
| contributionOffset?: number | ||
| disableSound?: boolean | ||
| transactionText?: string | ||
| } | ||
|
|
||
| const snackbarOptions: OptionsObject = { | ||
| const snackbarOptionsSuccess: OptionsObject = { | ||
| variant: 'success', | ||
| autoHideDuration: 8000, | ||
| anchorOrigin: { | ||
|
|
@@ -59,6 +60,14 @@ const snackbarOptions: OptionsObject = { | |
| }, | ||
| }; | ||
|
|
||
| const snackbarOptionsInfo: OptionsObject = { | ||
| autoHideDuration: 8000, | ||
| anchorOrigin: { | ||
| vertical: 'bottom', | ||
| horizontal: 'center', | ||
| }, | ||
| }; | ||
|
|
||
| export interface Output { | ||
| index: number; | ||
| value: number; | ||
|
|
@@ -109,6 +118,7 @@ export const WidgetContainer: React.FunctionComponent<WidgetContainerProps> = | |
| disableAltpayment, | ||
| contributionOffset, | ||
| disableSound, | ||
| transactionText, | ||
| ...widgetProps | ||
| } = props; | ||
|
|
||
|
|
@@ -158,6 +168,7 @@ export const WidgetContainer: React.FunctionComponent<WidgetContainerProps> = | |
| } else { | ||
| const expectedAmount = amount ? resolveNumber(amount) : undefined; | ||
| const receivedAmount = resolveNumber(transaction.amount); | ||
| const currencyTicker = getCurrencyTypeFromAddress(to); | ||
|
|
||
| if (await shouldTriggerOnSuccess( | ||
| transaction, | ||
|
|
@@ -177,13 +188,12 @@ export const WidgetContainer: React.FunctionComponent<WidgetContainerProps> = | |
| txSound.play().catch(() => {}); | ||
| } | ||
|
|
||
| const currencyTicker = getCurrencyTypeFromAddress(to); | ||
| if (!hideToasts) | ||
| enqueueSnackbar( | ||
| `${ | ||
| successText ? successText + ' | ' : '' | ||
| }Received ${receivedAmount} ${currencyTicker}`, | ||
| snackbarOptions, | ||
| snackbarOptionsSuccess, | ||
| ); | ||
| setSuccess(true); | ||
| onSuccess?.(transaction); | ||
|
|
@@ -192,6 +202,15 @@ export const WidgetContainer: React.FunctionComponent<WidgetContainerProps> = | |
| }, 3000); | ||
| } else { | ||
| onTransaction?.(transaction); | ||
| if (transactionText){ | ||
| enqueueSnackbar( | ||
| `${ | ||
| transactionText ? transactionText : 'New transaction' | ||
| } | Received ${receivedAmount} ${currencyTicker}`, | ||
| snackbarOptionsInfo, | ||
| ); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't really expecting this... I think it's better to stick with the standard toast and perhaps we can make a new task to better differentiate them so people don't mistakenly think they paid the full correct amount when they did not.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second thought - @chedieck thoughts on this? Maybe John also has some ideas how best to visually communicate the custom message while also making it clear that less than the full amount was paid.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe call it "Unexpected payment" or something like that by default? Probably some other more precise adjective would be better. As for the PR, this |
||
|
|
||
| } | ||
| } | ||
| setNewTxs([]); | ||
|
|
@@ -286,6 +305,7 @@ export const WidgetContainer: React.FunctionComponent<WidgetContainerProps> = | |
| setShiftCompleted={setShiftCompleted} | ||
| disableAltpayment={disableAltpayment} | ||
| contributionOffset={contributionOffset} | ||
| transactionText={transactionText} | ||
| /> | ||
| </React.Fragment> | ||
| ); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should be set by default.
Let's keep the old behaviour (of no toast) if it's not set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is already set to only trigger the toast if there is a transaction text set