-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add WalletConnect integration for Ledger devices #720
base: master
Are you sure you want to change the base?
Changes from 2 commits
9114e0e
1313fb3
4e02ae5
085b220
5e3867e
258e27e
e624b4e
35fbbac
b36cc73
9f19746
b6328e0
cbd48e1
128db1e
f85cd48
975a4b2
4653e59
5c61134
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<template> | ||
<SessionFrame> | ||
<div class="session-container"> | ||
<h2 class="session-title">Use Ledger with WalletConnect</h2> | ||
<div class="session-main"> | ||
<p>Connect your Ledger device through Ledger Live using WalletConnect</p> | ||
<TmBtn value="Connect Wallet" @click.native="signIn()" /> | ||
</div> | ||
</div> | ||
</SessionFrame> | ||
</template> | ||
|
||
<script> | ||
import SessionFrame from "common/SessionFrame" | ||
import { sessionType } from "src/ActionModal/components/ActionModal" | ||
import { initWalletConnect } from "scripts/walletconnect-utils" | ||
import { toBech32 } from "@harmony-js/crypto" | ||
import TmBtn from "common/TmBtn" | ||
|
||
export default { | ||
name: 'session-walletconnect', | ||
components: { | ||
SessionFrame, | ||
TmBtn | ||
}, | ||
data: () => ({ | ||
modal: null | ||
}), | ||
mounted() { | ||
// TODO: Replace with actual project ID from cloud.reown.com | ||
this.modal = initWalletConnect('harmony-staking-dashboard') | ||
}, | ||
methods: { | ||
async signIn() { | ||
try { | ||
const accounts = await this.modal.getAccounts() | ||
if (accounts.length === 0) { | ||
console.error("No accounts found") | ||
return | ||
} | ||
|
||
this.$store.dispatch("signIn", { | ||
sessionType: sessionType.WALLETCONNECT, | ||
address: toBech32(accounts[0]) | ||
}) | ||
|
||
this.$router.push('/') | ||
} catch (ex) { | ||
console.error("WalletConnect error:", ex) | ||
} | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.session-title { | ||
padding: 0 1rem; | ||
margin: 0; | ||
} | ||
|
||
.session-main { | ||
padding: 1rem; | ||
text-align: center; | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { createAppKit } from '@reown/appkit/vue' | ||
import { mainnet } from '@reown/appkit/networks' | ||
import { WagmiAdapter } from '@reown/appkit-adapter-wagmi' | ||
import { toBech32 } from "@harmony-js/crypto" | ||
|
||
const HARMONY_MAINNET = { | ||
id: 1666600000, | ||
name: 'Harmony Mainnet', | ||
network: 'harmony', | ||
nativeCurrency: { name: 'ONE', symbol: 'ONE', decimals: 18 }, | ||
rpcUrls: { | ||
default: { http: ['https://api.harmony.one'] }, | ||
public: { http: ['https://api.harmony.one'] }, | ||
}, | ||
blockExplorers: { | ||
default: { name: 'Explorer', url: 'https://explorer.harmony.one/' }, | ||
}, | ||
} | ||
|
||
export const initWalletConnect = (projectId) => { | ||
const metadata = { | ||
name: 'Harmony Staking', | ||
description: 'Harmony Staking Dashboard', | ||
url: window.location.origin, | ||
icons: ['https://staking.harmony.one/icons/icon-512x512.png'] | ||
} | ||
|
||
const wagmiAdapter = new WagmiAdapter({ | ||
networks: [HARMONY_MAINNET], | ||
projectId | ||
}) | ||
|
||
return createAppKit({ | ||
adapters: [wagmiAdapter], | ||
networks: [HARMONY_MAINNET], | ||
projectId, | ||
metadata, | ||
features: { | ||
analytics: true | ||
} | ||
}) | ||
} | ||
|
||
export const processWalletConnectMessage = async (transactionData, fee, networkConfig) => { | ||
const { gasEstimate } = fee | ||
const { chain_id, rpc_url } = networkConfig | ||
|
||
const harmony = new Harmony(rpc_url, { | ||
chainType: ChainType.Harmony, | ||
chainId: chain_id | ||
}) | ||
|
||
const txnParams = { | ||
gasLimit: Unit.Wei(new BN(gasEstimate).add(new BN("20000"))).toHex(), | ||
gasPrice: Unit.Wei(new BN(1000000000)).toHex(), | ||
chainId: harmony.chainId | ||
} | ||
|
||
switch (transactionData.type) { | ||
case "MsgSend": | ||
return harmony.transactions.signTransaction({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, this is incorrect because the instance |
||
...txnParams, | ||
to: transactionData.to, | ||
value: Unit.Wei(transactionData.amount).toHex(), | ||
data: "0x" | ||
}) | ||
|
||
case "MsgDelegate": | ||
return harmony.stakings.delegate({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
...txnParams, | ||
delegatorAddress: transactionData.delegatorAddress, | ||
validatorAddress: transactionData.validatorAddress, | ||
amount: Unit.Wei(transactionData.amount).toHex() | ||
}) | ||
|
||
case "MsgUndelegate": | ||
return harmony.stakings.undelegate({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
...txnParams, | ||
delegatorAddress: transactionData.delegatorAddress, | ||
validatorAddress: transactionData.validatorAddress, | ||
amount: Unit.Wei(transactionData.amount).toHex() | ||
}) | ||
|
||
case "MsgWithdrawDelegationReward": | ||
return harmony.stakings.collectRewards({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
...txnParams, | ||
delegatorAddress: transactionData.delegatorAddress | ||
}) | ||
|
||
default: | ||
throw new Error(`Unknown transaction type: ${transactionData.type}`) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect.
Harmony
class is undefined. Please do not simply copy from old implementations. Instead, properly invoke correct contract calling methods from wagmi