-
Notifications
You must be signed in to change notification settings - Fork 513
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
[core-v2.3.0-alpha.1] : Feature - Transaction notifications #1070
Merged
Adamj1232
merged 124 commits into
v2-web3-onboard-develop
from
feature/transaction-notifications
Jun 20, 2022
Merged
Changes from 107 commits
Commits
Show all changes
124 commits
Select commit
Hold shift + click to select a range
8941fcc
Initial Notify setup steps
Adamj1232 88be97f
Styling notification
Adamj1232 e3743fc
Styling getting closer
Adamj1232 777ffd7
Layout looking a lot better
Adamj1232 a8b77d9
Aniomations working properly for pending
Adamj1232 27f03ed
Updated cleanliness
Adamj1232 f51ba00
More updates and abstractions
Adamj1232 e75cabb
Demo stuff
Adamj1232 5c28c31
Merge in dev and update Notify, getting closer
Adamj1232 ac05485
Props passed in properly
Adamj1232 e7da8b6
Rename and refactors
Adamj1232 b0d901a
Notify into AC
Adamj1232 28ef295
Merge in dev
Adamj1232 03ff348
Cleanup and merge in develop
Adamj1232 f2e7133
More cleanup and positioning
Adamj1232 4b14fb6
Add css variables
Adamj1232 5c4274c
Fix and style timer
Adamj1232 3670eb6
More cleanup
Adamj1232 61680b5
Updated structure and componentized further
Adamj1232 0d02808
cleanup
Adamj1232 e698895
Add flags to denote v1 ref code
Adamj1232 20f80a4
Playing around with organisation
lnbc1QWFyb24 7f8c0de
In progress
lnbc1QWFyb24 d9005eb
Merge branch 'v2-web3-onboard-develop' into feature/transaction-notif…
lnbc1QWFyb24 b49b1a5
Progress
lnbc1QWFyb24 fc39788
Progress
lnbc1QWFyb24 ca70f46
Working notifications
lnbc1QWFyb24 3f84085
Latest SDK branch
lnbc1QWFyb24 2b6dc47
Add timeout to unsub calls
lnbc1QWFyb24 0a99d42
Merge branch 'v2-web3-onboard-develop' into feature/transaction-notif…
lnbc1QWFyb24 c8dca6c
Add timeout to disconnect
lnbc1QWFyb24 4889dff
Use NotifyEventStyles type
lnbc1QWFyb24 89c5118
Update comments
lnbc1QWFyb24 a4c78dd
Tidy up import statements
lnbc1QWFyb24 910c6e2
Update docs
Adamj1232 b9db596
Update versions
lnbc1QWFyb24 ecaed63
Componentise notification
lnbc1QWFyb24 95f53ab
Add margin to modal
lnbc1QWFyb24 462dc21
Remove network from customize notification
lnbc1QWFyb24 783548c
Add hitnt and error types back
lnbc1QWFyb24 1cbc680
Throw if invalid custom notification
lnbc1QWFyb24 b129040
Upgrade sdk and handle unsupported network error
lnbc1QWFyb24 4a21452
Auto dismiss notification
lnbc1QWFyb24 c0c1133
More README updates
Adamj1232 88dfe4b
Merge in Aarons changes
Adamj1232 af633d3
Update spacing and layout to display properly
Adamj1232 65d672d
cleanup and more positioning
Adamj1232 eecba0d
Animations working
Adamj1232 de3e49d
Fix animation speed, linking in transaction hash
Adamj1232 9fb4fca
Fix padding on AC
lnbc1QWFyb24 5e1fccb
Add text color to non-linking transaction hash
Adamj1232 176a8b2
Merge in develop and fix animations when positioned left
Adamj1232 1c2c579
More variablization and updating docs
Adamj1232 d4862c0
Add demo with updates for testing in the future
Adamj1232 6a9141a
Return the 4 second default dismiss to notifications, Fix margin caus…
Adamj1232 5bcc28c
Remove margin
lnbc1QWFyb24 3df6dc6
Update on hover to display close button, chain icon size, add close i…
Adamj1232 df3224e
Add new hint notification
Adamj1232 f9ebf37
Merge branch 'feature/transaction-notifications' of blocknative.githu…
Adamj1232 33ac571
Update README for more info around notifications
Adamj1232 df97d99
Revert dismiss timeout used for testing
Adamj1232 6512586
styling touchups
Adamj1232 226f10f
Add DAPP notifications
Adamj1232 0e3df6b
reset sizing for network select
Adamj1232 f9a2bda
Working but needs cleanup
Adamj1232 3f59629
Update action to return update and dismiss methods
Adamj1232 3f9fb36
Update docs and remove unneeded type
Adamj1232 df0bc81
Cleanup of unneeded imports
Adamj1232 e924fde
Updated styling of notifications for second round of style updates, r…
Adamj1232 0a5ca56
More styling of new info icon layout
Adamj1232 88c8a19
Update padding for info icon
Adamj1232 f54ced6
Handle replacement transactions
lnbc1QWFyb24 708d2a2
Working on scrolling
Adamj1232 1018377
Merge branch 'feature/transaction-notifications' into feature/dapp_no…
Adamj1232 5d7eddc
Update notifications working
Adamj1232 9e92f0b
Revert scoll on container breaking animations
Adamj1232 f3e2461
Updates SDK to version with multichain
lnbc1QWFyb24 2a8fd27
Always display close button on mobile notifications
Adamj1232 a171a9b
Fix scrolling
Adamj1232 8c8d9bc
Fix styling on notification container
Adamj1232 93a52c7
Handle newest notifications entering closest to AC despite location
Adamj1232 4e71f85
Updated styling of container to allow more space on mobile
Adamj1232 7170789
Merge in develop
Adamj1232 b321f1e
Merge branch 'feature/transaction-notifications' into feature/dapp_no…
Adamj1232 a1faaf0
Update layout for single line notifications
Adamj1232 032d418
Updates to styling of hash/time container
Adamj1232 b1b8997
Update styling for new layout
Adamj1232 4b83672
Working but animation updates coming
Adamj1232 cce27be
Update layout for all animations to match mobile animations
Adamj1232 f6aeaa6
Removes unused dep
lnbc1QWFyb24 99f01dd
Update yarn and remove uuid from dep in core
Adamj1232 d94a2f1
Merge branch 'feature/transaction-notifications' of blocknative.githu…
Adamj1232 5edc273
Remove 1rem buffer for animations
Adamj1232 fb3107f
Revert to 4 second dismiss
Adamj1232 57deb7e
Update types in action
Adamj1232 7851613
Add nanoId, update types for notification update method
Adamj1232 d080f5c
Update animations of removal
Adamj1232 6ccb8ad
Fix comment to reflect functionality
Adamj1232 14394e5
Fix pending on safari
Adamj1232 281817a
Update packages/core/rollup.config.js
Adamj1232 abee655
Update packages/demo/src/App.svelte
Adamj1232 8d232d9
remove unused import
Adamj1232 24bff92
Merge in develop
Adamj1232 3aa25e7
merge in dev
Adamj1232 7bc0a66
Update types and remove unneeded import
Adamj1232 b27195b
Fix animation cutoff on end of list when removing an element
Adamj1232 ade426a
Update readme
Adamj1232 5b9ce35
Update packages/core/README.md
Adamj1232 b258629
Update packages/core/README.md
Adamj1232 0da053d
Update packages/core/README.md
Adamj1232 6f6a0a4
Update packages/core/README.md
Adamj1232 047afd5
Update packages/core/README.md
Adamj1232 04613e8
Update packages/demo/src/App.svelte
Adamj1232 4e78bf4
Update packages/core/README.md
Adamj1232 2a70a80
Update packages/core/README.md
Adamj1232 00e11b8
Update packages/core/README.md
Adamj1232 8f0341a
Update packages/core/README.md
Adamj1232 20d13d0
Merge in latest dev and update versions
Adamj1232 f3f63d2
Merge branch 'feature/transaction-notifications' of blocknative.githu…
Adamj1232 5e4a038
Fix styling and scroll direction when notifications are placed on bot…
Adamj1232 b7d9bcc
Merge branch 'v2-web3-onboard-develop' into feature/transaction-notif…
Adamj1232 3553ea3
Add latest packages to Core README
Adamj1232 95fcb2c
Handle scroll container withaccount center expanded
Adamj1232 fbdc4f7
Update touch-events for scroll on mobile
Adamj1232 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ type InitOptions { | |
appMetadata?: AppMetadata | ||
i18n?: i18nOptions | ||
accountCenter?: AccountCenterOptions | ||
apiKey?: string | ||
notify?: Partial<NotifyOptions> | ||
} | ||
``` | ||
|
||
|
@@ -116,6 +118,99 @@ type AccountCenterPosition = | |
| 'topLeft' | ||
``` | ||
|
||
**`notify`** | ||
Notify provides by default transaction notifications for all connected wallets on the current blockchain. When switching chains the previous chain listeners remain active for 60 seconds to allow capture and report of an remaining transactions that may be in flight. | ||
By default transaction notifications are captured if a DAppID is provided in the Onboard config along with the Account Center being enabled. | ||
An object that defines whether transaction notifications will display (defaults to true if an API key is provided). This object contains an `enabled` flag prop and an optional `transactionHandler` which is a callback that can disable or allow customizations of notifications. | ||
Currently notifications positions in the same location as the account center(either below - if the Account Center is positioned along the top, or above if positioned on the bottom of the view). | ||
Adamj1232 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
The transactionHandler can react off any property of the Ethereum TransactionData returned to the callback from the event(see console.log in example init) and in turn can return a Custom Notification object to define the verbiage, styling or add functionality: | ||
Adamj1232 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- `Notification.message` - to completely customize the message shown | ||
- `Notification.eventCode` - Handle codes in your own way - see codes here under the notify prop [default en file here](src/i18n/en.json) | ||
Adamj1232 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- `Notification.type` - icon type displayed (see NotificationType below for options) | ||
Adamj1232 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- `Notification.autoDismiss` - time on screen | ||
Adamj1232 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- `Notification.link` - add link to hash | ||
Adamj1232 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- `Notification.onClick()` - notification body click event | ||
Adamj1232 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Notify can also be completely styled by using the CSS variables found below. These are setup to allow for maximum customization with base styling variables setting to global the global more themed styling (i.e. `--onboard-grey-600`) as well as a more precise component level styling available (`--notify-onboard-grey-600`) with the latter taking precedent if defined | ||
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.
@Adamj1232 this sentence is a little confusing I think 🤔 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. That sentence makes 0 sense, lol thanks for pointing that out!
Adamj1232 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
If notifications are enabled the notifications can be handled through onboard app state as seen below. | ||
```javascript | ||
const wallets = onboard.state.select('notifications') | ||
const { unsubscribe } = wallets.subscribe(update => | ||
console.log('transaction notifications: ', update) | ||
) | ||
|
||
// unsubscribe when updates are no longer needed | ||
unsubscribe() | ||
``` | ||
|
||
```typescript | ||
export type NotifyOptions = { | ||
enabled: boolean // default: true | ||
/** | ||
* Callback that receives all transaction events | ||
* Return a custom notification based on the event | ||
* Or return false to disable notification for this event | ||
* Or return undefined for a default notification | ||
*/ | ||
transactionHandler?: ( | ||
event: EthereumTransactionData | ||
) => TransactionHandlerReturn | ||
} | ||
|
||
export type TransactionHandlerReturn = CustomNotification | boolean | void | ||
|
||
export type CustomNotification = Partial<Omit<Notification, 'id' | 'startTime'>> | ||
|
||
export type Notification = { | ||
id: string | ||
key: string | ||
type: NotificationType | ||
network: Network | ||
startTime?: number | ||
eventCode: string | ||
message: string | ||
autoDismiss: number | ||
link?: string | ||
onclick?: (event: Event) => void | ||
} | ||
|
||
export type NotificationType = 'pending' | 'success' | 'error' | 'hint' | ||
|
||
export declare type Network = 'main' | 'testnet' | 'ropsten' | 'rinkeby' | 'goerli' | 'kovan' | 'xdai' | 'bsc-main' | 'matic-main' | 'fantom-main' | 'matic-mumbai' | 'local'; | ||
|
||
export interface UpdateNotification { | ||
(notificationObject: CustomNotification): { | ||
dismiss: () => void | ||
update: UpdateNotification | ||
} | ||
} | ||
``` | ||
|
||
Notify can be used to deliver custom DApp notifications by passing a `CustomNotification` object to the `customNotification` action and will be returned a `UpdateNotification` type. | ||
Adamj1232 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This `UpdateNotification` will return an `update` function that can be passed a new `CustomNotification` to update the existing notification. | ||
The `customNotification` method also returns a `dismiss` method that is called without any parameters to dismiss the notification. | ||
|
||
```typescript | ||
const { update, dismiss } = | ||
onboard.state.actions.customNotification({ | ||
type: 'pending', | ||
message: | ||
'This is a custom DApp pending notification to use however you want', | ||
autoDismiss: 0 | ||
Adamj1232 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
setTimeout( | ||
() => | ||
update({ | ||
eventCode: 'dbUpdateSuccess', | ||
message: 'Updated status for custom notification', | ||
type: 'success', | ||
autoDismiss: 8000 | ||
}), | ||
4000 | ||
) | ||
``` | ||
|
||
### Initialization Example | ||
|
||
Putting it all together, here is an example initialization with the injected wallet modules: | ||
|
@@ -176,6 +271,19 @@ const onboard = Onboard({ | |
{ name: 'Coinbase', url: 'https://wallet.coinbase.com/' } | ||
] | ||
}, | ||
apiKey: 'xxx387fb-bxx1-4xxc-a0x3-9d37e426xxxx' | ||
notify: { | ||
enabled: true, | ||
transactionHandler: transaction => { | ||
console.log({ transaction }) | ||
if (transaction.eventCode === 'txPool') { | ||
return { | ||
type: 'success', | ||
message: 'Your transaction from #1 DApp is in the mempool', | ||
} | ||
} | ||
} | ||
}, | ||
accountCenter: { | ||
desktop: { | ||
position: 'topRight', | ||
|
@@ -194,6 +302,20 @@ const onboard = Onboard({ | |
selectingWallet: { | ||
header: 'custom text header' | ||
} | ||
}, | ||
notify: { | ||
transaction: { | ||
txStuck: 'custom text for this notification event' | ||
}, | ||
watched: { | ||
// Any words in brackets can be re-ordered or removed to fit your dapps desired verbiage | ||
"txPool": "Your account is {verb} {formattedValue} {asset} {preposition} {counterpartyShortened}" | ||
} | ||
} | ||
}, | ||
es: { | ||
transaction: { | ||
txRequest: 'Su transacción está esperando que confirme' | ||
} | ||
} | ||
} | ||
|
@@ -285,6 +407,9 @@ type AppState = { | |
chains: Chain[] | ||
accountCenter: AccountCenter | ||
walletModules: WalletModule[] | ||
locale: Locale | ||
notify: NotifyOptions | ||
notifications: Notification[] | ||
} | ||
|
||
type Chain { | ||
|
@@ -605,6 +730,19 @@ The Onboard styles can customized via [CSS variables](https://developer.mozilla. | |
/* SPACING */ | ||
--account-select-modal-margin-4: 1rem; | ||
--account-select-modal-margin-5: 0.5rem; | ||
|
||
/* notify STYLES */ | ||
--notify-onboard-font-family-normal | ||
--notify-onboard-font-size-5 | ||
--notify-onboard-gray-300 | ||
--notify-onboard-gray-600 | ||
--notify-onboard-border-radius | ||
--notify-onboard-font-size-7 | ||
--notify-onboard-font-size-6 | ||
--notify-onboard-line-height-4 | ||
--notify-onboard-primary-100 | ||
--notify-onboard-primary-400 | ||
--notify-onboard-main-padding | ||
} | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { Configuration } from './types' | ||
import { getDevice } from './utils' | ||
|
||
export let configuration: Configuration = { | ||
svelteInstance: null, | ||
appMetadata: null, | ||
apiKey: null, | ||
device: getDevice() | ||
} | ||
|
||
export function updateConfiguration(update: Partial<Configuration>): void { | ||
configuration = { ...configuration, ...update } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default ` | ||
<svg width="14" height="11" viewBox="0 0 14 11" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path d="M4.48076 8.10881L1.33076 4.95881L0.280762 6.00881L4.48076 10.2088L13.4808 1.20881L12.4308 0.158813L4.48076 8.10881Z" fill="#A4F4C6"/> | ||
</svg> | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default ` | ||
<svg width="100%" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path d="M10 0C4.47 0 0 4.47 0 10C0 15.53 4.47 20 10 20C15.53 20 20 15.53 20 10C20 4.47 15.53 0 10 0ZM15 13.59L13.59 15L10 11.41L6.41 15L5 13.59L8.59 10L5 6.41L6.41 5L10 8.59L13.59 5L15 6.41L11.41 10L15 13.59Z" fill="currentColor"/> | ||
</svg> | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default `<svg width="16" height="13" viewBox="0 0 16 13" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path d="M0.666992 13.0002H15.3337L8.00033 0.333496L0.666992 13.0002ZM8.66699 11.0002H7.33366V9.66683H8.66699V11.0002ZM8.66699 8.3335H7.33366V5.66683H8.66699V8.3335Z" fill="#FFB3B3"/> | ||
</svg> | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default ` | ||
<svg width="100%" height="100%" viewBox="0 0 12 20" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path d="M0 0L0.0100002 6L4 10L0.0100002 14.01L0 20H12V14L8 10L12 6.01V0H0ZM10 14.5V18H2V14.5L6 10.5L10 14.5Z" fill="#929BED"/> | ||
</svg> | ||
` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@Adamj1232 What did removing the
./
prefix resolve?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.
@taylorjdawson Im not too sure, @aaronbarnardsound added that