Skip to content

Commit

Permalink
Merge pull request #447 from blocknative/develop
Browse files Browse the repository at this point in the history
Release 1.15.0
  • Loading branch information
lnbc1QWFyb24 authored Nov 13, 2020
2 parents 7330e43 + 5876148 commit bedb7cd
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bnc-onboard",
"version": "1.14.0",
"version": "1.15.0",
"description": "Onboard users to web3 by allowing them to select a wallet, get that wallet ready to transact and have access to synced wallet state.",
"keywords": [
"ethereum",
Expand Down
2 changes: 1 addition & 1 deletion src/modules/check/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function accountSelect(
`
: `
<div style="display: flex; align-items: center;">
<select id="account-select" onchange="window.accountSelect()" style="padding: 0.5rem;">
<select id="account-select" onchange="window.accountSelect();" class="bn-onboard-custom bn-onboard-account-select>
${accountsAndBalances.map(
(account: { balance: string; address: string }) =>
`<option>${account.address} --- ${
Expand Down
7 changes: 5 additions & 2 deletions src/modules/select/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const defaultWalletNames = [
'operaTouch',
'status',
'hyperpay',
'unilogin'
'unilogin',
'tokenpocket'
]

function select(
Expand Down Expand Up @@ -100,9 +101,11 @@ function getModule(name: string): Promise<any> | undefined {
case 'huobiwallet':
return import('./wallets/huobiwallet')
case 'wallet.io':
return import('./wallets/wallet-io')
return import('./wallets/wallet-io')
case 'hyperpay':
return import('./wallets/hyperpay')
case 'tokenpocket':
return import('./wallets/tokenpocket')
default:
return
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions src/modules/select/wallets/tokenpocket.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { mobileWalletInstallMessage } from '../content'
import { WalletModule, Helpers, CommonWalletOptions } from '../../../interfaces'

import tokenpocketIcon from '../wallet-icons/icon-tokenpocket.png'
import tokenpocketIcon2x from '../wallet-icons/[email protected]'

function tokenpocket(options: CommonWalletOptions): WalletModule {
const { preferred, label, iconSrc, svg } = options

return {
name: label || 'TokenPocket',
iconSrc: iconSrc || tokenpocketIcon,
iconSrcSet: iconSrc || tokenpocketIcon2x,
svg,
wallet: async (helpers: Helpers) => {
const { getProviderName, createModernProviderInterface } = helpers

const provider =
(window as any).ethereum ||
((window as any).web3 && (window as any).web3.currentProvider)

return {
provider,
interface:
(getProviderName(provider) === 'TokenPocket' &&
createModernProviderInterface(provider)) ||
null
}
},
type: 'injected',
link: 'https://tokenpocket.pro',
installMessage: mobileWalletInstallMessage,
mobile: true,
preferred
}
}

export default tokenpocket
63 changes: 46 additions & 17 deletions src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@ import { WalletInterface } from './interfaces'

export function getNetwork(provider: any): Promise<number | any> {
return new Promise((resolve, reject) => {
const params = {
const options = {
jsonrpc: '2.0',
method: 'net_version',
params: [],
id: 42
}

// use MetaMask parameter if there
if (provider.chainId) {
return resolve(Number(provider.chainId))
}

const callback = (e: any, res: any) => {
e && reject(e)
const result = res && res.result
resolve(result && Number(result))
}

if (typeof provider.sendAsync === 'function') {
provider.sendAsync(params, callback)
provider.sendAsync(options, callback)
} else if (typeof provider.send === 'function') {
provider.send(params, callback)
provider.send(options, callback)
} else {
resolve(null)
}
Expand All @@ -30,23 +35,30 @@ export function getNetwork(provider: any): Promise<number | any> {

export function getAddress(provider: any): Promise<string | any> {
return new Promise((resolve, reject) => {
const params = {
const options = {
jsonrpc: '2.0',
method: 'eth_accounts',
params: [],
id: 42
}

// use MetaMask request method if there
if (provider.request) {
return provider.request(options).then((res: string[]) => {
return resolve(res[0])
})
}

const callback = (e: any, res: any) => {
e && reject(e)
const result = res && res.result && res.result[0]
resolve(result)
}

if (typeof provider.sendAsync === 'function') {
provider.sendAsync(params, callback)
provider.sendAsync(options, callback)
} else if (typeof provider.send === 'function') {
provider.send(params, callback)
provider.send(options, callback)
} else {
resolve(null)
}
Expand All @@ -65,23 +77,31 @@ export function getBalance(
return
}

const params = {
const options = {
jsonrpc: '2.0',
method: 'eth_getBalance',
params: [currentAddress, 'latest'],
id: 42
}

// use MetaMask request method if there
if (provider.request) {
return provider
.request(options)
.then((res: string) => (res ? new BigNumber(res).toString(10) : null))
.then(resolve)
}

const callback = (e: any, res: any) => {
e && reject(e)
const result = res && res.result
resolve(result && new BigNumber(result).toString(10))
}

if (typeof provider.sendAsync === 'function') {
provider.sendAsync(params, callback)
provider.sendAsync(options, callback)
} else if (typeof provider.send === 'function') {
provider.send(params, callback)
provider.send(options, callback)
} else {
resolve(null)
}
Expand Down Expand Up @@ -131,14 +151,19 @@ export function createModernProviderInterface(provider: any): WalletInterface {
connect: () =>
new Promise(
(resolve: () => void, reject: (err: { message: string }) => void) => {
provider
.enable()
.then(resolve)
.catch(() =>
reject({
message: 'This dapp needs access to your account information.'
const request = provider.request
? getAddress(provider).then((address: string) => {
return address
? address
: provider.request({ method: 'eth_requestAccounts' })
})
)
: provider.enable()

return request.then(resolve).catch(() =>
reject({
message: 'This dapp needs access to your account information.'
})
)
}
),
name: getProviderName(provider)
Expand All @@ -164,7 +189,11 @@ export function getProviderName(provider: any): string | undefined {
if (!provider) return

if (provider.isWalletIO) {
return 'wallet.io';
return 'wallet.io'
}

if (provider.isTokenPocket) {
return 'TokenPocket'
}

if (provider.wallet === 'MEETONE') {
Expand Down
4 changes: 4 additions & 0 deletions src/views/Onboard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
color: #91bced;
border-color: #91bced;
}
:global(.bn-onboard-wallet-check-section select) {
padding: 0.5rem;
}
</style>

{#if $app.walletSelectInProgress}
Expand Down
2 changes: 1 addition & 1 deletion src/views/WalletCheck.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@
{/if}

{#if activeModal.html}
<section>
<section class="bn-onboard-custom bn-onboard-wallet-check-section">
{@html activeModal.html}
</section>
{/if}
Expand Down

0 comments on commit bedb7cd

Please sign in to comment.