diff --git a/packages/page-migration/src/Migration/index.tsx b/packages/page-migration/src/Migration/index.tsx index 1f81f5dfa476..45f5f71733ed 100644 --- a/packages/page-migration/src/Migration/index.tsx +++ b/packages/page-migration/src/Migration/index.tsx @@ -1,265 +1,21 @@ // Copyright 2017-2022 @polkadot/app-rpc authors & contributors // SPDX-License-Identifier: Apache-2.0 -import React, { useState, useEffect } from 'react'; +import React from 'react'; -import type { DeriveBalancesAll } from '@polkadot/api-derive/types'; -import type { RuntimeDispatchInfo } from '@polkadot/types/interfaces'; - -import { Available, Dropdown, InputAddressCheqd } from '@polkadot/react-components'; -import { InputAddress, MarkError, MarkWarning, TxButton, Button } from '@polkadot/react-components'; +import { MarkWarning } from '@polkadot/react-components'; import { useTranslation } from '../translate'; -import { isValidCheqdAddress, getCheqdAddressError } from '@polkadot/react-components/InputAddressCheqd'; -import { useApi, useCall } from '@polkadot/react-hooks'; -import { formatBalance, nextTick } from '@polkadot/util'; - -function convertDockToCheqd(dockBalance) { - if (!dockBalance) { - return 0; - } - const swapRatio = 18.5178; - const dockAmt = dockBalance.toNumber() / 1000000; - const cheqdBalance = dockAmt / swapRatio; - return cheqdBalance; -} - -function hasAvailableBalance(dockBalance) { - if (!dockBalance || !dockBalance.availableBalance) { - return false; - } - return !dockBalance.availableBalance.isZero(); -} - -function hasLockedBalance(dockBalance) { - if (!dockBalance || !dockBalance.lockedBalance) { - return false; - } - return !dockBalance.lockedBalance.isZero(); -} function MigrationApp ({ className }): React.ReactElement { const { t } = useTranslation(); - const [senderId, setSenderId] = useState(null); - const [cheqdId, setCheqdId] = useState(''); - const [selectFromDropdown, setSelectFromDropdown] = useState(false); - const [cheqdAddresses, setCheqdAddresses] = useState([]); - const [dispatchInfo, setDispatchInfo] = useState(null); - const { api } = useApi(); - const allBalances = useCall(api.derive.balances?.all, [senderId]); - const values = [cheqdId]; - const extrinsic = api && api.tx && api.tx.cheqdMigration && api.tx.cheqdMigration.migrate(values); - const isValid = senderId && cheqdId && isValidCheqdAddress(cheqdId); - const totalMigrationBalance = allBalances ? (dispatchInfo ? allBalances.availableBalance.sub(dispatchInfo.partialFee) : allBalances.availableBalance) : 0; - - useEffect((): void => { - senderId && extrinsic && api.call.transactionPaymentApi && - nextTick(async (): Promise => { - try { - const info = await extrinsic.paymentInfo(senderId); - setDispatchInfo(info); - } catch (error) { - console.error(error); - } - }); - }, [api, senderId, extrinsic]); - - function handleSuccess() { - window.location = 'https://www.dock.io/token-migration-success'; - } - - async function getExtensionAddresses() { - const chainId = 'cheqd-mainnet-1'; - const walletObj = window.keplr || window.leap; - - await walletObj.enable(chainId); - - const offlineSigner = walletObj.getOfflineSigner(chainId); - const accounts = await offlineSigner.getAccounts(); - setCheqdAddresses([...cheqdAddresses, ...accounts.map(({ address }) => address)]); - setSelectFromDropdown(accounts.length > 0); - } - - useEffect(() => { - if (window.keplr || window.leap) { - getExtensionAddresses(); - } - }, []); - return (
('Migrating your Dock balance to cheqd will zero the balance on your Dock account.')} - /> - -

- The Dock network is migrating its functionality and all tokens to the cheqd blockchain. This migration will allow Dock to leverage cheqd’s advanced infrastructure and bring enhanced value to both ecosystems. Existing $DOCK tokens will be converted into $CHEQ tokens, ensuring a smooth transition for all token holders. -

- -

- Before you start the process make sure you have a cheqd account. If you do not currently have one, see instructions on how to create one. -

- -

- To migrate your $DOCK tokens: -

-
    -
  1. - Select your Dock account. If it isn't there follow these instructions. -
  2. -
  3. - Connect your cheqd wallet or enter your cheqd account manually. Connecting a Leap wallet will allow us to confirm that the tokens are going to the cheqd account that you control. -
  4. -
  5. - Accept T&Cs and click Submit -
  6. -
  7. - Authorize the transaction by entering your account password. Click Sign & Submit -
  8. -
- -

- The entire amount of the account will be migrated at once. After the migration request is submitted your $DOCK tokens will be burnt and you will be sent the converted CHEQD amount with Swap Ratio: 18.5178 $DOCK to 1 $CHEQ. The migration will take up to 1-2 business days to complete, after that the converted $CHEQ amount will be available in the indicated cheqd wallet. -

- -

- The migration service will only be available until March 15, 2025. -
- Please follow these instructions carefully and contact our team with any questions at support@dock.io. -

- - ('The account you will migrate to Cheqd.')} - label={t('migrate account')} - labelExtra={ - ('transferrable')} - params={senderId} - /> - } - value={senderId} - onChange={setSenderId} - type='account' - /> - -
- - {selectFromDropdown ? ( - <> - ('The cheqd account your tokens will be migrated to.')} - label={t('cheqd extension account')} - isMultiple={false} - onChange={setCheqdId} - options={cheqdAddresses.map((cheqdAddress) => ({ - value: cheqdAddress, - text: cheqdAddress, - }))} - value={cheqdId} - /> - { - e.preventDefault(); - setSelectFromDropdown(false); - }}>Enter address manually - - ) : ( - <> - ('The cheqd account your tokens will be migrated to.')} - label={t('cheqd account')} - value={cheqdId} - onChange={setCheqdId} - type='account' - /> - {cheqdAddresses.length > 0 && ( - <> - { - e.preventDefault(); - setSelectFromDropdown(true); - }}>Select from wallet extension - - )} - - )} - - {cheqdId && !isValidCheqdAddress(cheqdId) && ( - (getCheqdAddressError(cheqdId) || 'This cheqd address is invalid, please check it before continuing.')} - /> - )} - -

- - {(senderId && allBalances) ? ( -

- {hasAvailableBalance(allBalances) ? ( - hasLockedBalance(allBalances) ? ( - <> - This Dock account has locked or staked funds, please unbond to migrate. - - ) : (( - <> - After the migration is complete, your {formatBalance(totalMigrationBalance)} (total available minus chain fees) will be converted into {convertDockToCheqd(totalMigrationBalance)} CHEQD. - - ) - ) - ) : ( - <> - This Dock account has no available balance to migrate. - - )} -

- ) : ( -

- - Enter a sender and receiver address to see the total CHEQD you will receive. -

- )} - -

- By submitting this transaction you agree to the migration terms and conditions. -

- -
- - - ('Submit Transaction')} - /> - + > + The DOCK -> CHEQD token migration has ended as of March 15th, 2025. If you need assistance contact the cheqd team on Telegram +
); }