From b6986d8ac5a1c6e620ac510de6baf2c36c710ae9 Mon Sep 17 00:00:00 2001 From: billy Date: Tue, 5 Apr 2022 01:34:41 +0800 Subject: [PATCH 01/14] feat: compo steps init --- .../shared/VerifyWallet/CurrentWalletBox.tsx | 215 ++++++++++++++++++ .../components/shared/VerifyWallet/Steps.tsx | 73 ++++++ .../shared/VerifyWallet/constants.ts | 16 ++ .../assets/stepAssets/dividerActive.png | Bin 0 -> 421 bytes .../assets/stepAssets/dividerDisable.png | Bin 0 -> 140 bytes .../shared/assets/stepAssets/dividerDone.png | Bin 0 -> 142 bytes .../shared/assets/stepAssets/step1Active.png | Bin 0 -> 915 bytes .../shared/assets/stepAssets/step2Active.png | Bin 0 -> 1003 bytes .../shared/assets/stepAssets/step2Disable.png | Bin 0 -> 827 bytes .../shared/assets/stepAssets/stepSuccess.png | Bin 0 -> 2395 bytes .../pages/Wallet/VerifyWallet/index.tsx | 23 ++ .../pages/Wallet/components/StartUp/index.tsx | 3 +- .../extension/popups/pages/Wallet/index.tsx | 2 + .../shared-base/src/Routes/PopupRoutes.ts | 1 + 14 files changed, 332 insertions(+), 1 deletion(-) create mode 100644 packages/mask/src/components/shared/VerifyWallet/CurrentWalletBox.tsx create mode 100644 packages/mask/src/components/shared/VerifyWallet/Steps.tsx create mode 100644 packages/mask/src/components/shared/VerifyWallet/constants.ts create mode 100644 packages/mask/src/components/shared/assets/stepAssets/dividerActive.png create mode 100644 packages/mask/src/components/shared/assets/stepAssets/dividerDisable.png create mode 100644 packages/mask/src/components/shared/assets/stepAssets/dividerDone.png create mode 100644 packages/mask/src/components/shared/assets/stepAssets/step1Active.png create mode 100644 packages/mask/src/components/shared/assets/stepAssets/step2Active.png create mode 100644 packages/mask/src/components/shared/assets/stepAssets/step2Disable.png create mode 100644 packages/mask/src/components/shared/assets/stepAssets/stepSuccess.png create mode 100644 packages/mask/src/extension/popups/pages/Wallet/VerifyWallet/index.tsx diff --git a/packages/mask/src/components/shared/VerifyWallet/CurrentWalletBox.tsx b/packages/mask/src/components/shared/VerifyWallet/CurrentWalletBox.tsx new file mode 100644 index 000000000000..09c399566e59 --- /dev/null +++ b/packages/mask/src/components/shared/VerifyWallet/CurrentWalletBox.tsx @@ -0,0 +1,215 @@ +import { useCallback } from 'react' +import { ExternalLink } from 'react-feather' +import classNames from 'classnames' +import { ProviderType } from '@masknet/web3-shared-evm' +import { Button, Link, Typography } from '@mui/material' +import { makeStyles } from '@masknet/theme' +import { useRemoteControlledDialog } from '@masknet/shared-base-ui' +import { + useAccount, + useWeb3State, + useChainId, + useNetworkDescriptor, + useProviderDescriptor, + useProviderType, + useReverseAddress, + useWallet, +} from '@masknet/plugin-infra' +import { FormattedAddress, WalletIcon } from '@masknet/shared' +import { WalletMessages } from '../../../plugins/Wallet/messages' +import { useI18N } from '../../../utils' +import Services from '../../../extension/service' +import { ActionButtonPromise } from '../../../extension/options-page/DashboardComponents/ActionButton' + +const useStyles = makeStyles()((theme) => ({ + currentAccount: { + padding: '12px 8px', + width: '100%', + background: '#fff', + boxSizing: 'border-box', + marginBottom: theme.spacing(2), + display: 'flex', + borderRadius: 8, + alignItems: 'center', + }, + + accountInfo: { + flexGrow: 1, + marginLeft: theme.spacing(1), + }, + accountName: { + fontSize: 16, + marginRight: 4, + fontWeight: 'bold', + }, + infoRow: { + display: 'flex', + alignItems: 'center', + }, + actionButton: { + fontSize: 12, + marginLeft: theme.spacing(1), + padding: '8px 12px', + fontWeight: 'bold', + background: 'rgba(15, 20, 25, 1)', + color: '#fff', + width: 'fit-content', + }, + address: { + fontSize: 12, + marginRight: theme.spacing(1), + display: 'inline-block', + color: theme.palette.text.secondary, + }, + link: { + color: theme.palette.text.primary, + fontSize: 14, + display: 'flex', + alignItems: 'center', + }, + linkIcon: { + marginRight: theme.spacing(1), + }, + twitterProviderBorder: { + width: 14, + height: 14, + }, + connectButtonWrapper: { + display: 'flex', + justifyContent: 'center', + alignItems: 'center', + margin: theme.spacing(2, 0), + }, + domain: { + fontSize: 16, + lineHeight: '18px', + marginLeft: 6, + padding: 4, + borderRadius: 8, + backgroundColor: '#ffffff', + color: theme.palette.common.black, + }, +})) +interface CurrentWalletBox { + isDashboard?: boolean + disableChange?: boolean +} +export function CurrentWalletBox(props: CurrentWalletBox) { + const { t } = useI18N() + const { classes } = useStyles() + const chainId = useChainId() + const account = useAccount() + const wallet = useWallet() + const providerType = useProviderType() + const providerDescriptor = useProviderDescriptor() + const networkDescriptor = useNetworkDescriptor() + const { Utils } = useWeb3State() ?? {} + + const { value: domain } = useReverseAddress(account) + + // #region change provider + const { openDialog: openSelectProviderDialog } = useRemoteControlledDialog( + WalletMessages.events.selectProviderDialogUpdated, + ) + // #endregion + + // #region walletconnect + const { setDialog: setWalletConnectDialog } = useRemoteControlledDialog( + WalletMessages.events.walletConnectQRCodeDialogUpdated, + ) + // #endregion + + const onDisconnect = useCallback(async () => { + switch (providerType) { + case ProviderType.WalletConnect: + setWalletConnectDialog({ + open: true, + uri: await Services.Ethereum.createConnectionURI(), + }) + break + case ProviderType.Fortmatic: + await Services.Ethereum.disconnectFortmatic(chainId) + break + } + }, [chainId, providerType, setWalletConnectDialog]) + + const onChange = useCallback(() => { + openSelectProviderDialog() + }, [openSelectProviderDialog]) + + return account ? ( +
+ +
+
+ {providerType !== ProviderType.MaskWallet ? ( + + {domain && Utils?.formatDomainName + ? Utils.formatDomainName(domain) + : providerDescriptor?.name} + + ) : ( + <> + + {wallet?.name ?? providerDescriptor?.name} + + {domain && Utils?.formatDomainName ? ( + {Utils.formatDomainName(domain)} + ) : null} + + )} +
+
+ + + + + + + +
+
+ {!props.disableChange && ( +
+ {providerType === ProviderType.WalletConnect || providerType === ProviderType.Fortmatic ? ( + } + failIcon={<>} + /> + ) : null} + +
+ )} +
+ ) : ( +
+ +
+ ) +} diff --git a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx new file mode 100644 index 000000000000..de647ce01f35 --- /dev/null +++ b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx @@ -0,0 +1,73 @@ +import { makeStyles } from '@masknet/theme' +import { useState } from 'react' +import { CurrentWalletBox } from './CurrentWalletBox' +import { + step1ActiveIcon, + stepSuccessIcon, + dividerDisableIcon, + dividerSuccessIcon, + dividerActiveIcon, + step2DisableIcon, + step2ActiveIcon, +} from './constants' +import { ImageIcon } from '@masknet/shared' + +const useStyles = makeStyles()({ + container: { + width: '100%', + display: 'flex', + flexDirection: 'column', + alignItems: 'center', + }, + stepBox: { + marginTop: 12, + }, + stepLine: { + display: 'flex', + flexDirection: 'column', + alignItems: 'center', + }, + stepRow: { + display: 'flex', + alignItems: 'center', + minHeight: 200, + }, + divider: { + margin: '2px 0', + }, +}) + +export function Steps() { + const { classes } = useStyles() + const [step, setStep] = useState(0) + + const stepIconMap: any = { + 0: { + step1: step1ActiveIcon, + divider: dividerDisableIcon, + step2: step2DisableIcon, + }, + 1: { + step1: stepSuccessIcon, + divider: dividerActiveIcon, + step2: step2ActiveIcon, + }, + 2: { + step1: stepSuccessIcon, + divider: dividerSuccessIcon, + step2: stepSuccessIcon, + }, + } + return ( +
+ +
+
+ + + +
+
+
+ ) +} diff --git a/packages/mask/src/components/shared/VerifyWallet/constants.ts b/packages/mask/src/components/shared/VerifyWallet/constants.ts new file mode 100644 index 000000000000..f09f49e666a6 --- /dev/null +++ b/packages/mask/src/components/shared/VerifyWallet/constants.ts @@ -0,0 +1,16 @@ +const step1ActiveIcon = new URL('../assets/stepAssets/step1Active.png', import.meta.url) +const step2DisableIcon = new URL('../assets/stepAssets/step2Disable.png', import.meta.url) +const step2ActiveIcon = new URL('../assets/stepAssets/step2Active.png', import.meta.url) +const stepSuccessIcon = new URL('../assets/stepAssets/stepSuccess.png', import.meta.url) +const dividerDisableIcon = new URL('../assets/stepAssets/dividerDisable.png', import.meta.url) +const dividerActiveIcon = new URL('../assets/stepAssets/dividerActive.png', import.meta.url) +const dividerSuccessIcon = new URL('../assets/stepAssets/dividerDone.png', import.meta.url) +export { + step1ActiveIcon, + step2DisableIcon, + step2ActiveIcon, + stepSuccessIcon, + dividerDisableIcon, + dividerActiveIcon, + dividerSuccessIcon, +} diff --git a/packages/mask/src/components/shared/assets/stepAssets/dividerActive.png b/packages/mask/src/components/shared/assets/stepAssets/dividerActive.png new file mode 100644 index 0000000000000000000000000000000000000000..260dae99f2f091f7cb7b4cbc258bd3009d4074a6 GIT binary patch literal 421 zcmV;W0b2fvP)@1mxWS<_aHOFAjR4AJ@i*$ii^%hz#W`U|kO!_V^DVdv^=&@--aX<}P+q@6E7F`@- z>vb%9Rxijl2I;1lP)|ZfYX+fnFs_r_t;>zq;9oLHXJ_jtsM_brE{EHG4PJ1+Jo|=> zW5H3TKAJv~4V^5?J>qyT{5>3v!CP>QLD&XgJ4J|lWZL<}^7E<3kp19~Sydq~G;+}v-mdiv{s!Nc$W1bw P00000NkvXXu0mjfHVU$@ literal 0 HcmV?d00001 diff --git a/packages/mask/src/components/shared/assets/stepAssets/dividerDisable.png b/packages/mask/src/components/shared/assets/stepAssets/dividerDisable.png new file mode 100644 index 0000000000000000000000000000000000000000..3eed001bf264691e7ba51ba145b8cdde5a897512 GIT binary patch literal 140 zcmeAS@N?(olHy`uVBq!ia0vp^OhD|)!3HD~UYmaaQk(@Ik;M!Q+`=Ht$S`Y;1W=H% zILO_JVcj{Imp~3nx}&cn1H;CC?mvmFK)#}P)6kV4VjN&*&%RSLls1Z~8hkOT`$ zQ(6d_`~kDrEW63f_1^cfGaFYQJ74d;d)~R{ek|x8Bi}fgqM==7qD5kE5s)+M3KuXa zKWJb!J|d&ubHG1fGK(7~sy&H&;6U1)kqL$uZ3K6rUYEHIy3@ zj~R{4$sxcI@o@RacFleS+!E00Oh7?-pmmO=;*C$7JFGBfxOBMX!A)E+$o5i;8JiI4 zl_rpj+?81%lW&`V{pHp<4bMz%3}zIgrLmD=^|tW5|59AfN4z-t(s<{3HtvBu_2DFk zt|71C9L}iSA{S&;Ry?1=^$Tk@O(j>E5tcb50)?cYr}t92 zdn*|QN#Zbas8%RQ#2jS89V>yz<)oOKfkk9w`0ZXvpT3oNyliRVrg6b^+QyT;4O8;~ zLd!~2XS^F|q!4RB9QENT)2~x-f8dSM#A_MAJt(;0fn%QA)c#$4Bke?D#c=wE#LUtl z)7U=om^ps96=6(;>jS=oTyeHSTmj$uQrQbx@td{2_VJ6gPcnB35J7wc_dZS8PL zB3?K)jS1$hq pGmbS&K^Yv%bAM3L`}2Tt`~ey@P+hJV7Hgk#IHj3WFjGhE9>&=5`A|6C9iXIfiD1zY0$H81gH-{hrg~U^CMnMEo@(+wb zBIqT#7!pX#1QZiQvKTRDvpZ!~b*+$odnPhLL$5!k@M%FW#_vnc;4SN&W4!`iiA+K53YM9*IWw>>gh(8s=Dm1V zQGnKsh*ys(8ccjnl`Wg?K(XdMhrxkhg$exCymp*cyc2hBK`frNz&*TtUxl}msfJ{} zk1Zz328zIpA<;VEQi$Iv`Y_VVcWy@LIcMS53P8_L1tz|vs=qfd^PbYqtYw^8W^Be$ zQdl+3LpA%jb<)Dd7KE|c6!z~j{2+W|tw*P*(NfCDD$E=+u8sf%r<~;?PY%AJ1!(sU zm&u3r)shsZz7l+xu7H!O?gB3z{|52WV`^QWRyaX$t8-c%X}__tGWdvbYfc8De7|_T zZ1NU3;%sQ~? z7#kgD$?9&`(7~LIA2*Z08Jaw}5bTw26|Rq2TU+kn5K5GdG6v1YFwEF0d&xMdW?0Km zVXIcaTo9O}4W7?h*Yo8#3Zy3M-w+|xv8`jM;Yd`Q7p5y!)6sh#lcvB~>wZ-&@}aw! z%aAWNL?o2bD)n=5=qsMaQawgfU}^V?o-Y=QQ>9d>wI+N~CXzUb0Tx z&9Fq(&|YGL=p8VFuB@!Ypq5>NrDQK-tVOGo^f6{a{vxFkU#VZTDni!u|}({ zkNYIX!F)c?!TcB)gCCe+8B_{TZomLcPsw>+<2Gju%-)i?nTpAXkJ zu+QAsG+ep~DRy^vX*e8GKA+d6Qptet?d_?QOe$5IFP_y_;}R%QcEf=E&1REEqY(qC z$z)8 zM@NK~8jS|E+ieG&h_eH8zCCmzeg}AG>x|{#F__Zv@iF0yQl(O%e!uUInHI4uRpKTx z<5vr8f_RbC>+tZKjE`;|)oQg6EYA6nV(kGIICkj2qWz5{_bUzP><`<-ZuJxG2V4LE002ovPDHLk FV1h~3e(eAN literal 0 HcmV?d00001 diff --git a/packages/mask/src/components/shared/assets/stepAssets/stepSuccess.png b/packages/mask/src/components/shared/assets/stepAssets/stepSuccess.png new file mode 100644 index 0000000000000000000000000000000000000000..032d8502b4a6dbfb916ed7051c479a6e8c2f4d49 GIT binary patch literal 2395 zcmV-h38eOkP);LTG&VwFMF;4L zvKWaCQoTb+sAA)a84wypAW(v423bj)wrY&yIM2?r-_JdqbN!RpO`2pXMl9w;FTU@- zd(ZvuIp?0A3-BrZzYqZq{r0QE|?w7%xUB>j~ zG-Waw{>8ojoEJ!Mb~-A%OjKj!F{)Vitf8l{Y_`Vp#z|KDCJ8^kCM$l2gZp2dAGP$ zTEnG$i5{;mo9|XUoKMZ8JGOnDWqOB4O`gDGlUMmkZQA>d(_W`#xB>M_U5WY&EX@^I z=>j}Pn&$Js$xpdh#_VF&_-Ad#a1tIOWDVch{Skk?&7Tu+5~1F}b*F9Pbbahk|4#mq zLMsbb_pd^BDGRR_Uq#6Ah~m-0!sEb+6@R@Xc9(}ry<&LRJlwDD8|TgGZ}GG{@G*$B z`3*yj|8Bdwtp+N;U+$`UMf)E*4Zyyzk+p!!3(Lj=ORieY8XeocXohf)CtZM#Lj(=x zdc}-t_3i40%4TvZlgrQ&l&FB9dU%FF8bkA`>r~mdY2djG;6h>nn-6?+-46^Sz%QQ_ zT>dk!L&{1+Z_5+>?>nwLW6Y;6@nLhdn_4U7#aS9h%^&I%7Y{uj$0v;$EHk*j;qGL{ z2<9`aZ~8Wzfqrng0B_ zC_oLr*DY>Ee&MS!P^>F>$n?e;SV-(ykU;dQ_GYamF3pb7hrzy_S z#Y-EXW7jor`+6i%(ecU+m)Z` z6DpuYqF>}kKtB&0FS3TVzZZlPSetrGb2Bz>zt3uBYbmT~ATnkU{)Sb|v?OU#j!#y* zM6>oR+usaM!4$Z#C*J!nqYM7@!vg%_>F+f-`4!O5CB!>pW{P>TBx4!uJP8kcaZ#K( z3`y_+U^f+oMb1{B%?K-SWLI5cSJPAR;pAc1QS*oO^%9A9UxY=lJC`W#TU3WS?AMzVk0m$~;CDw?ZH6wq zTPwqfM0Cq*??2ohYwD9AykTPlD(wo14IV`YZbthaodjziD6tY?Lw~aZLo;l(*hTok zJs$TqoSE=#)uFpdNP-!eW?w{)8kO)|2Nfs?Eg68b3## z9ao`QkF1!b%y{e;+wxmHWa}hY96eo*KsOlFEkD*#LEP8C{=<)(-qCGI8cIcu$AdWs zu4cprp&N2~lTw{Ht2j<>%T;D*k{L}>!wjMz^p&SNcNN0xr11MZ{9i|4`zt4-zc9eR z79!pYV!rD5mWul^PPpT0Hkc*YIuEG}@va2f_6wZR^l%(;NZ_D*DZivM->J4kcIOGj zSc(Z&Nxbc;XgOzvUE7RDAwRKr zTXk$tHJO*|y2{SjRN*96){->`>HCq9WS|k!VMlD@Lzd!pW=yd(mD{pa@X}ZmT7J~= z+bR}Vs+F`u0u?GFihRO)5YeVQ&BT6<`Gj1ZgpoNBwf5aGY}X^lvZI6(S9aP~@t2;` zmbb+@VNRC-;$jpGOYbOvf*wkIlBF%Dd7XDCjFRc3ay(b7M;40AM8q{o(r^{Nv0^0npFs6cErXo5l|2XzRbH6p!k^)JPF5he7Hq-qs$ zITZlgnWK)~i6*AU$n# z3$g|pRC%vL3sb8~LL8b5PCX0mNEP?h%pz2Up12n(tDK%^mDCc|-74E-Qf*rgLPG_t z!trp@NQV*mA&2F_4eLR&z_&mLj1O!`8pS9=U@$WFNaIPFyv>Ksj9 zY{@-MQ7c7i7pcgk=*jVwNPloYR0_$BM4{MwSs4_x-TnSgs2hxi9=;ATblFJVCx16@ z$|HS+LcyTXIiDcuGPMsQg$7{tLF`*56m*hrj>; N002ovPDHLkV1h42d42!@ literal 0 HcmV?d00001 diff --git a/packages/mask/src/extension/popups/pages/Wallet/VerifyWallet/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/VerifyWallet/index.tsx new file mode 100644 index 000000000000..12667d3080bb --- /dev/null +++ b/packages/mask/src/extension/popups/pages/Wallet/VerifyWallet/index.tsx @@ -0,0 +1,23 @@ +import { makeStyles } from '@masknet/theme' +import { memo } from 'react' +import { Steps } from '../../../../../components/shared/VerifyWallet/Steps' + +const useStyles = makeStyles()((theme) => ({ + container: { + display: 'flex', + flexDirection: 'column', + flex: 1, + background: 'rgba(247, 249, 250, 1)', + padding: '8px 16px 16px 16px', + }, +})) +const VerifyWallet = memo(() => { + const { classes } = useStyles() + return ( +
+ +
+ ) +}) + +export default VerifyWallet diff --git a/packages/mask/src/extension/popups/pages/Wallet/components/StartUp/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/components/StartUp/index.tsx index d9b3f59504d9..f357cfbdbc63 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/components/StartUp/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/components/StartUp/index.tsx @@ -103,7 +103,8 @@ export const WalletStartUp = memo(() => { {!loading ? ( diff --git a/packages/mask/src/extension/popups/pages/Wallet/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/index.tsx index 5da93e45c4dd..a017418784e2 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/index.tsx @@ -32,6 +32,7 @@ const SetPaymentPassword = lazy(() => import('./SetPaymentPassword')) const WalletRecovery = lazy(() => import('./WalletRecovery')) const LegacyWalletRecovery = lazy(() => import('./LegacyWalletRecovery')) const ReplaceTransaction = lazy(() => import('./ReplaceTransaction')) +const VerifyWallet = lazy(() => import('./VerifyWallet')) const r = relativeRouteOf(PopupRoutes.Wallet) export default function Wallet() { @@ -116,6 +117,7 @@ export default function Wallet() { } /> } /> } /> + } /> )} diff --git a/packages/shared-base/src/Routes/PopupRoutes.ts b/packages/shared-base/src/Routes/PopupRoutes.ts index 3294d3ade04f..174b37b7f0d0 100644 --- a/packages/shared-base/src/Routes/PopupRoutes.ts +++ b/packages/shared-base/src/Routes/PopupRoutes.ts @@ -30,4 +30,5 @@ export enum PopupRoutes { ThirdPartyRequestPermission = '/3rd-request-permission', SignRequest = '/sign-request', Swap = '/swap', + VerifyWallet = '/wallet/verify', } From 7128d11066de35ec6186aceb96f056407f83e811 Mon Sep 17 00:00:00 2001 From: billy Date: Tue, 5 Apr 2022 02:07:21 +0800 Subject: [PATCH 02/14] fix: ui --- .../components/shared/VerifyWallet/Steps.tsx | 55 +++++++++++++++++-- .../shared/VerifyWallet/constants.ts | 1 + 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx index de647ce01f35..3c03e5425a79 100644 --- a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx +++ b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx @@ -11,8 +11,10 @@ import { step2ActiveIcon, } from './constants' import { ImageIcon } from '@masknet/shared' +import { Typography } from '@mui/material' +import ActionButton from '../../../extension/options-page/DashboardComponents/ActionButton' -const useStyles = makeStyles()({ +const useStyles = makeStyles()((theme) => ({ container: { width: '100%', display: 'flex', @@ -21,21 +23,43 @@ const useStyles = makeStyles()({ }, stepBox: { marginTop: 12, + display: 'flex', + alignItems: 'flex-start', + flexGrow: 'grow', }, stepLine: { display: 'flex', flexDirection: 'column', alignItems: 'center', + marginRight: 12, }, - stepRow: { + stepRowBox: { + width: '100%', display: 'flex', + flexDirection: 'column', alignItems: 'center', minHeight: 200, }, + stepRow: { + color: theme.palette.text.secondary, + minHeight: 100, + }, + stepIntro: { + marginTop: 12, + fontSize: 14, + }, divider: { - margin: '2px 0', + margin: '4px 0', + }, + actionBox: { + width: 'calc(100% - 32px)', + gap: 12, + position: 'fixed', + bottom: 16, + display: 'flex', + alignItems: 'center', }, -}) +})) export function Steps() { const { classes } = useStyles() @@ -67,6 +91,29 @@ export function Steps() { +
+
+ Persona Name Sign + + Sign seamlessly with Persona, ensure the validity of data. + +
+
+ Wallet Name Sign + + After two steps, you will own, view, utilize all your cyber identities through Next.ID. You + can also disconnect them easily. + +
+
+ +
+ + Cancel + + + {step === 2 ? 'Done' : 'Confirm'} +
) diff --git a/packages/mask/src/components/shared/VerifyWallet/constants.ts b/packages/mask/src/components/shared/VerifyWallet/constants.ts index f09f49e666a6..f16ea4657f0e 100644 --- a/packages/mask/src/components/shared/VerifyWallet/constants.ts +++ b/packages/mask/src/components/shared/VerifyWallet/constants.ts @@ -5,6 +5,7 @@ const stepSuccessIcon = new URL('../assets/stepAssets/stepSuccess.png', import.m const dividerDisableIcon = new URL('../assets/stepAssets/dividerDisable.png', import.meta.url) const dividerActiveIcon = new URL('../assets/stepAssets/dividerActive.png', import.meta.url) const dividerSuccessIcon = new URL('../assets/stepAssets/dividerDone.png', import.meta.url) + export { step1ActiveIcon, step2DisableIcon, From b309e41358997eaeb129ed87804d2792b31dbfbe Mon Sep 17 00:00:00 2001 From: billy Date: Tue, 5 Apr 2022 16:59:26 +0800 Subject: [PATCH 03/14] fix: fix --- .../components/shared/VerifyWallet/Steps.tsx | 55 +++++++++++++++++-- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx index 3c03e5425a79..8128109beafe 100644 --- a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx +++ b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx @@ -13,6 +13,7 @@ import { import { ImageIcon } from '@masknet/shared' import { Typography } from '@mui/material' import ActionButton from '../../../extension/options-page/DashboardComponents/ActionButton' +import { useNavigate } from 'react-router-dom' const useStyles = makeStyles()((theme) => ({ container: { @@ -59,29 +60,60 @@ const useStyles = makeStyles()((theme) => ({ display: 'flex', alignItems: 'center', }, + roundBtn: { + borderRadius: 99, + }, })) +enum SignSteps { + Ready = 0, + Step1Done = 1, + Step2Done = 2, +} + export function Steps() { const { classes } = useStyles() const [step, setStep] = useState(0) - + const navigate = useNavigate() const stepIconMap: any = { - 0: { + [SignSteps.Ready]: { step1: step1ActiveIcon, divider: dividerDisableIcon, step2: step2DisableIcon, }, - 1: { + [SignSteps.Step1Done]: { step1: stepSuccessIcon, divider: dividerActiveIcon, step2: step2ActiveIcon, }, - 2: { + [SignSteps.Step2Done]: { step1: stepSuccessIcon, divider: dividerSuccessIcon, step2: stepSuccessIcon, }, } + + const onConfirm = () => { + if (step === SignSteps.Ready) { + personaSlientSign() + } else if (step === SignSteps.Step1Done) { + walletSign() + } else { + navigate(-1) + } + } + const personaSlientSign = async () => { + console.log('p sign') + setStep(1) + } + const walletSign = async () => { + console.log('wallet sign') + setStep(2) + } + const onCancel = () => { + navigate(-1) + } + return (
@@ -108,10 +140,21 @@ export function Steps() {
- + Cancel - + {step === 2 ? 'Done' : 'Confirm'}
From 35afcfb8685e22fffd13cb2824e041a6aa924a78 Mon Sep 17 00:00:00 2001 From: billy Date: Wed, 6 Apr 2022 15:04:36 +0800 Subject: [PATCH 04/14] fix: kill unused code --- packages/mask/src/components/shared/VerifyWallet/Steps.tsx | 2 +- .../extension/popups/pages/Wallet/components/StartUp/index.tsx | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx index 8128109beafe..167552382de8 100644 --- a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx +++ b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx @@ -38,7 +38,6 @@ const useStyles = makeStyles()((theme) => ({ width: '100%', display: 'flex', flexDirection: 'column', - alignItems: 'center', minHeight: 200, }, stepRow: { @@ -102,6 +101,7 @@ export function Steps() { navigate(-1) } } + const personaSlientSign = async () => { console.log('p sign') setStep(1) diff --git a/packages/mask/src/extension/popups/pages/Wallet/components/StartUp/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/components/StartUp/index.tsx index f357cfbdbc63..d9b3f59504d9 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/components/StartUp/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/components/StartUp/index.tsx @@ -103,8 +103,7 @@ export const WalletStartUp = memo(() => {
{!loading ? ( From 1c06e0d194f726379909c72a7eb03554bf8b2c4a Mon Sep 17 00:00:00 2001 From: billy Date: Wed, 6 Apr 2022 16:28:11 +0800 Subject: [PATCH 05/14] feat: slient sign --- .../components/shared/VerifyWallet/Steps.tsx | 33 +++++++++++++++++-- .../pages/Wallet/VerifyWallet/index.tsx | 1 + 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx index 167552382de8..090336bc83db 100644 --- a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx +++ b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx @@ -14,6 +14,12 @@ import { ImageIcon } from '@masknet/shared' import { Typography } from '@mui/material' import ActionButton from '../../../extension/options-page/DashboardComponents/ActionButton' import { useNavigate } from 'react-router-dom' +import { useValueRef } from '@masknet/shared-base-ui' +import { currentPersonaIdentifier } from '../../../settings/settings' +import { ECKeyIdentifier, Identifier, NextIDAction, NextIDPlatform } from '@masknet/shared-base' +import { useAsync } from 'react-use' +import Services from '../../../extension/service' +import { NextIDProof } from '@masknet/web3-providers' const useStyles = makeStyles()((theme) => ({ container: { @@ -74,6 +80,13 @@ export function Steps() { const { classes } = useStyles() const [step, setStep] = useState(0) const navigate = useNavigate() + const currentIdentifier = Identifier.fromString(useValueRef(currentPersonaIdentifier), ECKeyIdentifier) + const { value: persona_ } = useAsync(async () => { + return Services.Identity.queryPersona(currentIdentifier.unwrap()) + }, []) + + if (!persona_ || !persona_.publicHexKey) return null + const stepIconMap: any = { [SignSteps.Ready]: { step1: step1ActiveIcon, @@ -103,8 +116,24 @@ export function Steps() { } const personaSlientSign = async () => { - console.log('p sign') - setStep(1) + try { + const payload = await NextIDProof.createPersonaPayload( + persona_.publicHexKey as string, + NextIDAction.Create, + persona_.nickname as string, + NextIDPlatform.Ethereum, + 'default', + ) + if (!payload) throw new Error('Failed to create persona payload.') + const signResult = await Services.Identity.generateSignResult( + currentIdentifier.val as any, + payload.signPayload, + ) + if (!signResult) throw new Error('Failed to sign persona.') + setStep(1) + } catch (error) { + console.error(error) + } } const walletSign = async () => { console.log('wallet sign') diff --git a/packages/mask/src/extension/popups/pages/Wallet/VerifyWallet/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/VerifyWallet/index.tsx index 12667d3080bb..d50278b5c66c 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/VerifyWallet/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/VerifyWallet/index.tsx @@ -13,6 +13,7 @@ const useStyles = makeStyles()((theme) => ({ })) const VerifyWallet = memo(() => { const { classes } = useStyles() + return (
From 1056270ab42335433784633e360aae82177bc03e Mon Sep 17 00:00:00 2001 From: billy Date: Wed, 6 Apr 2022 17:40:02 +0800 Subject: [PATCH 06/14] fix: fix --- .../shared/VerifyWallet/CurrentWalletBox.tsx | 5 +-- .../components/shared/VerifyWallet/Steps.tsx | 31 +++++++++++++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/packages/mask/src/components/shared/VerifyWallet/CurrentWalletBox.tsx b/packages/mask/src/components/shared/VerifyWallet/CurrentWalletBox.tsx index 09c399566e59..018cb166c0e7 100644 --- a/packages/mask/src/components/shared/VerifyWallet/CurrentWalletBox.tsx +++ b/packages/mask/src/components/shared/VerifyWallet/CurrentWalletBox.tsx @@ -47,13 +47,14 @@ const useStyles = makeStyles()((theme) => ({ alignItems: 'center', }, actionButton: { - fontSize: 12, + fontSize: 14, marginLeft: theme.spacing(1), padding: '8px 12px', fontWeight: 'bold', background: 'rgba(15, 20, 25, 1)', color: '#fff', - width: 'fit-content', + minWidth: 70, + borderRadius: '6px', }, address: { fontSize: 12, diff --git a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx index 090336bc83db..1013be331b4f 100644 --- a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx +++ b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx @@ -20,6 +20,7 @@ import { ECKeyIdentifier, Identifier, NextIDAction, NextIDPlatform } from '@mask import { useAsync } from 'react-use' import Services from '../../../extension/service' import { NextIDProof } from '@masknet/web3-providers' +import { useWallet } from '@masknet/plugin-infra' const useStyles = makeStyles()((theme) => ({ container: { @@ -84,8 +85,11 @@ export function Steps() { const { value: persona_ } = useAsync(async () => { return Services.Identity.queryPersona(currentIdentifier.unwrap()) }, []) + const [payload, setPayload] = useState() + const [signature, setSignature] = useState() + const wallet = useWallet() - if (!persona_ || !persona_.publicHexKey) return null + if (!persona_ || !persona_.publicHexKey || !wallet) return null const stepIconMap: any = { [SignSteps.Ready]: { @@ -120,15 +124,17 @@ export function Steps() { const payload = await NextIDProof.createPersonaPayload( persona_.publicHexKey as string, NextIDAction.Create, - persona_.nickname as string, + wallet.address, NextIDPlatform.Ethereum, 'default', ) if (!payload) throw new Error('Failed to create persona payload.') + setPayload(payload) const signResult = await Services.Identity.generateSignResult( currentIdentifier.val as any, payload.signPayload, ) + setSignature(signResult.signature.signature) if (!signResult) throw new Error('Failed to sign persona.') setStep(1) } catch (error) { @@ -136,7 +142,26 @@ export function Steps() { } } const walletSign = async () => { - console.log('wallet sign') + try { + const walletSig = await Services.Ethereum.personalSign(payload.signPayload, wallet.address) + console.log(walletSig, 'ggg') + if (!walletSig) throw new Error('Wallet sign failed') + console.log(payload, 'paylod') + await NextIDProof.bindProof( + payload.uuid, + persona_.publicHexKey as string, + NextIDAction.Create, + NextIDPlatform.Ethereum, + wallet.address, + payload.createdAt, + { + walletSignature: walletSig, + signature: signature, + }, + ) + } catch (error) { + console.error(error) + } setStep(2) } const onCancel = () => { From af85127bdc41d07ba47de6edff82792c219bbfe4 Mon Sep 17 00:00:00 2001 From: billy Date: Wed, 6 Apr 2022 17:46:50 +0800 Subject: [PATCH 07/14] fix: fix --- .../components/shared/VerifyWallet/Steps.tsx | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx index 1013be331b4f..10f735969bc4 100644 --- a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx +++ b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx @@ -16,7 +16,7 @@ import ActionButton from '../../../extension/options-page/DashboardComponents/Ac import { useNavigate } from 'react-router-dom' import { useValueRef } from '@masknet/shared-base-ui' import { currentPersonaIdentifier } from '../../../settings/settings' -import { ECKeyIdentifier, Identifier, NextIDAction, NextIDPlatform } from '@masknet/shared-base' +import { ECKeyIdentifier, Identifier, NextIDAction, NextIDPayload, NextIDPlatform } from '@masknet/shared-base' import { useAsync } from 'react-use' import Services from '../../../extension/service' import { NextIDProof } from '@masknet/web3-providers' @@ -79,19 +79,19 @@ enum SignSteps { export function Steps() { const { classes } = useStyles() - const [step, setStep] = useState(0) + const [step, setStep] = useState(SignSteps.Ready) const navigate = useNavigate() const currentIdentifier = Identifier.fromString(useValueRef(currentPersonaIdentifier), ECKeyIdentifier) const { value: persona_ } = useAsync(async () => { return Services.Identity.queryPersona(currentIdentifier.unwrap()) }, []) - const [payload, setPayload] = useState() - const [signature, setSignature] = useState() + const [payload, setPayload] = useState() + const [signature, setSignature] = useState() const wallet = useWallet() if (!persona_ || !persona_.publicHexKey || !wallet) return null - const stepIconMap: any = { + const stepIconMap = { [SignSteps.Ready]: { step1: step1ActiveIcon, divider: dividerDisableIcon, @@ -131,22 +131,21 @@ export function Steps() { if (!payload) throw new Error('Failed to create persona payload.') setPayload(payload) const signResult = await Services.Identity.generateSignResult( - currentIdentifier.val as any, + currentIdentifier.val as ECKeyIdentifier, payload.signPayload, ) setSignature(signResult.signature.signature) if (!signResult) throw new Error('Failed to sign persona.') - setStep(1) + setStep(SignSteps.Step1Done) } catch (error) { console.error(error) } } const walletSign = async () => { + if (!payload) throw new Error('paylod error') try { const walletSig = await Services.Ethereum.personalSign(payload.signPayload, wallet.address) - console.log(walletSig, 'ggg') if (!walletSig) throw new Error('Wallet sign failed') - console.log(payload, 'paylod') await NextIDProof.bindProof( payload.uuid, persona_.publicHexKey as string, @@ -159,10 +158,10 @@ export function Steps() { signature: signature, }, ) + setStep(SignSteps.Step2Done) } catch (error) { console.error(error) } - setStep(2) } const onCancel = () => { navigate(-1) @@ -174,7 +173,7 @@ export function Steps() {
- +
From 445c302e5b7c19efc0592600cf66f4e1e616d01f Mon Sep 17 00:00:00 2001 From: billy Date: Wed, 6 Apr 2022 18:45:22 +0800 Subject: [PATCH 08/14] feat: connect wallet page --- packages/icons/brands/Blocto.tsx | 49 +++++++++++++++ packages/icons/brands/index.ts | 1 + .../popups/components/PopupFrame/index.tsx | 10 +++- .../pages/Wallet/ConnectWallet/constants.ts | 10 ++++ .../pages/Wallet/ConnectWallet/index.tsx | 60 +++++++++++++++++++ .../extension/popups/pages/Wallet/index.tsx | 2 + .../shared-base/src/Routes/PopupRoutes.ts | 1 + 7 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 packages/icons/brands/Blocto.tsx create mode 100644 packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/constants.ts create mode 100644 packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/index.tsx diff --git a/packages/icons/brands/Blocto.tsx b/packages/icons/brands/Blocto.tsx new file mode 100644 index 000000000000..475355bf36dd --- /dev/null +++ b/packages/icons/brands/Blocto.tsx @@ -0,0 +1,49 @@ +import { createIcon } from '../utils' +import type { SvgIcon } from '@mui/material' + +export const BloctoIcon: typeof SvgIcon = createIcon( + 'Blocto', + + + + + + + + + + + + + + + + + + + + + , + '0 0 43 50', +) diff --git a/packages/icons/brands/index.ts b/packages/icons/brands/index.ts index 107479bd226b..de5508807f7f 100644 --- a/packages/icons/brands/index.ts +++ b/packages/icons/brands/index.ts @@ -12,3 +12,4 @@ export * from './MaskGrey' export * from './Discord' export * from './MaskBanner' export * from './MaskPlaceholder' +export * from './Blocto' diff --git a/packages/mask/src/extension/popups/components/PopupFrame/index.tsx b/packages/mask/src/extension/popups/components/PopupFrame/index.tsx index 21881ee4d917..ebbf78575de7 100644 --- a/packages/mask/src/extension/popups/components/PopupFrame/index.tsx +++ b/packages/mask/src/extension/popups/components/PopupFrame/index.tsx @@ -100,7 +100,15 @@ export const PopupFrame = memo((props) => { return ( <> - + {excludePath || history.length === 1 ? ( diff --git a/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/constants.ts b/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/constants.ts new file mode 100644 index 000000000000..5cdaaaac5020 --- /dev/null +++ b/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/constants.ts @@ -0,0 +1,10 @@ +import { MaskWalletIcon, WalletConnectIcon, MetaMaskIcon, BloctoIcon } from '@masknet/icons' + +const supportedWallets = [ + { title: 'MetaMask', icon: MetaMaskIcon }, + { title: 'Mask', icon: MaskWalletIcon }, + { title: 'WalletConnetc', icon: WalletConnectIcon }, + { title: 'Blocto', icon: BloctoIcon }, +] + +export { supportedWallets } diff --git a/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/index.tsx new file mode 100644 index 000000000000..b13084505553 --- /dev/null +++ b/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/index.tsx @@ -0,0 +1,60 @@ +import { makeStyles } from '@masknet/theme' +import { Typography } from '@mui/material' +import { memo } from 'react' +import { supportedWallets } from './constants' +import { useNavigate } from 'react-router-dom' +import { PopupRoutes } from '@masknet/shared-base' + +const useStyles = makeStyles()((theme) => ({ + container: { + width: '100%', + display: 'flex', + flexWrap: 'wrap', + columnGap: 12, + rowGap: 16, + padding: '16px', + boxSizing: 'border-box', + }, + walletItem: { + cursor: 'pointer', + background: '#fff', + width: 'calc( 50% - 6px )', + borderRadius: '8px', + display: 'flex', + flexDirection: 'column', + alignItems: 'center', + gap: 4, + padding: '12px 0', + boxSizing: 'content-box', + fontSize: 12, + fontWeight: 700, + color: theme.palette.text.secondary, + fontFamily: 'Helvetica', + height: 'fit-content', + }, + walletIcon: { + width: '4rem', + height: '4rem', + }, +})) +const ConenctWalletPage = memo(() => { + const { classes } = useStyles() + const navigate = useNavigate() + const clickItem = () => { + navigate(PopupRoutes.VerifyWallet) + } + return ( +
+ {supportedWallets.map((item, idx) => { + return ( +
+ + {item.title} +
+ ) + })} +
+ ) +}) + +export default ConenctWalletPage diff --git a/packages/mask/src/extension/popups/pages/Wallet/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/index.tsx index a017418784e2..d9b2a2655ada 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/index.tsx @@ -33,6 +33,7 @@ const WalletRecovery = lazy(() => import('./WalletRecovery')) const LegacyWalletRecovery = lazy(() => import('./LegacyWalletRecovery')) const ReplaceTransaction = lazy(() => import('./ReplaceTransaction')) const VerifyWallet = lazy(() => import('./VerifyWallet')) +const ConnectWallet = lazy(() => import('./ConnectWallet')) const r = relativeRouteOf(PopupRoutes.Wallet) export default function Wallet() { @@ -118,6 +119,7 @@ export default function Wallet() { } /> } /> } /> + } /> )} diff --git a/packages/shared-base/src/Routes/PopupRoutes.ts b/packages/shared-base/src/Routes/PopupRoutes.ts index 174b37b7f0d0..2465d1e722b7 100644 --- a/packages/shared-base/src/Routes/PopupRoutes.ts +++ b/packages/shared-base/src/Routes/PopupRoutes.ts @@ -30,5 +30,6 @@ export enum PopupRoutes { ThirdPartyRequestPermission = '/3rd-request-permission', SignRequest = '/sign-request', Swap = '/swap', + ConnectWallet = '/wallet/connect', VerifyWallet = '/wallet/verify', } From 72a0e144ca6bd6ec7e45eaa2b2f1e1c39cc5697d Mon Sep 17 00:00:00 2001 From: billy Date: Wed, 6 Apr 2022 18:46:01 +0800 Subject: [PATCH 09/14] fix: typo --- .../extension/popups/pages/Wallet/ConnectWallet/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/constants.ts b/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/constants.ts index 5cdaaaac5020..c3d21d9e53ec 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/constants.ts +++ b/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/constants.ts @@ -3,7 +3,7 @@ import { MaskWalletIcon, WalletConnectIcon, MetaMaskIcon, BloctoIcon } from '@ma const supportedWallets = [ { title: 'MetaMask', icon: MetaMaskIcon }, { title: 'Mask', icon: MaskWalletIcon }, - { title: 'WalletConnetc', icon: WalletConnectIcon }, + { title: 'WalletConnect', icon: WalletConnectIcon }, { title: 'Blocto', icon: BloctoIcon }, ] From 86672c2bdb729a30ec6e66f31cea7cb9c6c05e55 Mon Sep 17 00:00:00 2001 From: billy Date: Wed, 6 Apr 2022 18:50:02 +0800 Subject: [PATCH 10/14] fix: typo --- packages/mask/src/components/shared/VerifyWallet/Steps.tsx | 6 +++--- .../extension/popups/pages/Wallet/ConnectWallet/index.tsx | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx index 10f735969bc4..4f624dc85913 100644 --- a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx +++ b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx @@ -111,7 +111,7 @@ export function Steps() { const onConfirm = () => { if (step === SignSteps.Ready) { - personaSlientSign() + personaSilentSign() } else if (step === SignSteps.Step1Done) { walletSign() } else { @@ -119,7 +119,7 @@ export function Steps() { } } - const personaSlientSign = async () => { + const personaSilentSign = async () => { try { const payload = await NextIDProof.createPersonaPayload( persona_.publicHexKey as string, @@ -142,7 +142,7 @@ export function Steps() { } } const walletSign = async () => { - if (!payload) throw new Error('paylod error') + if (!payload) throw new Error('payload error') try { const walletSig = await Services.Ethereum.personalSign(payload.signPayload, wallet.address) if (!walletSig) throw new Error('Wallet sign failed') diff --git a/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/index.tsx index b13084505553..f7bc06671ee2 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/index.tsx @@ -37,7 +37,7 @@ const useStyles = makeStyles()((theme) => ({ height: '4rem', }, })) -const ConenctWalletPage = memo(() => { +const ConnectWalletPage = memo(() => { const { classes } = useStyles() const navigate = useNavigate() const clickItem = () => { @@ -57,4 +57,4 @@ const ConenctWalletPage = memo(() => { ) }) -export default ConenctWalletPage +export default ConnectWalletPage From 6ba8c11a8b279154bc34d7501b991f4d16fdafee Mon Sep 17 00:00:00 2001 From: billy Date: Tue, 12 Apr 2022 16:09:27 +0800 Subject: [PATCH 11/14] fix: comment --- .../shared/VerifyWallet/constants.ts | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/packages/mask/src/components/shared/VerifyWallet/constants.ts b/packages/mask/src/components/shared/VerifyWallet/constants.ts index f16ea4657f0e..fe083043d000 100644 --- a/packages/mask/src/components/shared/VerifyWallet/constants.ts +++ b/packages/mask/src/components/shared/VerifyWallet/constants.ts @@ -1,17 +1,7 @@ -const step1ActiveIcon = new URL('../assets/stepAssets/step1Active.png', import.meta.url) -const step2DisableIcon = new URL('../assets/stepAssets/step2Disable.png', import.meta.url) -const step2ActiveIcon = new URL('../assets/stepAssets/step2Active.png', import.meta.url) -const stepSuccessIcon = new URL('../assets/stepAssets/stepSuccess.png', import.meta.url) -const dividerDisableIcon = new URL('../assets/stepAssets/dividerDisable.png', import.meta.url) -const dividerActiveIcon = new URL('../assets/stepAssets/dividerActive.png', import.meta.url) -const dividerSuccessIcon = new URL('../assets/stepAssets/dividerDone.png', import.meta.url) - -export { - step1ActiveIcon, - step2DisableIcon, - step2ActiveIcon, - stepSuccessIcon, - dividerDisableIcon, - dividerActiveIcon, - dividerSuccessIcon, -} +export const step1ActiveIcon = new URL('../assets/stepAssets/step1Active.png', import.meta.url) +export const step2DisableIcon = new URL('../assets/stepAssets/step2Disable.png', import.meta.url) +export const step2ActiveIcon = new URL('../assets/stepAssets/step2Active.png', import.meta.url) +export const stepSuccessIcon = new URL('../assets/stepAssets/stepSuccess.png', import.meta.url) +export const dividerDisableIcon = new URL('../assets/stepAssets/dividerDisable.png', import.meta.url) +export const dividerActiveIcon = new URL('../assets/stepAssets/dividerActive.png', import.meta.url) +export const dividerSuccessIcon = new URL('../assets/stepAssets/dividerDone.png', import.meta.url) From eca2ce7d700b4bcabb16beb4660ef9f1a97f4514 Mon Sep 17 00:00:00 2001 From: billy Date: Tue, 12 Apr 2022 16:36:47 +0800 Subject: [PATCH 12/14] refactor: temp --- packages/mask/src/components/shared/VerifyWallet/Steps.tsx | 2 +- packages/mask/src/extension/popups/pages/Personas/index.tsx | 2 ++ .../src/extension/popups/pages/Wallet/VerifyWallet/index.tsx | 3 +++ packages/mask/src/extension/popups/pages/Wallet/index.tsx | 1 - 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx index 4f624dc85913..87ffc7fd300a 100644 --- a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx +++ b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx @@ -84,7 +84,7 @@ export function Steps() { const currentIdentifier = Identifier.fromString(useValueRef(currentPersonaIdentifier), ECKeyIdentifier) const { value: persona_ } = useAsync(async () => { return Services.Identity.queryPersona(currentIdentifier.unwrap()) - }, []) + }, [currentIdentifier]) const [payload, setPayload] = useState() const [signature, setSignature] = useState() const wallet = useWallet() diff --git a/packages/mask/src/extension/popups/pages/Personas/index.tsx b/packages/mask/src/extension/popups/pages/Personas/index.tsx index 8e1a5ead5ca1..62ea349e301d 100644 --- a/packages/mask/src/extension/popups/pages/Personas/index.tsx +++ b/packages/mask/src/extension/popups/pages/Personas/index.tsx @@ -4,6 +4,7 @@ import { LoadingPlaceholder } from '../../components/LoadingPlaceholder' import { PersonaContext } from './hooks/usePersonaContext' import { PopupRoutes, relativeRouteOf } from '@masknet/shared-base' import { Route, Routes } from 'react-router-dom' +import VerifyWallet from '../Wallet/VerifyWallet' const Home = lazy(() => import('./Home')) const Logout = lazy(() => import('./Logout')) @@ -19,6 +20,7 @@ const Persona = memo(() => { } /> } /> } /> + } /> } /> diff --git a/packages/mask/src/extension/popups/pages/Wallet/VerifyWallet/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/VerifyWallet/index.tsx index d50278b5c66c..aaa609e38824 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/VerifyWallet/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/VerifyWallet/index.tsx @@ -1,6 +1,7 @@ import { makeStyles } from '@masknet/theme' import { memo } from 'react' import { Steps } from '../../../../../components/shared/VerifyWallet/Steps' +import { PersonaContext } from '../../Personas/hooks/usePersonaContext' const useStyles = makeStyles()((theme) => ({ container: { @@ -13,6 +14,8 @@ const useStyles = makeStyles()((theme) => ({ })) const VerifyWallet = memo(() => { const { classes } = useStyles() + const { currentPersona } = PersonaContext.useContainer() + console.log(currentPersona, 'ggg') return (
diff --git a/packages/mask/src/extension/popups/pages/Wallet/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/index.tsx index d9b2a2655ada..5b41958a955e 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/index.tsx @@ -118,7 +118,6 @@ export default function Wallet() { } /> } /> } /> - } /> } /> )} From d12cf9e5a3043c194f1901380c267a3e0c77ab70 Mon Sep 17 00:00:00 2001 From: billy Date: Tue, 12 Apr 2022 17:10:22 +0800 Subject: [PATCH 13/14] refactor: refact steps compo --- .../components/shared/VerifyWallet/Steps.tsx | 85 ++++--------------- .../extension/popups/pages/Personas/index.tsx | 2 +- .../pages/Wallet/VerifyWallet/index.tsx | 60 ++++++++++++- .../shared-base/src/Routes/PopupRoutes.ts | 2 +- 4 files changed, 73 insertions(+), 76 deletions(-) diff --git a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx index 87ffc7fd300a..566a677ebd47 100644 --- a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx +++ b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx @@ -1,5 +1,4 @@ import { makeStyles } from '@masknet/theme' -import { useState } from 'react' import { CurrentWalletBox } from './CurrentWalletBox' import { step1ActiveIcon, @@ -14,13 +13,6 @@ import { ImageIcon } from '@masknet/shared' import { Typography } from '@mui/material' import ActionButton from '../../../extension/options-page/DashboardComponents/ActionButton' import { useNavigate } from 'react-router-dom' -import { useValueRef } from '@masknet/shared-base-ui' -import { currentPersonaIdentifier } from '../../../settings/settings' -import { ECKeyIdentifier, Identifier, NextIDAction, NextIDPayload, NextIDPlatform } from '@masknet/shared-base' -import { useAsync } from 'react-use' -import Services from '../../../extension/service' -import { NextIDProof } from '@masknet/web3-providers' -import { useWallet } from '@masknet/plugin-infra' const useStyles = makeStyles()((theme) => ({ container: { @@ -71,25 +63,22 @@ const useStyles = makeStyles()((theme) => ({ }, })) -enum SignSteps { +export enum SignSteps { Ready = 0, - Step1Done = 1, - Step2Done = 2, + FirstStepDone = 1, + SecondStepDone = 2, } -export function Steps() { +interface StepsProps { + step: SignSteps + personaSign: () => void + walletSign: () => void +} + +export function Steps(props: StepsProps) { const { classes } = useStyles() - const [step, setStep] = useState(SignSteps.Ready) const navigate = useNavigate() - const currentIdentifier = Identifier.fromString(useValueRef(currentPersonaIdentifier), ECKeyIdentifier) - const { value: persona_ } = useAsync(async () => { - return Services.Identity.queryPersona(currentIdentifier.unwrap()) - }, [currentIdentifier]) - const [payload, setPayload] = useState() - const [signature, setSignature] = useState() - const wallet = useWallet() - - if (!persona_ || !persona_.publicHexKey || !wallet) return null + const { step, personaSign, walletSign } = props const stepIconMap = { [SignSteps.Ready]: { @@ -97,12 +86,12 @@ export function Steps() { divider: dividerDisableIcon, step2: step2DisableIcon, }, - [SignSteps.Step1Done]: { + [SignSteps.FirstStepDone]: { step1: stepSuccessIcon, divider: dividerActiveIcon, step2: step2ActiveIcon, }, - [SignSteps.Step2Done]: { + [SignSteps.SecondStepDone]: { step1: stepSuccessIcon, divider: dividerSuccessIcon, step2: stepSuccessIcon, @@ -111,58 +100,14 @@ export function Steps() { const onConfirm = () => { if (step === SignSteps.Ready) { - personaSilentSign() - } else if (step === SignSteps.Step1Done) { + personaSign() + } else if (step === SignSteps.FirstStepDone) { walletSign() } else { navigate(-1) } } - const personaSilentSign = async () => { - try { - const payload = await NextIDProof.createPersonaPayload( - persona_.publicHexKey as string, - NextIDAction.Create, - wallet.address, - NextIDPlatform.Ethereum, - 'default', - ) - if (!payload) throw new Error('Failed to create persona payload.') - setPayload(payload) - const signResult = await Services.Identity.generateSignResult( - currentIdentifier.val as ECKeyIdentifier, - payload.signPayload, - ) - setSignature(signResult.signature.signature) - if (!signResult) throw new Error('Failed to sign persona.') - setStep(SignSteps.Step1Done) - } catch (error) { - console.error(error) - } - } - const walletSign = async () => { - if (!payload) throw new Error('payload error') - try { - const walletSig = await Services.Ethereum.personalSign(payload.signPayload, wallet.address) - if (!walletSig) throw new Error('Wallet sign failed') - await NextIDProof.bindProof( - payload.uuid, - persona_.publicHexKey as string, - NextIDAction.Create, - NextIDPlatform.Ethereum, - wallet.address, - payload.createdAt, - { - walletSignature: walletSig, - signature: signature, - }, - ) - setStep(SignSteps.Step2Done) - } catch (error) { - console.error(error) - } - } const onCancel = () => { navigate(-1) } diff --git a/packages/mask/src/extension/popups/pages/Personas/index.tsx b/packages/mask/src/extension/popups/pages/Personas/index.tsx index 62ea349e301d..9f6add97dff2 100644 --- a/packages/mask/src/extension/popups/pages/Personas/index.tsx +++ b/packages/mask/src/extension/popups/pages/Personas/index.tsx @@ -4,12 +4,12 @@ import { LoadingPlaceholder } from '../../components/LoadingPlaceholder' import { PersonaContext } from './hooks/usePersonaContext' import { PopupRoutes, relativeRouteOf } from '@masknet/shared-base' import { Route, Routes } from 'react-router-dom' -import VerifyWallet from '../Wallet/VerifyWallet' const Home = lazy(() => import('./Home')) const Logout = lazy(() => import('./Logout')) const PersonaRename = lazy(() => import('./Rename')) const PersonaSignRequest = lazy(() => import('./PersonaSignRequest')) +const VerifyWallet = lazy(() => import('../Wallet/VerifyWallet')) const r = relativeRouteOf(PopupRoutes.Personas) const Persona = memo(() => { diff --git a/packages/mask/src/extension/popups/pages/Wallet/VerifyWallet/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/VerifyWallet/index.tsx index aaa609e38824..e29fab9c4ae8 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/VerifyWallet/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/VerifyWallet/index.tsx @@ -1,6 +1,10 @@ +import { useWallet } from '@masknet/plugin-infra' +import { NextIDAction, NextIDPayload, NextIDPlatform } from '@masknet/shared-base' import { makeStyles } from '@masknet/theme' -import { memo } from 'react' -import { Steps } from '../../../../../components/shared/VerifyWallet/Steps' +import { NextIDProof } from '@masknet/web3-providers' +import { memo, useState } from 'react' +import { SignSteps, Steps } from '../../../../../components/shared/VerifyWallet/Steps' +import Services from '../../../../service' import { PersonaContext } from '../../Personas/hooks/usePersonaContext' const useStyles = makeStyles()((theme) => ({ @@ -15,11 +19,59 @@ const useStyles = makeStyles()((theme) => ({ const VerifyWallet = memo(() => { const { classes } = useStyles() const { currentPersona } = PersonaContext.useContainer() - console.log(currentPersona, 'ggg') + const wallet = useWallet() + const [step, setStep] = useState(SignSteps.Ready) + const [signature, setSignature] = useState() + const [payload, setPayload] = useState() + if (!currentPersona || !wallet) return null + const personaSilentSign = async () => { + try { + const payload = await NextIDProof.createPersonaPayload( + currentPersona.publicHexKey as string, + NextIDAction.Create, + wallet.address, + NextIDPlatform.Ethereum, + 'default', + ) + if (!payload) throw new Error('Failed to create persona payload.') + setPayload(payload) + const signResult = await Services.Identity.generateSignResult( + currentPersona.identifier, + payload.signPayload, + ) + setSignature(signResult.signature.signature) + if (!signResult) throw new Error('Failed to sign persona.') + setStep(SignSteps.FirstStepDone) + } catch (error) { + console.error(error) + } + } + const walletSign = async () => { + if (!payload) throw new Error('payload error') + try { + const walletSig = await Services.Ethereum.personalSign(payload.signPayload, wallet.address) + if (!walletSig) throw new Error('Wallet sign failed') + await NextIDProof.bindProof( + payload.uuid, + currentPersona.publicHexKey as string, + NextIDAction.Create, + NextIDPlatform.Ethereum, + wallet.address, + payload.createdAt, + { + walletSignature: walletSig, + signature: signature, + }, + ) + setStep(SignSteps.SecondStepDone) + } catch (error) { + console.error(error) + } + } return (
- +
) }) diff --git a/packages/shared-base/src/Routes/PopupRoutes.ts b/packages/shared-base/src/Routes/PopupRoutes.ts index 2465d1e722b7..963cb8f11fd6 100644 --- a/packages/shared-base/src/Routes/PopupRoutes.ts +++ b/packages/shared-base/src/Routes/PopupRoutes.ts @@ -31,5 +31,5 @@ export enum PopupRoutes { SignRequest = '/sign-request', Swap = '/swap', ConnectWallet = '/wallet/connect', - VerifyWallet = '/wallet/verify', + VerifyWallet = '/personas/verify', } From e6091e694ed9a3669ce00cddb07d041186fe7f9a Mon Sep 17 00:00:00 2001 From: billy Date: Tue, 12 Apr 2022 17:26:08 +0800 Subject: [PATCH 14/14] fix: fix --- .../src/extension/popups/assets/blocto.svg | 21 ++++++++ .../mask/src/extension/popups/assets/mask.svg | 20 ++++++++ .../src/extension/popups/assets/metamask.svg | 48 +++++++++++++++++++ .../extension/popups/assets/walletconnect.svg | 20 ++++++++ .../pages/Wallet/ConnectWallet/constants.ts | 10 ++-- .../pages/Wallet/ConnectWallet/index.tsx | 6 +-- 6 files changed, 116 insertions(+), 9 deletions(-) create mode 100644 packages/mask/src/extension/popups/assets/blocto.svg create mode 100644 packages/mask/src/extension/popups/assets/mask.svg create mode 100644 packages/mask/src/extension/popups/assets/metamask.svg create mode 100644 packages/mask/src/extension/popups/assets/walletconnect.svg diff --git a/packages/mask/src/extension/popups/assets/blocto.svg b/packages/mask/src/extension/popups/assets/blocto.svg new file mode 100644 index 000000000000..646d48924816 --- /dev/null +++ b/packages/mask/src/extension/popups/assets/blocto.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/mask/src/extension/popups/assets/mask.svg b/packages/mask/src/extension/popups/assets/mask.svg new file mode 100644 index 000000000000..3666da4207ed --- /dev/null +++ b/packages/mask/src/extension/popups/assets/mask.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/packages/mask/src/extension/popups/assets/metamask.svg b/packages/mask/src/extension/popups/assets/metamask.svg new file mode 100644 index 000000000000..2a8c95af16a7 --- /dev/null +++ b/packages/mask/src/extension/popups/assets/metamask.svg @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/mask/src/extension/popups/assets/walletconnect.svg b/packages/mask/src/extension/popups/assets/walletconnect.svg new file mode 100644 index 000000000000..764df3dbd43b --- /dev/null +++ b/packages/mask/src/extension/popups/assets/walletconnect.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/constants.ts b/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/constants.ts index c3d21d9e53ec..ed1b39f91e7f 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/constants.ts +++ b/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/constants.ts @@ -1,10 +1,8 @@ -import { MaskWalletIcon, WalletConnectIcon, MetaMaskIcon, BloctoIcon } from '@masknet/icons' - const supportedWallets = [ - { title: 'MetaMask', icon: MetaMaskIcon }, - { title: 'Mask', icon: MaskWalletIcon }, - { title: 'WalletConnect', icon: WalletConnectIcon }, - { title: 'Blocto', icon: BloctoIcon }, + { title: 'MetaMask', icon: new URL('../../../assets/metamask.svg', import.meta.url).toString() }, + { title: 'Mask', icon: new URL('../../../assets/mask.svg', import.meta.url).toString() }, + { title: 'WalletConnect', icon: new URL('../../../assets/walletconnect.svg', import.meta.url).toString() }, + { title: 'Blocto', icon: new URL('../../../assets/blocto.svg', import.meta.url).toString() }, ] export { supportedWallets } diff --git a/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/index.tsx index f7bc06671ee2..b9f1e4ebe884 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/ConnectWallet/index.tsx @@ -33,8 +33,8 @@ const useStyles = makeStyles()((theme) => ({ height: 'fit-content', }, walletIcon: { - width: '4rem', - height: '4rem', + width: '5rem', + height: '5rem', }, })) const ConnectWalletPage = memo(() => { @@ -48,7 +48,7 @@ const ConnectWalletPage = memo(() => { {supportedWallets.map((item, idx) => { return (
- + {item.title}
)