Skip to content

Commit e0e95b7

Browse files
authored
version 0.9.4 (#336)
* Add transaction.to field after it is available (#333) * Configurable Wallet Onboarding (#331) * Add custom buttons for wallet onboarding * Formatting * Add validation for new config property * Update snapshot * Update docs * Make height fixed on icons * Add hover states to buttons * Add link to icons * add links to doc * Revert "Configurable Wallet Onboarding (#331)" (#334) This reverts commit a719996. * Enhancement/configurable wallet on-boarding (#335) * Add custom buttons for wallet onboarding * Formatting * Add validation for new config property * Update snapshot * Update docs * Make height fixed on icons * Add hover states to buttons * Add link to icons * add links to doc * add links to doc * update to version 0.9.4
1 parent 0dd0991 commit e0e95b7

File tree

8 files changed

+350
-118
lines changed

8 files changed

+350
-118
lines changed

README.md

+60-3
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ yarn add bnc-assist
4343
#### Script Tag
4444

4545
The library uses [semantic versioning](https://semver.org/spec/v2.0.0.html).
46-
The current version is 0.9.3.
46+
The current version is 0.9.4.
4747
There are minified and non-minified versions.
4848
Put this script at the top of your `<head>`
4949

5050
```html
51-
<script src="https://assist.blocknative.com/0-9-3/assist.js"></script>
51+
<script src="https://assist.blocknative.com/0-9-4/assist.js"></script>
5252

5353
<!-- OR... -->
5454

55-
<script src="https://assist.blocknative.com/0-9-3/assist.min.js"></script>
55+
<script src="https://assist.blocknative.com/0-9-4/assist.min.js"></script>
5656
```
5757

5858
### Initialize the Library
@@ -207,6 +207,10 @@ var config = {
207207
handleNotificationEvent: Function // Called on every tx notification event with a transaction event object
208208
timeouts: {
209209
txStall: Number // The number of milliseconds after a transaction has been sent before showing a stall notification if not confirmed in the blockchain
210+
},
211+
recommendedWallets: {
212+
desktop: Array, // Array of Objects that define wallets this dapp supports on desktop to users that don't have a wallet
213+
mobile: Array // Array of Objects that define wallets this dapp supports on mobile to users that don't have a wallet
210214
}
211215
}
212216
```
@@ -471,6 +475,59 @@ By supplying an amount of wei to the `minimumBalance` option of the config, deve
471475

472476
Assist will detect transactions which look to be repeated. We notify users of repeat transactions when we see sequential transactions with the same `to` address and the same `value`.
473477

478+
### Recommended Wallets
479+
480+
If you would like to define which wallets your dapp works with and recommends to users that don't currently have a wallet installed, you can define it in the config for desktop and mobile devices:
481+
482+
```javascript
483+
{
484+
recommendedWallets: {
485+
desktop: [
486+
{
487+
name: 'MetaMask',
488+
link: 'https://metamask.io/',
489+
icon: 'https://metamask.io/img/metamask.png'
490+
}
491+
// other desktop wallets your dapp supports here
492+
],
493+
mobile: [
494+
{
495+
name: 'Coinbase',
496+
link: 'https://wallet.coinbase.com/',
497+
icon: 'https://cdn-images-1.medium.com/max/1200/1*7ywNS48PnonfsvvMu1tTsA.png'
498+
}
499+
// other mobile wallets your dapp supports here
500+
]
501+
}
502+
}
503+
```
504+
505+
#### Assist currently only supports the following wallets:
506+
507+
##### Desktop
508+
- MetaMask
509+
- link: https://metamask.io/img/metamask.png
510+
- icon: https://metamask.io/img/metamask.png
511+
- Opera
512+
- link: https://www.opera.com/
513+
- icon: https://images-na.ssl-images-amazon.com/images/I/71Y2mhDkBNL.png
514+
515+
##### Mobile
516+
- Opera Touch
517+
- link: https://www.opera.com/mobile/touch
518+
- icon: https://apps.goodereader.com/wp-content/uploads/icons/1525044654.png
519+
- Coinbase
520+
- link: https://wallet.coinbase.com/
521+
- icon: https://cdn-images-1.medium.com/max/1200/1*7ywNS48PnonfsvvMu1tTsA.png
522+
- Trust
523+
- link: https://trustwallet.com/
524+
- icon: https://uploads-ssl.webflow.com/5a88babea6e0f90001b39b0d/5a8cf5a81df25e0001d5c78d_logo_solid_square_blue%20(2).png
525+
- Status
526+
- link: https://dev.status.im/get/
527+
- icon: https://cdn.investinblockchain.com/wp-content/uploads/2017/12/status-2-300x300.png?x88891
528+
529+
NOTE: above links available at time of writing, but may change.
530+
474531
## API
475532

476533
### `init(config)`

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bnc-assist",
3-
"version": "0.9.3",
3+
"version": "0.9.4",
44
"description": "Blocknative Assist js library for Dapp developers",
55
"main": "lib/assist.min.js",
66
"scripts": {

src/__integration-tests__/ui-rendering/__snapshots__/index.test.js.snap

+124-102
Large diffs are not rendered by default.

src/css/styles.css

+36
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,42 @@ img.bn-onboard-img {
380380
vertical-align: middle;
381381
}
382382

383+
.custom-wallet-buttons {
384+
display: flex;
385+
flex-flow: column nowrap;
386+
justify-content: center;
387+
}
388+
389+
.custom-wallet-buttons .wallet-buttons {
390+
display: flex;
391+
align-items: center;
392+
flex-flow: row wrap;
393+
margin: 0.5rem 0;
394+
}
395+
396+
.custom-wallet-buttons .wallet-button {
397+
display: flex;
398+
align-items: center;
399+
justify-content: center;
400+
padding: 0.5rem 1rem;
401+
margin: 0.25rem 0.5rem 0.25rem 0;
402+
border: 1px solid #cccccc;
403+
border-radius: 5px;
404+
color: #333333;
405+
transition: background 150ms ease-in-out, color 100ms ease-in-out;
406+
}
407+
408+
.custom-wallet-buttons .wallet-button:hover {
409+
background-color: #cccccc;
410+
color: white;
411+
}
412+
413+
.custom-wallet-buttons .wallet-button .image-container img {
414+
width: 2rem;
415+
height: 2rem;
416+
margin-right: 1rem;
417+
}
418+
383419
@media (max-width: 768px) {
384420
.bn-onboard-basic .bn-onboard-sidebar {
385421
width: 34%;

src/js/helpers/validation.js

+16
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ export function validateConfig(config) {
6161
}),
6262
timeouts: ow.optional.object.exactShape({
6363
txStall: ow.number
64+
}),
65+
recommendedWallets: ow.optional.object.exactShape({
66+
desktop: ow.optional.array.ofType(
67+
ow.object.exactShape({
68+
name: ow.string,
69+
link: ow.string,
70+
icon: ow.string
71+
})
72+
).nonEmpty,
73+
mobile: ow.optional.array.ofType(
74+
ow.object.exactShape({
75+
name: ow.string,
76+
link: ow.string,
77+
icon: ow.string
78+
})
79+
).nonEmpty
6480
})
6581
})
6682
)

src/js/logic/send-transaction.js

+3
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ export function sendTransaction({
161161
txPromise = sendMethod(txOptions)
162162
}
163163

164+
// to field doesn't get populated until after the transaction has been initiated
165+
transactionEventObj.to = txOptions.to
166+
164167
handleEvent({
165168
eventCode: 'txRequest',
166169
categoryCode,

src/js/logic/user.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,7 @@ function getWeb3Wallet(categoryCode) {
214214
reject(errorObj)
215215
}, timeouts.changeUI),
216216
onClick: () => {
217-
if (state.mobileDevice) {
218-
window.location = `https://links.trustwalletapp.com/a/key_live_lfvIpVeI9TFWxPCqwU8rZnogFqhnzs4D?&event=openURL&url=${
219-
window.location.href
220-
}`
221-
} else {
217+
if (!state.mobileDevice) {
222218
window.location.reload()
223219
}
224220
}

src/js/views/dom.js

+109-7
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ export function createElementString(type, className, innerHTML) {
101101

102102
export function createElement(el, className, children, id) {
103103
const element = state.iframeDocument.createElement(el)
104-
element.className = className || ''
104+
105+
if (className) {
106+
element.className = className
107+
}
105108

106109
if (children && typeof children === 'string') {
107110
element.innerHTML = children
@@ -259,8 +262,52 @@ export function browserLogos() {
259262
`
260263
}
261264

265+
function mobileButton(data) {
266+
const link = createElement(
267+
'A',
268+
'bn-btn bn-btn-primary bn-btn-outline text-center flex-column'
269+
)
270+
link.style = 'margin: 0 10px;'
271+
link.href = data.link
272+
link.target = '_blank'
273+
link.rel = 'noreferrer noopener'
274+
link.style = 'margin: 0.25rem;'
275+
276+
const image = createElement('img')
277+
image.src = data.icon
278+
image.alt = data.name
279+
image.style = 'width: 100%; height: auto;'
280+
281+
const imageContainer = createElement('span')
282+
imageContainer.style = 'width: 79px; height: 79px;'
283+
imageContainer.appendChild(image)
284+
285+
const br = createElement('br')
286+
const span = createElement('span', null, data.name)
287+
288+
link.appendChild(imageContainer)
289+
link.appendChild(br)
290+
link.appendChild(span)
291+
292+
return link
293+
}
294+
262295
function walletLogos() {
263296
const { trustLogo, coinbaseLogo, operaTouchLogo } = imageSrc
297+
const { recommendedWallets } = state.config
298+
299+
const customButtons = recommendedWallets && recommendedWallets.mobile
300+
301+
if (customButtons) {
302+
const container = createElement('div', 'flex-row btn-row')
303+
container.style = 'flex-flow: row wrap;'
304+
305+
customButtons.forEach(item => {
306+
container.appendChild(mobileButton(item))
307+
})
308+
309+
return container.outerHTML
310+
}
264311

265312
return `
266313
<p class="flex-row btn-row">
@@ -398,7 +445,7 @@ export function onboardMain(type, step) {
398445
: onboardButton[step][type]
399446

400447
const {
401-
config: { style },
448+
config: { style, recommendedWallets, images },
402449
currentProvider
403450
} = state
404451

@@ -408,7 +455,6 @@ export function onboardMain(type, step) {
408455
const defaultImages = imageSrc[step + variant] || imageSrc[step]
409456

410457
const isMetaMask = currentProvider === 'metamask'
411-
const { images } = state.config
412458
const stepKey = stepToImageKey(step)
413459
const devImages = images && images[stepKey]
414460
const onboardImages = {
@@ -420,6 +466,8 @@ export function onboardMain(type, step) {
420466
((isMetaMask || stepKey) && defaultImages && defaultImages.srcset)
421467
}
422468

469+
const customButtons = recommendedWallets && recommendedWallets.desktop
470+
423471
return `
424472
${
425473
onboardImages.src
@@ -434,6 +482,7 @@ export function onboardMain(type, step) {
434482
<h1 class="h4">${heading}</h1>
435483
<p>${description}</p>
436484
<br>
485+
${customButtons && step === 1 ? createCustomButtons(customButtons) : ''}
437486
<br>
438487
<p class="bn-onboard-button-section">
439488
<a href="#"
@@ -443,6 +492,53 @@ export function onboardMain(type, step) {
443492
`
444493
}
445494

495+
function createCustomButtons(dataArr) {
496+
const container = createElement('div', 'custom-wallet-buttons')
497+
container.appendChild(
498+
createElement(
499+
'p',
500+
'',
501+
'The following wallets are compatible with this dapp:'
502+
)
503+
)
504+
505+
const buttonContainer = createElement('div', 'wallet-buttons')
506+
507+
dataArr.forEach(item => {
508+
buttonContainer.appendChild(button(item))
509+
})
510+
511+
container.appendChild(buttonContainer)
512+
513+
container.appendChild(
514+
createElement(
515+
'p',
516+
'',
517+
'Only have a single wallet active at a time, as having multiple active wallets may result in unexpected behavior.'
518+
)
519+
)
520+
521+
return container.outerHTML
522+
}
523+
524+
function button(data) {
525+
const link = createElement('a', 'wallet-button')
526+
link.href = data.link
527+
link.target = '_blank'
528+
link.rel = 'noreferrer noopener'
529+
530+
const logo = createElement('img')
531+
logo.src = data.icon
532+
logo.alt = data.name
533+
534+
const imageContainer = createElement('div', 'image-container', logo)
535+
536+
link.appendChild(imageContainer)
537+
link.appendChild(createElement('span', 'wallet-name', data.name))
538+
539+
return link
540+
}
541+
446542
export function onboardModal(type, step) {
447543
return `
448544
<div id="bn-user-${type}" class="bn-onboard">
@@ -771,8 +867,11 @@ export function removeTouchHandlers(element, type) {
771867

772868
export function handleTouchStart(element) {
773869
return e => {
774-
e.stopPropagation()
775-
e.preventDefault()
870+
if (e.target.tagName !== 'A') {
871+
e.stopPropagation()
872+
e.preventDefault()
873+
}
874+
776875
const touch = e.changedTouches[0]
777876
element.attributes['data-startY'] = touch.screenY
778877
element.attributes['data-startX'] = touch.screenX
@@ -801,8 +900,11 @@ export function handleTouchMove(element) {
801900

802901
export function handleTouchEnd(element, type) {
803902
return e => {
804-
e.stopPropagation()
805-
e.preventDefault()
903+
if (e.target.tagName !== 'A') {
904+
e.stopPropagation()
905+
e.preventDefault()
906+
}
907+
806908
const touch = e.changedTouches[0]
807909
const startY = element.attributes['data-startY']
808910
const startX = element.attributes['data-startX']

0 commit comments

Comments
 (0)