Skip to content

Commit

Permalink
update: add blockscan in addNetWork metamask
Browse files Browse the repository at this point in the history
  • Loading branch information
Vu Thanh Nam committed Aug 14, 2024
1 parent 63bd41d commit d6726da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
7 changes: 5 additions & 2 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ Vue.prototype.getAccount = async function () {
symbol: 'VIC',
decimals: 18
},
rpcUrls: [config.blockchain.clientRpc]
rpcUrls: [
config.blockchain.clientRpc
],
blockExplorerUrls: [config.explorerUrl]
}]

let account
Expand Down Expand Up @@ -298,7 +301,7 @@ Vue.prototype.checkLongNumber = Helper.checkLongNumber
Vue.prototype.formatBigNumber = Helper.formatBigNumber

const getConfig = Vue.prototype.appConfig = async function () {
let config = await axios.get('/api/config')
let config = await axios.get('http://localhost:3001/api/config')
return config.data
}

Expand Down
25 changes: 8 additions & 17 deletions app/walletAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ const walletAdapter = {

connectViction: async () => {
let provider = null
if (window.coin98) {
provider = window.coin98.provider
} else if (window.viction) {
if (window.viction) {
provider = window.viction
}
if (!provider) {
Expand All @@ -60,11 +58,7 @@ const walletAdapter = {

connectRamper: async (supportedWalletOption) => {
let provider = null
if (window.coin98) {
provider = window.coin98.provider
} else if (window.viction) {
provider = window.viction
} else if (window.ramper2) {
if (window.ramper2) {
provider = window.ramper2.provider
}
if (!provider) {
Expand All @@ -73,6 +67,7 @@ const walletAdapter = {
const chainId = await provider.request({
method: 'net_version'
})

try {
if (supportedWalletOption[0].chainId !== chainId) {
await provider.request({
Expand All @@ -92,23 +87,19 @@ const walletAdapter = {

connectMetamask: async (supportedWalletOption) => {
let provider = null
if (window.coin98) {
provider = window.coin98.provider
} else if (window.viction) {
provider = window.viction
} else if (window.ramper2) {
provider = window.ramper2.provider
} else if (window.ethereum) {
if (window.ethereum) {
provider = window.ethereum
}
if (!provider) {
return { error: 'Please install Metamask wallet' }
}
const chainId = await window.ethereum.request({
const chainId = await provider.request({
method: 'net_version'
})

const chainIdHex = '0x' + parseInt(chainId).toString(16)
try {
if (supportedWalletOption[0].chainId !== chainId) {
if (supportedWalletOption[0].chainId !== chainIdHex) {
await provider.request({
method: 'wallet_addEthereumChain',
params: supportedWalletOption
Expand Down

0 comments on commit d6726da

Please sign in to comment.