-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added the add mainnet button and changed copy in the wallet support s…
…ection
- Loading branch information
Showing
4 changed files
with
164 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/components/AddNetworkButton/AddNetworkButton.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.button { | ||
tab-size: 4; | ||
transition: box-shadow 0.3s; | ||
|
||
box-sizing: border-box; | ||
border: none; | ||
font-size: 100%; | ||
font-weight: inherit; | ||
line-height: inherit; | ||
margin: 15px 0px 30px 0px; | ||
text-transform: none; | ||
background-color: transparent; | ||
background-image: none; | ||
cursor: pointer; | ||
|
||
border-radius: 50px; | ||
border-width: 1px; | ||
|
||
padding-left: 1rem; | ||
padding-right: 1rem; | ||
padding-top: 0.5rem; | ||
padding-bottom: 0.5rem; | ||
|
||
background-color: #fe005b; | ||
color: white; | ||
|
||
&:hover { | ||
box-shadow: 0 0 11px rgba(33, 33, 33, 0.7); | ||
border: 0 solid #fe005b; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React from 'react'; | ||
|
||
import { LUKSO_NETWORK_CONFIGS } from '../../constants.js'; | ||
|
||
import styles from './AddNetworkButton.module.scss'; | ||
|
||
/** | ||
* | ||
* @param {*} networkName: either mainnet or testnet | ||
* @returns | ||
*/ | ||
export default function AddNetworkButton({ networkName }) { | ||
const addNetwork = async () => { | ||
const ethereum = window.ethereum; | ||
|
||
if (!ethereum) { | ||
alert('No extension detected.'); | ||
return; | ||
} | ||
|
||
try { | ||
await ethereum.request({ | ||
method: 'wallet_switchEthereumChain', | ||
params: [ | ||
{ | ||
chainId: | ||
'0x' + | ||
BigInt(LUKSO_NETWORK_CONFIGS[networkName].chainId).toString(16), | ||
}, | ||
], | ||
}); | ||
alert( | ||
`Your extension is now connected to LUKSO ${ | ||
networkName == 'mainnet' ? 'Mainnet' : 'Testnet' | ||
}`, | ||
); | ||
} catch (switchError) { | ||
// This error code indicates that the chain has not been added to MetaMask. | ||
if (switchError.code === 4902) { | ||
try { | ||
await ethereum.request({ | ||
method: 'wallet_addEthereumChain', | ||
params: [ | ||
{ | ||
chainId: | ||
'0x' + | ||
BigInt(LUKSO_NETWORK_CONFIGS[networkName].chainId).toString( | ||
16, | ||
), | ||
chainName: LUKSO_NETWORK_CONFIGS[networkName].chainName, | ||
rpcUrls: LUKSO_NETWORK_CONFIGS[networkName].rpcUrls, | ||
nativeCurrency: { | ||
name: 'LYX', | ||
symbol: 'LYX', | ||
decimals: 18, | ||
}, | ||
}, | ||
], | ||
}); | ||
} catch (addError) { | ||
alert(addError.message); | ||
} | ||
} else { | ||
alert(switchError.message); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<button className={styles.button} onClick={addNetwork}> | ||
ADD LUKSO {networkName.toUpperCase()} | ||
</button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters