Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components/stability-pool/ConnectButton.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/stores/user.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React from "react";
import { runInAction, makeAutoObservable } from "mobx"
import EventBus from "../lib/EventBus"
import vestaStore from "./vesta.store"
import {walletTypes, getMetaMask, getWalletConnect} from "../wallets/Wallets"
import {walletTypes, getMetaMask, getWalletConnect, getTally} from "../wallets/Wallets"

const chainIdMap = {
1: "mainnet",
Expand Down Expand Up @@ -82,6 +82,8 @@ class UserStore {
wallet = await getMetaMask(newConnection)
} else if (this.walletType === walletTypes.WALLET_CONNECT){
wallet = await getWalletConnect(newConnection)
} else if (this.walletType === walletTypes.TALLY){
wallet = await getTally(newConnection)
}
this.web3 = wallet.web3
this.provider = wallet.provider
Expand Down
63 changes: 56 additions & 7 deletions src/wallets/Wallets.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,59 @@ import detectEthereumProvider from '@metamask/detect-provider'
*
*/
export const getMetaMask = async () => {
if(window.ethereum.isMetaMask){
const provider = window.ethereum || await detectEthereumProvider()
if (!provider) {
if(isAndroid || isIOS) {
const currentPath = window.location.pathname
window.location.replace("https://metamask.app.link/dapp/app.bprotocol.org" + currentPath)
return
}
EventBus.$emit("app-error", "metamask is not connected");
return;
}

const web3 = new Web3(Web3.givenProvider || "ws://localhost:8545")
console.log("web3")
console.log(web3)
console.log(window.ethereum.isMetaMask)

const connectFn = async () => {
try{
const accounts = await provider.request({ method: "eth_requestAccounts" })
return accounts[0]
}
catch(err) {
if (err.code === 4001) {
// EIP-1193 userRejectedRequest error
// If this happens, the user rejected the connection request.
EventBus.$emit("app-error", "Please connect to Meta Mask");
} else {
EventBus.$emit("app-error", err.message);
}
throw err
}
}

return {
web3,
provider,
connectFn
}
}else{
if(window.ethereum.isTally){
EventBus.$emit("app-error", "Tally is currently installed and set as the default wallet");
}else{
EventBus.$emit("app-error", "Metamask is currently not installed or open");
}
}
}

export const getTally = async () => {
if(window.ethereum.isTally){
const provider = window.ethereum || await detectEthereumProvider()
if (!provider) {
if(isAndroid || isIOS) {
const currentPath = window.location.pathname
window.location.replace("https://metamask.app.link/dapp/app.bprotocol.org" + currentPath)
return
}
EventBus.$emit("app-error", "metamask is not connected");
EventBus.$emit("app-error", "tally is not connected");
return;
}

Expand All @@ -35,7 +80,7 @@ export const getMetaMask = async () => {
if (err.code === 4001) {
// EIP-1193 userRejectedRequest error
// If this happens, the user rejected the connection request.
EventBus.$emit("app-error", "Please connect to Meta Mask");
EventBus.$emit("app-error", "Please connect to Tally");
} else {
EventBus.$emit("app-error", err.message);
}
Expand All @@ -48,6 +93,9 @@ export const getMetaMask = async () => {
provider,
connectFn
}
}else{
EventBus.$emit("app-error", "Tally is currently not installed or is not set as the default wallet");
}
}

export const getWalletConnect = (newConnection) => {
Expand Down Expand Up @@ -82,4 +130,5 @@ export const getWalletConnect = (newConnection) => {
export const walletTypes = {
"WALLET_CONNECT": "WALLET_CONNECT",
"META_MASK": "META_MASK",
"TALLY": "TALLY"
}