-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'sett/hero-v1000' into develop
- Loading branch information
Showing
53 changed files
with
1,540 additions
and
375 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,108 @@ | ||
import React, { useContext } from 'react'; | ||
import BaseModal from '@/components/BaseModal'; | ||
import { CDN_URL_ICONS } from '@/config'; | ||
import { WalletType } from '@/interfaces/wallet'; | ||
import styles from './styles.module.scss'; | ||
import Image from 'next/image'; | ||
import { XVerseContext } from '@/Providers/xverse-context'; | ||
import useConnect from '@/hooks/useConnect'; | ||
import throttle from 'lodash/throttle' | ||
import { getError } from '@/utils/error'; | ||
import toast from 'react-hot-toast'; | ||
import { useAppDispatch } from '@/stores/hooks'; | ||
import { requestReload } from '@/stores/states/common/reducer'; | ||
import AppLoading from '@/components/AppLoading'; | ||
import cs from 'classnames'; | ||
import { signMessage } from '@/utils/metamask-helper'; | ||
|
||
interface IProps { | ||
isShow: boolean; | ||
onHide: () => void; | ||
} | ||
|
||
interface ModalItem { | ||
image: string; | ||
text: string; | ||
rpc: string; | ||
chainID: number; | ||
} | ||
const ITEMS: ModalItem[] = [ | ||
{ | ||
image: 'https://cryptologos.cc/logos/optimism-ethereum-op-logo.svg', | ||
text: 'Optimism', | ||
rpc: 'https://optimism.llamarpc.com', | ||
chainID: 10 | ||
}, | ||
{ | ||
image: 'https://cryptologos.cc/logos/polygon-matic-logo.svg', | ||
text: 'Polygon', | ||
rpc: 'https://polygon.llamarpc.com', | ||
chainID: 137 | ||
}, | ||
]; | ||
|
||
export const MESSAGE_EVM = 'Are you a Modular Blockchain OG?' | ||
|
||
const ConnectModalEVM = React.memo(({ isShow, onHide }: IProps)=> { | ||
const dispatch = useAppDispatch() | ||
|
||
const [loading, setLoading] = React.useState(false) | ||
|
||
const onSignMessage = async (item: ModalItem) => { | ||
try { | ||
if (loading) return; | ||
setLoading(true) | ||
const { address, signature } = await signMessage(MESSAGE_EVM); | ||
console.log('SANG TEST: ', { | ||
address, signature | ||
}); | ||
|
||
dispatch(requestReload()) | ||
onHide() | ||
} catch (error) { | ||
const { message } = getError(error); | ||
toast.error(message) | ||
} finally { | ||
setLoading(false) | ||
} | ||
} | ||
|
||
const throttleSignMessage = React.useCallback(throttle(onSignMessage, 300), [loading]) | ||
|
||
const renderItem = React.useCallback( | ||
(item: ModalItem) => { | ||
return ( | ||
<div | ||
className={styles.modalItem} | ||
key={item.text} | ||
onClick={() => throttleSignMessage(item)} | ||
> | ||
<Image width={48} height={48} src={item.image} alt="ic_wallet" /> | ||
<div className={styles.modalItem_content}> | ||
<p className={styles.modalItem_title}> | ||
{item.text} | ||
</p> | ||
</div> | ||
</div> | ||
); | ||
}, | ||
[loading] | ||
); | ||
|
||
return ( | ||
<BaseModal isShow={isShow} onHide={onHide} title="Choose network" size="small"> | ||
<div className={cs(styles.modalContent, loading && styles.modalContent__loading)}> | ||
{ITEMS.map(renderItem)} | ||
</div> | ||
{ | ||
loading && ( | ||
<AppLoading className={styles.loading}/> | ||
) | ||
} | ||
</BaseModal> | ||
); | ||
}) | ||
|
||
ConnectModalEVM.displayName = 'ConnectModalEVM'; | ||
|
||
export default ConnectModalEVM; |
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
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 |
---|---|---|
@@ -1,7 +1,11 @@ | ||
const MIN_DECIMAL = 2; | ||
const MAX_DECIMAL = 6; | ||
const NATIVE_ETH_ADDRESS = '0x0000000000000000000000000000000000000000'; | ||
const METAMASK_DOWNLOAD_PAGE = 'https://metamask.io/download/'; | ||
|
||
export { | ||
MIN_DECIMAL, | ||
MAX_DECIMAL | ||
MAX_DECIMAL, | ||
NATIVE_ETH_ADDRESS, | ||
METAMASK_DOWNLOAD_PAGE | ||
}; |
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,18 @@ | ||
export enum WalletError { | ||
UNSUPPORTED_CHAIN = 'UNSUPPORTED_CHAIN', | ||
FAILED_SWITCH_CHAIN = 'FAILED_SWITCH_CHAIN', | ||
FAILED_ADD_CHAIN = 'FAILED_ADD_CHAIN', | ||
FAILED_CONNECT = 'FAILED_CONNECT', | ||
NO_INSTANCE = 'NO_INSTANCE', | ||
FAILED_LINK_WALLET = 'FAILED_LINK_WALLET', | ||
FAILED_UNLINK_WALLET = 'FAILED_UNLINK_WALLET', | ||
FAILED_SIGN_MESSAGE = 'FAILED_SIGN_MESSAGE', | ||
NO_METAMASK = 'NO_METAMASK', | ||
FAILED_TRANSFER = 'FAILED_TRANSFER', | ||
FAILED_GET_TX = 'FAILED_GET_TX', | ||
} | ||
|
||
export enum WalletErrorCode { | ||
USER_REJECTED = 4001, | ||
NO_CHAIN = 4902, | ||
} |
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
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 |
---|---|---|
|
@@ -9,5 +9,6 @@ interface IUniSat { | |
declare global { | ||
interface Window { | ||
unisat: IUniSat; | ||
ethereum: any; | ||
} | ||
} |
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
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
Oops, something went wrong.