Skip to content

Commit

Permalink
Commit progress before switching branches
Browse files Browse the repository at this point in the history
  • Loading branch information
ccali11 committed Aug 1, 2023
1 parent f5ad4ea commit 671a251
Show file tree
Hide file tree
Showing 8 changed files with 357 additions and 6 deletions.
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@walletconnect/web3-provider": "^1.8.0",
"@web3modal/ethereum": "^2.7.1",
"@web3modal/html": "^2.7.1",
"@web3modal/standalone": "^2.4.3",
"borsh": "^0.7.0",
"buffer": "^6.0.3",
"d3": "^7.8.1",
Expand Down
8 changes: 6 additions & 2 deletions apps/web/src/composables/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import usePrice from '@/composables/price'
import useTrezor from '@/composables/trezor'
import useUsers from '@/composables/users'
import useWalletConnect from './walletConnect'
import useWalletConnectV2 from './walletConnectV2'
import { Account, BreakdownAmount, BreakdownString, ContractEventsByAddress, Pool, ProviderString, UserWithAccounts } from '@casimir/types'

const currentStaked = ref<BreakdownAmount>({
Expand Down Expand Up @@ -39,6 +40,7 @@ export default function useContracts() {
const { getEthersTrezorSigner } = useTrezor()
const { user } = useUsers()
const { isWalletConnectSigner, getEthersWalletConnectSigner } = useWalletConnect()
const { getEthersWalletConnectSignerV2 } = useWalletConnectV2()

const stakeDepositedListener = async () => await refreshBreakdown()
const stakeRebalancedListener = async () => await refreshBreakdown()
Expand All @@ -51,12 +53,14 @@ export default function useContracts() {
'Browser': getEthersBrowserSigner,
'Ledger': getEthersLedgerSigner,
'Trezor': getEthersTrezorSigner,
'WalletConnect': getEthersWalletConnectSigner
'WalletConnect': getEthersWalletConnectSignerV2
}
const signerType = ethersProviderList.includes(walletProvider) ? 'Browser' : walletProvider
const signerCreator = signerCreators[signerType as keyof typeof signerCreators]
let signer = signerCreator(walletProvider)
if (isWalletConnectSigner(signer)) signer = await signer
// if (isWalletConnectSigner(signer)) signer = await signer
signer = await signer
console.log('signer in deposit :>> ', signer)
const managerSigner = manager.connect(signer as ethers.Signer)
const fees = await getDepositFees()
const depositAmount = parseFloat(amount) * ((100 + fees) / 100)
Expand Down
25 changes: 22 additions & 3 deletions apps/web/src/composables/walletConnectV2.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import { ethers } from 'ethers'
import { EthersWalletConnectSigner } from '@casimir/wallets'
import { EthereumClient, w3mConnectors, w3mProvider } from '@web3modal/ethereum'
import { Web3Modal } from '@web3modal/html'
import { configureChains, createConfig, mainnet, signMessage } from '@wagmi/core'
import { publicProvider } from '@wagmi/core/providers/public'
import useEthers from '@/composables/ethers'
import useAuth from '@/composables/auth'
import { CryptoAddress, LoginCredentials } from '@casimir/types'
import { infuraProvider } from '@wagmi/core/providers/infura'
import useAuth from '@/composables/auth'
import useEthers from '@/composables/ethers'
import useEnvironment from '@/composables/environment'


const { getEthersBalance } = useEthers()
const { createSiweMessage, signInWithEthereum } = useAuth()
const { ethereumUrl } = useEnvironment()

// const chains = [mainnet]
const projectId = '8e6877b49198d7a9f9561b8712805726'



const { chains, publicClient } = configureChains(
[mainnet],
[infuraProvider({ apiKey: import.meta.env.INFURA_API_KEY as string }), w3mProvider({ projectId }), publicProvider()]
[w3mProvider({ projectId }), publicProvider()]
)
const wagmiConfig = createConfig({
autoConnect: true,
Expand All @@ -28,6 +34,18 @@ export default function useWalletConnectV2() {
const ethereumClient = new EthereumClient(wagmiConfig, chains)
const web3modal = new Web3Modal({ projectId }, ethereumClient)

async function getEthersWalletConnectSignerV2() {
// const options = {
// provider: new ethers.providers.JsonRpcProvider(ethereumUrl),
// // baseURL: speculosUrl
// }
// return new EthersWalletConnectSigner(options)
const signer = EthersWalletConnectSigner.create({})
// const signer = await EthersWalletConnectSigner.create({ provider: new ethers.providers.JsonRpcProvider(ethereumUrl) })
console.log('signer :>> ', signer)
return signer
}

async function getWalletConnectAddressAndBalance() : Promise<CryptoAddress> {
const { address } = (ethereumClient.getAccount())
const balance = (await getEthersBalance(address as string)).toString()
Expand Down Expand Up @@ -57,6 +75,7 @@ export default function useWalletConnectV2() {
return {
web3modal,
getWalletConnectAddressAndBalance,
getEthersWalletConnectSignerV2,
loginWithWalletConnectV2
}
}
14 changes: 14 additions & 0 deletions apps/web/src/layouts/default-layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import router from '@/composables/router'
import VueFeather from 'vue-feather'
import useWallet from '@/composables/wallet'
import useUser from '@/composables/users'
import useWalletConnectV2 from '@/composables/walletConnectV2'
const { getEthersWalletConnectSignerV2 } = useWalletConnectV2()
async function func() {
await getEthersWalletConnectSignerV2()
}
const authFlowCardNumber = ref(1)
const selectedProivder = ref(null as null | string)
Expand Down Expand Up @@ -74,6 +80,14 @@ onUnmounted(() =>{

<template>
<div class="min-w-[360px]">
<!-- Huge button -->
<button
class="absolute top-0 right-0 w-[60px] h-[60px] bg-white rounded-[8px] flex justify-center items-center"
style="z-index: 10;"
@click="func"
>
GetWalletConnectEthersSigner
</button>
<div :class="openWalletConnect? 'flex flex-col h-screen' : ''">
<div
class=" px-[60px] pt-[17px] pb-[19px] flex flex-wrap gap-[20px] justify-between items-center bg-black relative"
Expand Down
1 change: 1 addition & 0 deletions common/wallets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@ledgerhq/hw-transport": "^6.27.10",
"@ledgerhq/hw-transport-webusb": "^6.27.10",
"@trezor/connect-web": "^9.0.3",
"@walletconnect/ethereum-provider": "^2.9.1",
"ethers": "^5.7.2"
}
}
8 changes: 7 additions & 1 deletion common/wallets/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { /*BitcoinLedgerSigner, */EthersLedgerSigner } from './providers/ledger'
import { EthersTrezorSigner } from './providers/trezor'
import { EthersWalletConnectSigner } from './providers/walletConnect'

export { /*BitcoinLedgerSigner, */EthersLedgerSigner, EthersTrezorSigner }
export {
/*BitcoinLedgerSigner,*/
EthersLedgerSigner,
EthersTrezorSigner,
EthersWalletConnectSigner
}
64 changes: 64 additions & 0 deletions common/wallets/src/providers/walletConnect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// import { EthereumProvider } from '@walletconnect/ethereum-provider'

import { Web3Modal } from '@web3modal/standalone'
import UniversalProvider from '@walletconnect/universal-provider'
import Client from '@walletconnect/sign-client'

import { ethers, providers, utils } from 'ethers'
const DEFAULT_PROJECT_ID = '8e6877b49198d7a9f9561b8712805726'
const DEFAULT_RELAY_URL = 'wss://relay.walletconnect.com'
const DEFAULT_LOGGER = 'warn'

interface WalletAddressSignerOptions {
provider?: ethers.providers.Provider
}

export class EthersWalletConnectSigner extends ethers.Signer {
private _ethereumProvider: UniversalProvider
private _web3Provider: providers.Web3Provider

private constructor(options: WalletAddressSignerOptions, ethereumProvider: UniversalProvider, web3Provider: providers.Web3Provider) {
super()

this._ethereumProvider = ethereumProvider
this._web3Provider = web3Provider

if (options.provider) {
console.log('got to options.provider')
ethers.utils.defineReadOnly(this, 'provider', options.provider)
} else {
console.log('web3Provider in !options.provider :>> ', web3Provider)
console.log('ethereumProvider :>> ', ethereumProvider)
ethers.utils.defineReadOnly(this, 'provider', web3Provider)
}
}

static async create(options: WalletAddressSignerOptions): Promise<EthersWalletConnectSigner> {
const ethereumProvider = await UniversalProvider.init({
projectId: DEFAULT_PROJECT_ID,
logger: DEFAULT_LOGGER,
relayUrl: DEFAULT_RELAY_URL,
})

const web3Provider = new providers.Web3Provider(ethereumProvider)

return new EthersWalletConnectSigner(options, ethereumProvider, web3Provider)
}

async getAddress(): Promise<string> {
return '0x'
}

async signMessage(message: string | ethers.Bytes): Promise<string> {
return '0x'
}

async signTransaction(tx: ethers.providers.TransactionRequest): Promise<string> {
return '0x'
}

connect(provider: ethers.providers.Provider): ethers.Signer {
return new EthersWalletConnectSigner()
}
}

Loading

0 comments on commit 671a251

Please sign in to comment.