diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..ec2a4d1ab --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,51 @@ +name: Release + +on: + push: + branches: + - pre-release + - master + - develop + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '18' + + - name: Install dependencies + run: yarn install + + - name: Build project for Chrome + run: yarn run build:chrome + + - name: List files in build directory + run: ls -l ./build + + - name: Create a draft release + id: create_release + uses: actions/create-release@v1 + with: + tag_name: v${{ github.event.repository.name }}-${{ github.ref_name }}-release + release_name: Release ${{ github.event.repository.name }} for ${{ github.ref_name }} + draft: true + prerelease: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Upload zip to release + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./build/chrome.zip + asset_name: chrome.zip + asset_content_type: application/zip + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/source/assets/images/faucet-error.svg b/source/assets/images/faucet-error.svg deleted file mode 100644 index ffe9d6b33..000000000 --- a/source/assets/images/faucet-error.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/source/assets/images/faucet-loading.svg b/source/assets/images/faucet-loading.svg deleted file mode 100644 index 179d6689d..000000000 --- a/source/assets/images/faucet-loading.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/source/assets/images/faucet-success.svg b/source/assets/images/faucet-success.svg deleted file mode 100644 index 5090ae89f..000000000 --- a/source/assets/images/faucet-success.svg +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/source/assets/images/faucetmodal.png b/source/assets/images/faucetmodal.png deleted file mode 100644 index 7f15444cf..000000000 Binary files a/source/assets/images/faucetmodal.png and /dev/null differ diff --git a/source/assets/locales/en.json b/source/assets/locales/en.json index 3754a2f7f..34280f1df 100644 --- a/source/assets/locales/en.json +++ b/source/assets/locales/en.json @@ -521,20 +521,5 @@ "walletSeedPhrasePage": { "keepSeedPhrase": "Keep your seed phrase secret!", "anyoneWithThisInfo": "Anyone with this information is able to steal your funds." - }, - "faucet": { - "grabTextOne":"Grab ${{token}} with our faucet!", - "grabTextTwo":"Grab ${{token}} with our faucet on the {{rpcName}}!", - "pleaseWait":"Please wait while we work our magic...", - "doNotClose":"Do not close the wallet.", - "ERROR":"ERROR!", - "CONGRATULATIONS":"CONGRATULATIONS!", - "someHasJust":"Some {{tokenSymbol}} has just been sent to your {{networkName}} wallet.", - "transactionHash":"Transaction hash", - "requestNow": "Request Now", - "Close": "Close", - "tryAgain": "Try again", - "withOurFaucet": "Grab {{token}} with our faucet to begin experiencing the {{networkName}} network!", - "youCanGet": "You can get {{quantity}} {{token}} per wallet address every 24h." } } \ No newline at end of file diff --git a/source/assets/locales/es.json b/source/assets/locales/es.json index f66c0e696..5209220b8 100644 --- a/source/assets/locales/es.json +++ b/source/assets/locales/es.json @@ -521,20 +521,5 @@ "walletSeedPhrasePage": { "keepSeedPhrase": "¡Mantén en secreto tu seed frase!", "anyoneWithThisInfo": "Cualquier persona con esta información puede robar tus fondos." - }, - "faucet": { - "grabTextOne": "¡Obtén ${{token}} con nuestra llave!", - "grabTextTwo": "¡Obtén ${{token}} con nuestra llave en el {{rpcName}}!", - "pleaseWait": "Por favor, espere mientras hacemos nuestra magia...", - "doNotClose": "No cierres la billetera.", - "ERROR": "¡ERROR!", - "CONGRATULATIONS": "¡FELICITACIONES!", - "someHasJust": "Algo de {{tokenSymbol}} acaba de ser enviado a tu billetera de {{networkName}}.", - "transactionHash": "Hash de transacción", - "requestNow": "Solicitar ahora", - "Close": "Cerrar", - "tryAgain": "Intentar de nuevo", - "withOurFaucet": "¡Obtén {{token}} con nuestra llave para comenzar a experimentar la red {{networkName}}!", - "youCanGet": "Puedes obtener {{quantity}} {{token}} por dirección de billetera cada 24 horas." } } diff --git a/source/assets/locales/pt-br.json b/source/assets/locales/pt-br.json index 9c654d463..916982ccf 100644 --- a/source/assets/locales/pt-br.json +++ b/source/assets/locales/pt-br.json @@ -393,20 +393,5 @@ "transactionDetails": "DETALLES DE LA TRANSACCIÓN", "importWallet": "Importar billetera", "congratulations": "PARABÉNS!" - }, - "faucet": { - "grabTextOne": "Pegue ${{token}} com nossa torneira!", - "grabTextTwo": "Pegue ${{token}} com nossa torneira no {{rpcName}}!", - "pleaseWait": "Por favor, aguarde enquanto trabalhamos nossa mágica...", - "doNotClose": "Não feche a carteira.", - "ERROR": "ERRO!", - "CONGRATULATIONS": "PARABÉNS!", - "someHasJust": "Algum {{tokenSymbol}} acabou de ser enviado para sua carteira {{networkName}}.", - "transactionHash": "Hash da transação", - "requestNow": "Solicitar agora", - "Close": "Fechar", - "tryAgain": "Tentar novamente", - "withOurFaucet": "Pegue {{token}} com nossa torneira para começar a experimentar a rede {{networkName}}!", - "youCanGet": "Você pode obter {{quantity}} {{token}} por endereço de carteira a cada 24 horas." - } + } } diff --git a/source/components/Header/Header.tsx b/source/components/Header/Header.tsx index 6c2eb4f35..85897b776 100755 --- a/source/components/Header/Header.tsx +++ b/source/components/Header/Header.tsx @@ -70,7 +70,7 @@ export const Header: React.FC = ({ accountHeader = false }) => { return (
-
+
{ return (
= ( return ( {(menuprops) => ( <> @@ -251,13 +250,11 @@ export const NetworkMenu: React.FC = ( activeNetworkValidator( currentNetwork ) && ( -
- -
+ )} ) @@ -307,7 +304,7 @@ export const NetworkMenu: React.FC = ( : index === arr.length - 1 ? 'rounded-bl-lg rounded-br-lg' : 'border-b border-dashed border-gray-600' - } flex relative flex-row items-center justify-start mx-auto p-2 max-w-95 text-white text-sm font-medium active:bg-opacity-40 bg-brand-blue500 focus:outline-none cursor-pointer transform transition duration-300`} + } flex flex-row items-center justify-start mx-auto p-2 max-w-95 text-white text-sm font-medium active:bg-opacity-40 bg-brand-blue500 focus:outline-none cursor-pointer transform transition duration-300`} onClick={() => handleChangeNetwork( currentNetwork, @@ -318,26 +315,15 @@ export const NetworkMenu: React.FC = ( {currentNetwork.label} -
- {!isBitcoinBased && - activeNetworkValidator(currentNetwork) && ( - - )} - {Object.values(FaucetChainIds).includes( - currentNetwork.chainId - ) && ( -
-
-

- Faucet -

-
+ + {!isBitcoinBased && + activeNetworkValidator(currentNetwork) && ( + )} -
))} diff --git a/source/components/Modal/FaucetAccessModal.tsx b/source/components/Modal/FaucetAccessModal.tsx deleted file mode 100644 index fcc8a4b28..000000000 --- a/source/components/Modal/FaucetAccessModal.tsx +++ /dev/null @@ -1,31 +0,0 @@ -import React from 'react'; -import { useTranslation } from 'react-i18next'; - -import rolluxLogo from 'assets/images/rolluxChain.png'; -import sysLogo from 'assets/images/sysChain.svg'; -import { useUtils } from 'hooks/useUtils'; -import { useHandleNetworkTokenNames } from 'pages/Faucet/Utils/NetworksInfos'; - -export const FaucetAccessModal = () => { - const { navigate } = useUtils(); - const { t } = useTranslation(); - const { tokenSymbol, networkName } = useHandleNetworkTokenNames(); - - return ( -
navigate('/faucet')} - className="cursor-pointer z-[88] py-2 justify-center absolute left-[4.3%] top-[8rem] w-[364px] flex items-center rounded-b-[8px] bg-brand-blue400 opacity-100 hover:opacity-55" - > -
- - -
-

- {t('faucet.grabTextTwo', { - token: tokenSymbol, - rpcName: networkName, - })} -

-
- ); -}; diff --git a/source/components/Modal/FaucetModal.tsx b/source/components/Modal/FaucetModal.tsx deleted file mode 100644 index f4b1d51fa..000000000 --- a/source/components/Modal/FaucetModal.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import React from 'react'; -import { useTranslation } from 'react-i18next'; - -import { Icon } from '..'; -import image from 'assets/images/faucetmodal.png'; -import rolluxLogo from 'assets/images/rolluxChain.png'; -import sysLogo from 'assets/images/sysChain.svg'; -import { useHandleNetworkTokenNames } from 'pages/Faucet/Utils/NetworksInfos'; - -type FaucetFirstAccessModalProps = { - handleOnClose: () => void; -}; - -export const FaucetFirstAccessModal = ({ - handleOnClose, -}: FaucetFirstAccessModalProps) => { - const { t } = useTranslation(); - const { tokenSymbol } = useHandleNetworkTokenNames(); - - return ( -
-
-
- - -
-
-

- {t('faucet.grabTextOne', { - token: tokenSymbol, - })} -

-
-
- - - - -
- ); -}; diff --git a/source/pages/Faucet/Components/FaucetApiFeedback.tsx b/source/pages/Faucet/Components/FaucetApiFeedback.tsx deleted file mode 100644 index 379586049..000000000 --- a/source/pages/Faucet/Components/FaucetApiFeedback.tsx +++ /dev/null @@ -1,55 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import { useTranslation } from 'react-i18next'; - -import { StatusModal } from 'components/Modal/StatusModal'; - -type FaucetApiFeedbackProps = { - apiResponse: string; - apiTitle: string; - status?: string; -}; -export const FaucetApiFeedback: React.FC = ({ - apiTitle, - apiResponse, - status, -}) => { - const [isCopied, setIsCopied] = useState(false); - const { t } = useTranslation(); - - const handleCopyToClipboard = () => { - setIsCopied(!isCopied); - navigator.clipboard.writeText(apiResponse); - }; - - useEffect(() => { - const timeoutDuration = 1000; - const timeoutId = setTimeout(() => { - setIsCopied(false); - }, timeoutDuration); - - return () => clearTimeout(timeoutId); - }, [isCopied]); - - return ( - <> - -
-

{apiTitle}

-

(status ? handleCopyToClipboard() : null)} - className="text-white text-sm underline overflow-hidden" - style={{ - cursor: status ? 'pointer' : 'default', - }} - > - {apiResponse} -

-
- - ); -}; diff --git a/source/pages/Faucet/Components/FaucetCardAccount.tsx b/source/pages/Faucet/Components/FaucetCardAccount.tsx deleted file mode 100644 index 4d1e6f66b..000000000 --- a/source/pages/Faucet/Components/FaucetCardAccount.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import { toSvg } from 'jdenticon'; -import React, { useEffect } from 'react'; - -type FaucetCardAccountProps = { - accountAddress: string; - accountImg: string; - accountName: string; -}; -export const FaucetCardAccount: React.FC = ({ - accountName, - accountAddress, - accountImg, -}) => { - useEffect(() => { - const placeholder = document.querySelector('.add-identicon'); - if (!placeholder) return; - - placeholder.innerHTML = toSvg(accountImg, 50, { - backColor: '#07152B', - padding: 1, - }); - }, [accountImg]); - return ( -
-
-
-

{accountName}

-

{accountAddress}

-
-
- ); -}; diff --git a/source/pages/Faucet/Components/FaucetFeedback.tsx b/source/pages/Faucet/Components/FaucetFeedback.tsx deleted file mode 100644 index 21cb884fb..000000000 --- a/source/pages/Faucet/Components/FaucetFeedback.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import React from 'react'; - -type FaucetFeedbackProps = { - icon: string; - textFeedbackDesc: string; - textFeedbackTitle: string; -}; -export const FaucetFeedback: React.FC = ({ - icon, - textFeedbackDesc, - textFeedbackTitle, -}) => ( -
- -

- {textFeedbackTitle} -

-

- {textFeedbackDesc} -

-
-); diff --git a/source/pages/Faucet/Components/index.ts b/source/pages/Faucet/Components/index.ts deleted file mode 100644 index 51df4f69d..000000000 --- a/source/pages/Faucet/Components/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './FaucetApiFeedback'; -export * from './FaucetCardAccount'; -export * from './FaucetFeedback'; diff --git a/source/pages/Faucet/Faucet.tsx b/source/pages/Faucet/Faucet.tsx deleted file mode 100644 index 20ffbb726..000000000 --- a/source/pages/Faucet/Faucet.tsx +++ /dev/null @@ -1,97 +0,0 @@ -import React from 'react'; -import { useTranslation } from 'react-i18next'; - -import errorIcon from 'assets/images/faucet-error.svg'; -import loadingIcon from 'assets/images/faucet-loading.svg'; -import successIcon from 'assets/images/faucet-success.svg'; -import { NeutralButton } from 'components/Button'; -import { Layout } from 'components/Layout'; -import { ellipsis } from 'utils/format'; - -import { - FaucetApiFeedback, - FaucetCardAccount, - FaucetFeedback, -} from './Components'; -import { FaucetComponentStates } from './Utils/FaucetComponentStates'; -import { useHandleNetworkTokenNames } from './Utils/NetworksInfos'; - -export const Faucet = () => { - const { - account, - status, - handleFaucetButton, - faucetButtonLabel, - isLoading, - faucetRequestDetails, - errorMessage, - txHash, - } = FaucetComponentStates(); - const { t } = useTranslation(); - const { networkName } = useHandleNetworkTokenNames(); - - return ( - - {status === `request` && !isLoading && ( - <> - - - - - )} - {isLoading && ( - <> - - - )} - {status === `error` && !isLoading && ( - <> - - - )} - {status === `success` && !isLoading && ( - <> - - - - )} - {!isLoading && ( -
- - {faucetButtonLabel} - -
- )} -
- ); -}; diff --git a/source/pages/Faucet/Types/index.ts b/source/pages/Faucet/Types/index.ts deleted file mode 100644 index 1ac77b5b8..000000000 --- a/source/pages/Faucet/Types/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -export type faucetTxDetailsProps = { - icon: string; - networkName: string; - quantity: number; - smartContract: string; - token: string; -}; diff --git a/source/pages/Faucet/Utils/FaucetComponentStates.tsx b/source/pages/Faucet/Utils/FaucetComponentStates.tsx deleted file mode 100644 index eb0ffc975..000000000 --- a/source/pages/Faucet/Utils/FaucetComponentStates.tsx +++ /dev/null @@ -1,127 +0,0 @@ -import { useCallback, useEffect, useMemo, useState } from 'react'; -import { useTranslation } from 'react-i18next'; -import { useSelector } from 'react-redux'; - -import { faucetTxDetailsProps } from '../Types'; -import { useUtils } from 'hooks/useUtils'; -import { claimFaucet } from 'scripts/Background/controllers/faucetController'; -import { FaucetChainIds } from 'scripts/Background/controllers/message-handler/types'; -import { RootState } from 'state/store'; - -import { - faucetTxRolluxInfo, - faucetTxRolluxTestnetInfo, - faucetTxSyscoinNEVMInfo, - faucetTxSyscoinNEVMTestnetInfo, -} from './NetworksInfos'; - -export const FaucetComponentStates = () => { - const activeAccount = useSelector( - (state: RootState) => state.vault.activeAccount - ); - const { accounts, activeNetwork } = useSelector( - (state: RootState) => state.vault - ); - - const [status, setStatus] = useState(`request`); - const [isLoading, setIsLoading] = useState(false); - const [txHash, setTxHash] = useState(``); - const [errorMessage, setErrorMessage] = useState(''); - const [faucetTxDetailsInfo, setFaucetTxDetailsInfo] = useState( - {} as faucetTxDetailsProps - ); - - const { navigate } = useUtils(); - const { t } = useTranslation(); - - const account = { - img: accounts[activeAccount.type][activeAccount.id]?.xpub, - label: accounts[activeAccount.type][activeAccount.id]?.label, - address: accounts[activeAccount.type][activeAccount.id]?.address, - }; - - const faucetRequestDetails = { - icon: faucetTxDetailsInfo?.icon, - tokenSymbol: faucetTxDetailsInfo?.token, - networkName: faucetTxDetailsInfo?.networkName, - grabText: t('faucet.withOurFaucet', { - token: faucetTxDetailsInfo.token, - networkName: faucetTxDetailsInfo.networkName, - }), - tokenQuantity: t('faucet.youCanGet', { - quantity: faucetTxDetailsInfo.quantity, - token: faucetTxDetailsInfo.token, - }), - smartContract: faucetTxDetailsInfo.smartContract, - }; - - const handleRequestFaucet = async () => { - setIsLoading(true); - try { - const data = await claimFaucet(activeNetwork.chainId, account.address); - console.log(data, 'data'); - if (!data?.status || !data?.data?.status) { - setStatus('error'); - setErrorMessage( - data?.data?.message ? data?.data?.message : data?.message - ); - } else { - setTxHash(data?.data?.hash); - setStatus(`success`); - } - } catch (error) { - console.log(error, 'a'); - setStatus('error'); - setErrorMessage(errorMessage); - } finally { - setIsLoading(false); - } - }; - - const handleFaucetButton = useCallback(() => { - if (status === 'request' || status === 'error') { - return handleRequestFaucet(); - } else if (status === 'success') { - return navigate('/home'); - } else { - return; - } - }, [status]); - - const faucetButtonLabel = useMemo(() => { - let buttonName: string; - if (status === 'request') { - buttonName = t('faucet.requestNow'); - } else if (status === 'success') { - buttonName = t('faucet.Close'); - } else if (status === 'error') { - buttonName = t('faucet.tryAgain'); - } else { - return; - } - return buttonName; - }, [status]); - - useEffect(() => { - if (activeNetwork.chainId === FaucetChainIds.RolluxMainnet) { - setFaucetTxDetailsInfo(faucetTxRolluxInfo); - } else if (activeNetwork.chainId === FaucetChainIds.RolluxTestnet) { - setFaucetTxDetailsInfo(faucetTxRolluxTestnetInfo); - } else if (activeNetwork.chainId === FaucetChainIds.nevmMainnet) { - setFaucetTxDetailsInfo(faucetTxSyscoinNEVMInfo); - } else { - setFaucetTxDetailsInfo(faucetTxSyscoinNEVMTestnetInfo); - } - }, [activeNetwork]); - - return { - account, - status, - handleFaucetButton, - faucetButtonLabel, - isLoading, - faucetRequestDetails, - errorMessage, - txHash, - }; -}; diff --git a/source/pages/Faucet/Utils/NetworksInfos.tsx b/source/pages/Faucet/Utils/NetworksInfos.tsx deleted file mode 100644 index 12614ace0..000000000 --- a/source/pages/Faucet/Utils/NetworksInfos.tsx +++ /dev/null @@ -1,72 +0,0 @@ -import { useMemo } from 'react'; -import { useSelector } from 'react-redux'; - -import { FaucetChainIds } from 'scripts/Background/controllers/message-handler/types'; -import { RootState } from 'state/store'; - -export const faucetTxRolluxInfo = { - icon: 'assets/images/rolluxChain.png', - token: '$SYS', - networkName: 'Rollux', - quantity: 0.001, - smartContract: '0x35EE5876Db071b527dC62FD3EE3c32e4304d8C23', -}; - -export const faucetTxRolluxTestnetInfo = { - icon: 'assets/images/rolluxChain.png', - token: '$TSYS', - networkName: 'Rollux Testnet', - quantity: 1, - smartContract: '0x35EE5876Db071b527dC62FD3EE3c32e4304d8C23', -}; - -export const faucetTxSyscoinNEVMInfo = { - icon: 'assets/images/sysChain.svg', - token: '$SYS', - networkName: 'Syscoin NEVM', - quantity: 0.01, - smartContract: '0x35EE5876Db071b527dC62FD3EE3c32e4304d8C23', -}; - -export const faucetTxSyscoinNEVMTestnetInfo = { - icon: 'assets/images/sysChain.svg', - token: '$TSYS', - networkName: 'Syscoin NEVM Testnet', - quantity: 1, - smartContract: '0x35EE5876Db071b527dC62FD3EE3c32e4304d8C23', -}; - -export const useHandleNetworkTokenNames = () => { - const { activeNetwork } = useSelector( - (rootState: RootState) => rootState.vault - ); - - const { token: tokenSymbol, network: networkName } = useMemo(() => { - let token: string; - let network: string; - - if (activeNetwork.chainId === FaucetChainIds.nevmMainnet) { - token = 'SYS'; - network = 'Syscoin NEVM'; - } else if (activeNetwork.chainId === FaucetChainIds.nevmTestnet) { - token = 'TSYS'; - network = 'Syscoin NEVM Testnet'; - } else if (activeNetwork.chainId === FaucetChainIds.RolluxTestnet) { - token = 'TSYS'; - network = 'Rollux Testnet'; - } else if (activeNetwork.chainId === FaucetChainIds.RolluxMainnet) { - token = 'SYS'; - network = 'Rollux'; - } else { - token = ''; - network = ''; - } - - return { token, network }; - }, [activeNetwork]); - - return { - tokenSymbol, - networkName, - }; -}; diff --git a/source/pages/Faucet/index.tsx b/source/pages/Faucet/index.tsx deleted file mode 100644 index 89d8bbf76..000000000 --- a/source/pages/Faucet/index.tsx +++ /dev/null @@ -1 +0,0 @@ -export { Faucet } from './Faucet'; diff --git a/source/pages/Home/Home.tsx b/source/pages/Home/Home.tsx index 8fb7ecb4e..839577505 100755 --- a/source/pages/Home/Home.tsx +++ b/source/pages/Home/Home.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useEffect, useMemo, useState } from 'react'; +import React, { useEffect, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useSelector } from 'react-redux'; import { useLocation } from 'react-router-dom'; @@ -6,15 +6,11 @@ import { useLocation } from 'react-router-dom'; import { CustomJsonRpcProvider } from '@pollum-io/sysweb3-keyring'; import { Header, Icon, Button, Loading } from 'components/index'; -import { FaucetAccessModal } from 'components/Modal/FaucetAccessModal'; -import { FaucetFirstAccessModal } from 'components/Modal/FaucetModal'; import { StatusModal } from 'components/Modal/StatusModal'; import { WalletProviderDefaultModal } from 'components/Modal/WalletProviderDafault'; import { ConnectHardwareWallet } from 'components/Modal/WarningBaseModal'; import { usePrice, useUtils } from 'hooks/index'; -import { FaucetChainIds } from 'scripts/Background/controllers/message-handler/types'; import { RootState } from 'state/store'; -import { setFaucetModalState } from 'state/vault'; import { getController } from 'utils/browser'; import { ONE_MILLION, @@ -35,7 +31,7 @@ export const Home = () => { //* Selectors const { asset: fiatAsset, price: fiatPrice } = useSelector( - (priceState: RootState) => priceState.price.fiat + (state: RootState) => state.price.fiat ); const isWalletImported = state?.isWalletImported; const { @@ -46,8 +42,7 @@ export const Home = () => { isBitcoinBased, lastLogin, isLoadingBalances, - faucetModal, - } = useSelector((rootState: RootState) => rootState.vault); + } = useSelector((state: RootState) => state.vault); //* States const [isTestnet, setIsTestnet] = useState(false); @@ -57,33 +52,19 @@ export const Home = () => { //* Constants const { url } = activeNetwork; const controller = getController(); - const { wallet } = controller; - const { isInCooldown }: CustomJsonRpcProvider = controller.wallet.ethereumTransaction.web3Provider; - const isUnlocked = controller.wallet.isUnlocked() && accounts[activeAccount.type][activeAccount.id].address !== ''; - const bgColor = isNetworkChanging ? 'bg-bkg-2' : 'bg-bkg-3'; const { syscoin: syscoinBalance, ethereum: ethereumBalance } = accounts[activeAccount.type][activeAccount.id].balances; - const actualBalance = useMemo( - () => (isBitcoinBased ? syscoinBalance : ethereumBalance), - [syscoinBalance, ethereumBalance] - ); - - const moreThanMillion = useMemo( - () => actualBalance > ONE_MILLION, - [actualBalance] - ); + const actualBalance = isBitcoinBased ? syscoinBalance : ethereumBalance; + const moreThanMillion = actualBalance >= ONE_MILLION; - const moreThanTrillion = useMemo( - () => actualBalance > ONE_TRILLION, - [actualBalance] - ); + const moreThanTrillion = actualBalance > ONE_TRILLION; const closeModal = () => { setShowModalCongrats(false); @@ -138,51 +119,15 @@ export const Home = () => { return formatBalanceDecimals(fiatPriceValue, true); }, [fiatPriceValue, isTestnet, moreThanMillion]); - const handleOnCloseFaucetModal = useCallback(() => { - wallet.setFaucetModalState(activeNetwork.chainId); - }, [activeNetwork, setFaucetModalState]); - - const shouldShowFaucetFirstModal = useMemo( - () => faucetModal[activeNetwork.chainId], - [faucetModal, activeNetwork] - ); - - const formattedBalance = useMemo( - () => - moreThanMillion - ? formatMillionNumber(actualBalance) - : formatBalanceDecimals(actualBalance || 0, false), - [actualBalance, moreThanMillion] - ); - - const shouldRenderHomePage = useMemo( - () => - accounts[activeAccount.type][activeAccount.id] && - lastLogin && - isUnlocked && - !isNetworkChanging, - [accounts, activeAccount, lastLogin, isUnlocked, isNetworkChanging] - ); - return (
- {shouldRenderHomePage ? ( + {accounts[activeAccount.type][activeAccount.id] && + lastLogin && + isUnlocked && + !isNetworkChanging ? ( <>
- {!isBitcoinBased && - Object.values(FaucetChainIds).includes(activeNetwork.chainId) && ( - <> - {shouldShowFaucetFirstModal ? ( - - ) : ( - - )} - - )} -
@@ -190,7 +135,9 @@ export const Home = () => { id="home-balance" className={`font-rubik text-5xl font-medium`} > - {formattedBalance}{' '} + {moreThanMillion + ? formatMillionNumber(actualBalance) + : formatBalanceDecimals(actualBalance || 0, false)}{' '}

{

-

{formatFiatAmount}

+

{formatFiatAmount}

diff --git a/source/pages/Send/SendEth.tsx b/source/pages/Send/SendEth.tsx index 64953d313..bfff929b3 100644 --- a/source/pages/Send/SendEth.tsx +++ b/source/pages/Send/SendEth.tsx @@ -35,7 +35,7 @@ export const SendEth = () => { gasPrice: 0, }); const [isMessageVisible, setIsMessageVisible] = useState(false); - const [inputValue, setInputValue] = useState({ address: '', amount: 0 }); + const [inputValue, setInputValue] = useState({ address: '', amount: null }); const [isValidAddress, setIsValidAddress] = useState(null); const [isValidAmount, setIsValidAmount] = useState(null); diff --git a/source/pages/Settings/CustomRPC.tsx b/source/pages/Settings/CustomRPC.tsx index 566387add..fc6863db7 100644 --- a/source/pages/Settings/CustomRPC.tsx +++ b/source/pages/Settings/CustomRPC.tsx @@ -33,7 +33,7 @@ const CustomRPCView = () => { >(null); const [isSyscoinRpc, setIsSyscoinRpc] = useState(Boolean(isSyscoinSelected)); const { activeNetwork, isBitcoinBased } = useSelector( - (state: RootState) => state.vault + (rootState: RootState) => rootState.vault ); const { wallet } = getController(); const { alert, navigate } = useUtils(); @@ -74,7 +74,6 @@ const CustomRPCView = () => { setAddedRpc(true); return; } - await controller.wallet.editCustomRpc(customRpc, state.selected); setLoading(false); setAddedRpc(true); @@ -99,7 +98,7 @@ const CustomRPCView = () => { url: (state && state.selected && state.selected.url) ?? '', chainId: (state && state.selected && state.selected.chainId) ?? '', symbol: (state && state.selected && state.selected.currency) ?? '', - explorer: (state && state.selected && state.selected.explorer) ?? '', + explorer: (state && state.selected && state.selected.url) ?? '', }; const isInputDisableByEditMode = state ? state.isDefault : false; diff --git a/source/pages/Settings/ExternalAddRPC.tsx b/source/pages/Settings/ExternalAddRPC.tsx index 2eb409c3e..19f0dc594 100644 --- a/source/pages/Settings/ExternalAddRPC.tsx +++ b/source/pages/Settings/ExternalAddRPC.tsx @@ -1,6 +1,8 @@ import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; +import { INetwork } from '@pollum-io/sysweb3-network'; + import { DefaultModal, Layout, @@ -12,22 +14,32 @@ import { dispatchBackgroundEvent, getController } from 'utils/browser'; const CustomRPCExternal = () => { const { host, ...data } = useQueryData(); const { t } = useTranslation(); - const [loading, setLoading] = useState(false); - const [confirmed, setConfirmed] = useState(false); const { alert } = useUtils(); const controller = getController(); + + const [loading, setLoading] = useState(false); + const [confirmed, setConfirmed] = useState(false); + const wallet = controller.wallet; + const onSubmit = async (customRpc: any) => { setLoading(true); + const networkWithCustomParams = { + ...customRpc, + explorer: data?.apiUrl ? data.apiUrl : customRpc?.apiUrl || '', + } as INetwork; + try { - await controller.wallet.addCustomRpc(customRpc).then(async (network) => { - setConfirmed(true); - setLoading(false); - const type = data.eventName; - dispatchBackgroundEvent(`${type}.${host}`, null); - await wallet.setActiveNetwork(network, 'ethereum'); - }); + await controller.wallet + .addCustomRpc(networkWithCustomParams) + .then(async (network) => { + setConfirmed(true); + setLoading(false); + const type = data.eventName; + dispatchBackgroundEvent(`${type}.${host}`, null); + await wallet.setActiveNetwork(network, 'ethereum'); + }); } catch (error: any) { alert.removeAll(); alert.error(error.message); diff --git a/source/routers/index.tsx b/source/routers/index.tsx index 96c923e7b..521626668 100644 --- a/source/routers/index.tsx +++ b/source/routers/index.tsx @@ -41,7 +41,6 @@ import { import { WarningModal } from 'components/Modal'; import { useUtils } from 'hooks/index'; import { ChainErrorPage } from 'pages/Chain'; -import { Faucet } from 'pages/Faucet'; import { SwitchNetwork } from 'pages/SwitchNetwork'; import { inactivityTime, @@ -199,11 +198,6 @@ export const Router = () => { element={} />} /> - } />} - /> - } />} diff --git a/source/scripts/Background/controllers/MainController.ts b/source/scripts/Background/controllers/MainController.ts index aeb19079a..f60ab1597 100644 --- a/source/scripts/Background/controllers/MainController.ts +++ b/source/scripts/Background/controllers/MainController.ts @@ -52,7 +52,6 @@ import { setTransactionStatusToAccelerated, setUpdatedNftsToState, setOpenDAppErrorModal, - setFaucetModalState as setFaucetState, } from 'state/vault'; import { IOmmitedAccount, @@ -122,10 +121,6 @@ const MainController = (walletState): IMainController => { store.dispatch(setEthProperty(exist)); }; - const setFaucetModalState = (chainId: number) => { - store.dispatch(setFaucetState({ chainId })); - }; - const setAdvancedSettings = (advancedProperty: string, isActive: boolean) => { store.dispatch(setSettings({ advancedProperty, isActive })); }; @@ -1095,6 +1090,8 @@ const MainController = (walletState): IMainController => { activeNetwork.url ); + console.log('updatedNfts', updatedNfts); + const validateUpdatedAndPreviousNftsLength = updatedNfts.length < currentAccount.assets.nfts.length; @@ -1647,7 +1644,6 @@ const MainController = (walletState): IMainController => { validatePendingEvmTransactions, ...keyringManager, openDAppErrorModal, - setFaucetModalState, }; }; diff --git a/source/scripts/Background/controllers/MigrationController.ts b/source/scripts/Background/controllers/MigrationController.ts new file mode 100644 index 000000000..34007ca53 --- /dev/null +++ b/source/scripts/Background/controllers/MigrationController.ts @@ -0,0 +1,11 @@ +import { loadState } from 'utils/localStorage'; + +const MigrationController = async () => { + const state: any = await loadState(); + + if (!state) { + return; + } +}; + +export default MigrationController; diff --git a/source/scripts/Background/controllers/faucetController.ts b/source/scripts/Background/controllers/faucetController.ts deleted file mode 100644 index a6eaa1342..000000000 --- a/source/scripts/Background/controllers/faucetController.ts +++ /dev/null @@ -1,27 +0,0 @@ -import axios from 'axios'; - -const claimFaucet = async (chainId: number, walletAddress: string) => { - let chainName: string; - - if (chainId === 57) { - chainName = `nevm-mainnet`; - } else if (chainId === 5700) { - chainName = `nevm-testnet`; - } else if (chainId === 57000) { - chainName = `rollux-testnet`; - } else if (chainId === 570) { - chainName = `rollux-mainnet`; - } else { - chainName = ``; - } - try { - const { data } = await axios.get( - `https://chains.tools/api/faucet/claim?networkKey=${chainName}&walletAddress=${walletAddress}` - ); - return data; - } catch (err) { - return err; - } -}; - -export { claimFaucet }; diff --git a/source/scripts/Background/controllers/index.ts b/source/scripts/Background/controllers/index.ts index 704a23f64..b4a1fee1a 100755 --- a/source/scripts/Background/controllers/index.ts +++ b/source/scripts/Background/controllers/index.ts @@ -19,7 +19,6 @@ import { setAccountTypeInAccountsObject, setActiveNetwork, setAdvancedSettings, - setFaucetModalState, setIsLastTxConfirmed, setNetwork, setTimer, @@ -180,12 +179,6 @@ const MasterController = ( store.getState()?.vault?.networks?.[TransactionsType.Syscoin][57] ?.isTestnet === undefined; - const isOldFaucetState = store.getState()?.vault?.faucetModal === undefined; - - if (isOldFaucetState) { - store.dispatch(setFaucetModalState({ chainId: 0, isFirstTime: true })); - } - if (isNetworkOldState || isNetworkOldEVMStateWithoutTestnet) { Object.values(initialNetworksState[TransactionsType.Ethereum]).forEach( (network) => { diff --git a/source/scripts/Background/controllers/message-handler/types.ts b/source/scripts/Background/controllers/message-handler/types.ts index 73eecea6f..af875f982 100644 --- a/source/scripts/Background/controllers/message-handler/types.ts +++ b/source/scripts/Background/controllers/message-handler/types.ts @@ -10,13 +10,6 @@ export enum HardWallets { TREZOR = 'TREZOR', } -export enum FaucetChainIds { - RolluxMainnet = 570, - RolluxTestnet = 57000, - nevmTestnet = 5700, - nevmMainnet = 57, -} - //TODO: addtype for rpc subscription notifications here export enum PaliEvents { accountsChanged = 'pali_accountsChanged', diff --git a/source/scripts/Background/index.ts b/source/scripts/Background/index.ts index 1871c07a6..d0970508c 100755 --- a/source/scripts/Background/index.ts +++ b/source/scripts/Background/index.ts @@ -11,6 +11,7 @@ import { log } from 'utils/logger'; import { PaliLanguages } from 'utils/types'; import MasterController, { IMasterController } from './controllers'; +import MigrationController from './controllers/MigrationController'; import { IEvmTransactionResponse } from './controllers/transactions/types'; /* eslint-disable @typescript-eslint/ban-ts-comment */ declare global { @@ -33,6 +34,7 @@ const onWalletReady = (windowController: IMasterController) => { }; if (!window.controller) { + MigrationController(); window.controller = MasterController(onWalletReady); } diff --git a/source/state/vault/index.ts b/source/state/vault/index.ts index e338f7647..8ec7de1b2 100644 --- a/source/state/vault/index.ts +++ b/source/state/vault/index.ts @@ -79,12 +79,6 @@ export const initialState: IVaultState = { networks: initialNetworksState, error: false, isPolling: false, - faucetModal: { - 57: true, - 570: true, - 5700: true, - 57000: true, - }, currentBlock: undefined, coinsList: [], }; @@ -306,27 +300,6 @@ const VaultState = createSlice({ setIsNetworkChanging(state: IVaultState, action: PayloadAction) { state.isNetworkChanging = action.payload; }, - setFaucetModalState: ( - state: IVaultState, - action: PayloadAction<{ chainId: number; isFirstTime?: boolean }> - ) => { - const { chainId, isFirstTime } = action.payload; - if (state.isBitcoinBased) { - return; - } - - if (isFirstTime) { - state.faucetModal = { - 57: true, - 570: true, - 5700: true, - 57000: true, - }; - return; - } - - state.faucetModal[chainId] = false; - }, setIsDappAskingToChangeNetwork( state: IVaultState, action: PayloadAction @@ -843,7 +816,6 @@ export const { setTransactionStatusToAccelerated, setCoinsList, setIsLastTxConfirmed, - setFaucetModalState, } = VaultState.actions; export default VaultState.reducer; diff --git a/source/state/vault/types.ts b/source/state/vault/types.ts index 6598f1132..7a8b1e78a 100644 --- a/source/state/vault/types.ts +++ b/source/state/vault/types.ts @@ -28,9 +28,6 @@ export interface IVaultState { coinsList: any[]; currentBlock: ethers.providers.Block; error: boolean; - faucetModal: { - [k: number]: boolean; - }; hasErrorOndAppEVM: boolean; hasEthProperty: boolean; isBitcoinBased: boolean; diff --git a/source/types/controllers.ts b/source/types/controllers.ts index 06d8dcc9f..cdac0c482 100644 --- a/source/types/controllers.ts +++ b/source/types/controllers.ts @@ -126,7 +126,6 @@ export interface IMainController extends IKeyringManager { newTxValue: IEvmTransactionResponse ) => void; setEvmTransactionAsCanceled: (txHash: string, chainID: number) => void; - setFaucetModalState: (chainId: number) => void; setHasEthProperty: (exist: boolean) => void; setIsAutolockEnabled: (isEnabled: boolean) => void; setIsLastTxConfirmed: ( diff --git a/source/utils/browser.ts b/source/utils/browser.ts index 75bc804ef..e03efdd86 100644 --- a/source/utils/browser.ts +++ b/source/utils/browser.ts @@ -12,3 +12,7 @@ export const dispatchBackgroundEvent = (eventName: string, data: any) => { const background = browser.extension.getBackgroundPage(); background.dispatchEvent(new CustomEvent(eventName, { detail: data })); }; + +export const reload = () => { + browser.runtime.reload(); +}; diff --git a/source/utils/localStorage.ts b/source/utils/localStorage.ts new file mode 100644 index 000000000..08cdc5136 --- /dev/null +++ b/source/utils/localStorage.ts @@ -0,0 +1,25 @@ +import store from 'state/store'; + +export const saveState = async (appState) => { + try { + const serializedState = JSON.stringify(appState); + await localStorage.setItem('persist:root', serializedState); + console.log('State saved successfully!'); + } catch (e) { + console.error(' Error saving state', e); + } +}; + +export const loadState = async () => { + try { + const state = store.getState(); + + if (state === null) { + return undefined; + } + return state; + } catch (e) { + console.error(' Error getting state', e); + return null; + } +}; diff --git a/source/utils/version.ts b/source/utils/version.ts new file mode 100644 index 000000000..bc67f978f --- /dev/null +++ b/source/utils/version.ts @@ -0,0 +1,16 @@ +// This function compares two versions. The format should be {major}.{minor}.{patch} +// The function returns -1 if the first version (v1) is less than the second (v2), 1 if the first version (v1) is greater than the second (v2), and 0 if they are equal. +export const compareVersions = (v1: string, v2: string): number => { + const v1Parts = v1.split('.').map(Number); + const v2Parts = v2.split('.').map(Number); + + for (let i = 0; i < 3; i++) { + if (v1Parts[i] > v2Parts[i]) { + return 1; + } else if (v1Parts[i] < v2Parts[i]) { + return -1; + } + } + + return 0; +}; diff --git a/yarn.lock b/yarn.lock index fa1ad3a49..c06af75b5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3131,9 +3131,11 @@ integrity sha512-Kmp/wBZk19Dn7uRiol8kF8agnf8m0+TU9qIwyfPmXglVxMlmiIz0VQSMw5oFgwhmD2aKTlfBIO5FtsVj3y7hKQ== "@types/node@^18.16.3": - version "18.16.9" - resolved "https://registry.yarnpkg.com/@types/node/-/node-18.16.9.tgz#e79416d778a8714597342bb87efb5a6e914f7a73" - integrity sha512-IeB32oIV4oGArLrd7znD2rkHQ6EDCM+2Sr76dJnrHwv9OHBTTM6nuDLK9bmikXzPa0ZlWMWtRGo/Uw4mrzQedA== + version "18.19.43" + resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.43.tgz#fe01bb599b60bb3279c26d0fdb751d2f3e299ae0" + integrity sha512-Mw/YlgXnyJdEwLoFv2dpuJaDFriX+Pc+0qOBJ57jC1H6cDxIj2xc5yUrdtArDVG0m+KV6622a4p2tenEqB3C/g== + dependencies: + undici-types "~5.26.4" "@types/normalize-package-data@^2.4.0": version "2.4.1" @@ -13395,6 +13397,11 @@ unbox-primitive@^1.0.2: has-symbols "^1.0.3" which-boxed-primitive "^1.0.2" +undici-types@~5.26.4: + version "5.26.5" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" + integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== + undici@^5.14.0: version "5.22.1" resolved "https://registry.yarnpkg.com/undici/-/undici-5.22.1.tgz#877d512effef2ac8be65e695f3586922e1a57d7b"