Skip to content

Commit

Permalink
Merge branch 'develop' into feature/auth-lambda-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejearley committed Oct 14, 2022
2 parents 0cbb84a + 0044c54 commit a76923c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
16 changes: 14 additions & 2 deletions apps/web/src/composables/ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { EthersProvider } from '@/interfaces/EthersProvider'
import { ProviderString } from '@/types/ProviderString'
import { TransactionInit } from '@/interfaces/TransactionInit'
import { MessageInit } from '@/interfaces/MessageInit'
import { TransactionRequest } from '@ethersproject/abstract-provider'
import { Deferrable } from '@ethersproject/properties'
import useAuth from '@/composables/auth'

const defaultProviders = {
Expand Down Expand Up @@ -62,15 +64,25 @@ export default function useEthers() {
const signer = web3Provider.getSigner()
const signature = await signer.signMessage(hashedMessage)

// Delete
// Todo move this sample code
const { login } = useAuth()
const response = await login({ address: signer._address, message: hashedMessage, signedMessage: signature })
console.log('Response', await response.json()) // Currently the response is always false

return signature
}

return { ethersProviderList, getEthersAddress, sendEthersTransaction, signEthersMessage }
async function getGasPriceAndLimit(
rpcUrl: string,
unsignedTransaction: Deferrable<TransactionRequest>
) {
const provider = new ethers.providers.JsonRpcProvider(rpcUrl)
const gasPrice = await provider.getGasPrice()
const gasLimit = await provider.estimateGas(unsignedTransaction as Deferrable<TransactionRequest>)
return { gasPrice, gasLimit }
}

return { ethersProviderList, getEthersAddress, sendEthersTransaction, signEthersMessage, getGasPriceAndLimit }
}

function getBrowserProviders(ethereum: any) {
Expand Down
9 changes: 4 additions & 5 deletions apps/web/src/composables/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TransactionInit } from '@/interfaces/TransactionInit'
import { Deferrable } from '@ethersproject/properties'
import { TransactionRequest } from '@ethersproject/abstract-provider'
import { MessageInit } from '@/interfaces/MessageInit'
import useEthers from './ethers'

export default function useLedger() {
const bip32Path = '44\'/60\'/0\'/0/0'
Expand Down Expand Up @@ -36,18 +37,16 @@ export default function useLedger() {
const rpcUrl = import.meta.env.PUBLIC_ETHEREUM_RPC || 'http://localhost:8545/'
const provider = new ethers.providers.JsonRpcProvider(rpcUrl)
const { chainId } = await provider.getNetwork()
const gasPrice = await provider.getGasPrice()
const nonce = await provider.getTransactionCount(from)
const unsignedTransaction: ethers.utils.UnsignedTransaction = {
to,
gasPrice,
nonce,
chainId,
value: ethers.utils.parseUnits(value)
}
const gasLimit = await provider.estimateGas(
unsignedTransaction as Deferrable<TransactionRequest>
)
const { getGasPriceAndLimit } = useEthers()
const { gasPrice, gasLimit } = await getGasPriceAndLimit(rpcUrl, unsignedTransaction as Deferrable<TransactionRequest>)
unsignedTransaction.gasPrice = gasPrice
unsignedTransaction.gasLimit = gasLimit

// Todo check before click (user can +/- gas limit accordingly)
Expand Down

0 comments on commit a76923c

Please sign in to comment.