Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Refactor chooseWallet code
Browse files Browse the repository at this point in the history
Colocate the wallet connector with its other info (name, etc)
  • Loading branch information
liamzebedee committed Apr 15, 2020
1 parent eed6c41 commit 0abb63d
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/components/lib/ConnectWalletDialog.js
Expand Up @@ -71,13 +71,14 @@ const WALLETS = [
{
name: "Metamask",
icon: "/images/metamask-fox.svg",
showName: true
showName: true,
connector: injectedConnector
},
{
name: "Ledger",
icon: "/images/ledger.svg"
icon: "/images/ledger.svg",
connector: ledgerConnector
},
}
]

export const ConnectWalletDialog = ({ shown, onConnected, onClose }) => {
Expand All @@ -90,16 +91,9 @@ export const ConnectWalletDialog = ({ shown, onConnected, onClose }) => {
error
}

async function chooseWallet(wallet) {
async function chooseWallet(wallet, connector) {
setChosenWallet(wallet)

let connector
if (wallet == 'Ledger') {
connector = ledgerConnector
} else if (wallet == 'Metamask') {
connector = injectedConnector
}

try {
await activate(connector, undefined, true)
onConnected()
Expand All @@ -118,8 +112,8 @@ export const ConnectWalletDialog = ({ shown, onConnected, onClose }) => {

<ul className='wallets'>
{
WALLETS.map(({ name, icon, showName }) => {
return <li className='wallet-option' onClick={() => chooseWallet(name)}>
WALLETS.map(({ name, icon, showName, connector }) => {
return <li className='wallet-option' onClick={() => chooseWallet(name, connector)}>
<img src={icon} />
{showName && name}
</li>
Expand Down

0 comments on commit 0abb63d

Please sign in to comment.