From 07daaacf8fe7362a4aa47188df23ee1426719f54 Mon Sep 17 00:00:00 2001 From: guanbinrui Date: Tue, 29 Jun 2021 18:27:27 +0800 Subject: [PATCH] feat: ITO bsc polygon history (#3421) * feat: ITO bsc polygon history * fix: ui * share dialog style * token symbol * fix: ui * fix: variable Co-authored-by: guanbinrui Co-authored-by: guanbinrui <52657989+guanbinrui@users.noreply.github.com> --- packages/contracts/CHANGELOG.md | 9 + packages/contracts/abis/BscPolygonITO.json | 446 ++++++++++++++++++ packages/contracts/types/BscPolygonITO.d.ts | 183 +++++++ .../src/plugins/ITO/UI/CompositionDialog.tsx | 8 +- .../src/plugins/ITO/UI/CreateForm.tsx | 3 +- packages/maskbook/src/plugins/ITO/UI/ITO.tsx | 12 +- .../src/plugins/ITO/UI/PoolInList.tsx | 18 +- .../src/plugins/ITO/UI/RemindDialog.tsx | 1 + .../src/plugins/ITO/UI/ShareDialog.tsx | 50 +- .../src/plugins/ITO/UI/SwapDialog.tsx | 5 +- .../src/plugins/ITO/UI/UnlockDialog.tsx | 8 +- .../maskbook/src/plugins/ITO/constants.ts | 27 +- .../plugins/ITO/contracts/useITO_Contract.ts | 14 +- .../ITO/contracts/useITO_ContractAddress.ts | 10 + .../twitter.com/customization/custom.ts | 1 + 15 files changed, 736 insertions(+), 59 deletions(-) create mode 100644 packages/contracts/abis/BscPolygonITO.json create mode 100644 packages/contracts/types/BscPolygonITO.d.ts create mode 100644 packages/maskbook/src/plugins/ITO/contracts/useITO_ContractAddress.ts diff --git a/packages/contracts/CHANGELOG.md b/packages/contracts/CHANGELOG.md index 51954034f7b5..31126d604ca6 100644 --- a/packages/contracts/CHANGELOG.md +++ b/packages/contracts/CHANGELOG.md @@ -29,6 +29,15 @@ Mainnet 0xf110fec3075d7531141b6bf16b11604cb028a17b Ropsten 0x37c2f41085ff45f54652c359a7de4deb9d125bf2 ``` +> Jun-18-2021 +> branch: +> commit: a6bf007f8cbe024920f32c31479287b79fe53601 + +```plain +Bsc 0x54a0A221C25Fc0a347EC929cFC5db0be17fA2a2B +Polygon 0x981be454a930479d92C91a0092D204b64845A5D6 +``` + ## MaskITO > Feb-21-2021 diff --git a/packages/contracts/abis/BscPolygonITO.json b/packages/contracts/abis/BscPolygonITO.json new file mode 100644 index 000000000000..688d13b358ff --- /dev/null +++ b/packages/contracts/abis/BscPolygonITO.json @@ -0,0 +1,446 @@ +[ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "bytes32", + "name": "id", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "address", + "name": "claimer", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "to_value", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "token_address", + "type": "address" + } + ], + "name": "ClaimSuccess", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "bytes32", + "name": "id", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "address", + "name": "token_address", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "remaining_balance", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint128[]", + "name": "exchanged_values", + "type": "uint128[]" + } + ], + "name": "DestructSuccess", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "total", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "id", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "address", + "name": "creator", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "creation_time", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "token_address", + "type": "address" + }, + { + "indexed": false, + "internalType": "string", + "name": "message", + "type": "string" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "start", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "end", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address[]", + "name": "exchange_addrs", + "type": "address[]" + }, + { + "indexed": false, + "internalType": "uint128[]", + "name": "ratios", + "type": "uint128[]" + }, + { + "indexed": false, + "internalType": "address", + "name": "qualification", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "limit", + "type": "uint256" + } + ], + "name": "FillSuccess", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "bytes32", + "name": "id", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "address", + "name": "swapper", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "from_address", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "to_address", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "from_value", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "to_value", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "input_total", + "type": "uint128" + } + ], + "name": "SwapSuccess", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "bytes32", + "name": "id", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "address", + "name": "token_address", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "withdraw_balance", + "type": "uint256" + } + ], + "name": "WithdrawSuccess", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "id", + "type": "bytes32" + } + ], + "name": "check_availability", + "outputs": [ + { + "internalType": "address[]", + "name": "exchange_addrs", + "type": "address[]" + }, + { + "internalType": "uint256", + "name": "remaining", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "started", + "type": "bool" + }, + { + "internalType": "bool", + "name": "expired", + "type": "bool" + }, + { + "internalType": "bool", + "name": "unlocked", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "unlock_time", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapped", + "type": "uint256" + }, + { + "internalType": "uint128[]", + "name": "exchanged_tokens", + "type": "uint128[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32[]", + "name": "ito_ids", + "type": "bytes32[]" + } + ], + "name": "claim", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "id", + "type": "bytes32" + } + ], + "name": "destruct", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "_hash", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_start", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_end", + "type": "uint256" + }, + { + "internalType": "string", + "name": "_message", + "type": "string" + }, + { + "internalType": "address[]", + "name": "_exchange_addrs", + "type": "address[]" + }, + { + "internalType": "uint128[]", + "name": "_ratios", + "type": "uint128[]" + }, + { + "internalType": "uint256", + "name": "_unlock_time", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_token_addr", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_total_tokens", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_limit", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_qualification", + "type": "address" + } + ], + "name": "fill_pool", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "id", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "_unlock_time", + "type": "uint256" + } + ], + "name": "setUnlockTime", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "_id", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "verification", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "validation", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "exchange_addr_i", + "type": "uint256" + }, + { + "internalType": "uint128", + "name": "_input_total", + "type": "uint128" + } + ], + "name": "swap", + "outputs": [ + { + "internalType": "uint256", + "name": "swapped", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "id", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "addr_i", + "type": "uint256" + } + ], + "name": "withdraw", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/packages/contracts/types/BscPolygonITO.d.ts b/packages/contracts/types/BscPolygonITO.d.ts new file mode 100644 index 000000000000..39f626056d3e --- /dev/null +++ b/packages/contracts/types/BscPolygonITO.d.ts @@ -0,0 +1,183 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import BN from 'bn.js' +import { ContractOptions } from 'web3-eth-contract' +import { EventLog } from 'web3-core' +import { EventEmitter } from 'events' +import { + Callback, + PayableTransactionObject, + NonPayableTransactionObject, + BlockType, + ContractEventLog, + BaseContract, +} from './types' + +interface EventOptions { + filter?: object + fromBlock?: BlockType + topics?: string[] +} + +export type ClaimSuccess = ContractEventLog<{ + id: string + claimer: string + timestamp: string + to_value: string + token_address: string + 0: string + 1: string + 2: string + 3: string + 4: string +}> +export type DestructSuccess = ContractEventLog<{ + id: string + token_address: string + remaining_balance: string + exchanged_values: string[] + 0: string + 1: string + 2: string + 3: string[] +}> +export type FillSuccess = ContractEventLog<{ + total: string + id: string + creator: string + creation_time: string + token_address: string + message: string + start: string + end: string + exchange_addrs: string[] + ratios: string[] + qualification: string + limit: string + 0: string + 1: string + 2: string + 3: string + 4: string + 5: string + 6: string + 7: string + 8: string[] + 9: string[] + 10: string + 11: string +}> +export type SwapSuccess = ContractEventLog<{ + id: string + swapper: string + from_address: string + to_address: string + from_value: string + to_value: string + input_total: string + 0: string + 1: string + 2: string + 3: string + 4: string + 5: string + 6: string +}> +export type WithdrawSuccess = ContractEventLog<{ + id: string + token_address: string + withdraw_balance: string + 0: string + 1: string + 2: string +}> + +export interface BscPolygonITO extends BaseContract { + constructor(jsonInterface: any[], address?: string, options?: ContractOptions): BscPolygonITO + clone(): BscPolygonITO + methods: { + check_availability(id: string | number[]): NonPayableTransactionObject<{ + exchange_addrs: string[] + remaining: string + started: boolean + expired: boolean + unlocked: boolean + unlock_time: string + swapped: string + exchanged_tokens: string[] + 0: string[] + 1: string + 2: boolean + 3: boolean + 4: boolean + 5: string + 6: string + 7: string[] + }> + + claim(ito_ids: (string | number[])[]): NonPayableTransactionObject + + destruct(id: string | number[]): NonPayableTransactionObject + + fill_pool( + _hash: string | number[], + _start: number | string | BN, + _end: number | string | BN, + _message: string, + _exchange_addrs: string[], + _ratios: (number | string | BN)[], + _unlock_time: number | string | BN, + _token_addr: string, + _total_tokens: number | string | BN, + _limit: number | string | BN, + _qualification: string, + ): PayableTransactionObject + + setUnlockTime(id: string | number[], _unlock_time: number | string | BN): NonPayableTransactionObject + + swap( + _id: string | number[], + verification: string | number[], + validation: string | number[], + exchange_addr_i: number | string | BN, + _input_total: number | string | BN, + ): PayableTransactionObject + + withdraw(id: string | number[], addr_i: number | string | BN): NonPayableTransactionObject + } + events: { + ClaimSuccess(cb?: Callback): EventEmitter + ClaimSuccess(options?: EventOptions, cb?: Callback): EventEmitter + + DestructSuccess(cb?: Callback): EventEmitter + DestructSuccess(options?: EventOptions, cb?: Callback): EventEmitter + + FillSuccess(cb?: Callback): EventEmitter + FillSuccess(options?: EventOptions, cb?: Callback): EventEmitter + + SwapSuccess(cb?: Callback): EventEmitter + SwapSuccess(options?: EventOptions, cb?: Callback): EventEmitter + + WithdrawSuccess(cb?: Callback): EventEmitter + WithdrawSuccess(options?: EventOptions, cb?: Callback): EventEmitter + + allEvents(options?: EventOptions, cb?: Callback): EventEmitter + } + + once(event: 'ClaimSuccess', cb: Callback): void + once(event: 'ClaimSuccess', options: EventOptions, cb: Callback): void + + once(event: 'DestructSuccess', cb: Callback): void + once(event: 'DestructSuccess', options: EventOptions, cb: Callback): void + + once(event: 'FillSuccess', cb: Callback): void + once(event: 'FillSuccess', options: EventOptions, cb: Callback): void + + once(event: 'SwapSuccess', cb: Callback): void + once(event: 'SwapSuccess', options: EventOptions, cb: Callback): void + + once(event: 'WithdrawSuccess', cb: Callback): void + once(event: 'WithdrawSuccess', options: EventOptions, cb: Callback): void +} diff --git a/packages/maskbook/src/plugins/ITO/UI/CompositionDialog.tsx b/packages/maskbook/src/plugins/ITO/UI/CompositionDialog.tsx index 3f41638533f9..70d6afeb11c9 100644 --- a/packages/maskbook/src/plugins/ITO/UI/CompositionDialog.tsx +++ b/packages/maskbook/src/plugins/ITO/UI/CompositionDialog.tsx @@ -1,10 +1,10 @@ import { useCallback, useEffect, useState } from 'react' import Web3Utils from 'web3-utils' import { DialogContent } from '@material-ui/core' -import { formatBalance, usePortalShadowRoot } from '@dimensiondev/maskbook-shared' +import { formatBalance, usePortalShadowRoot, useChainId, useAccount, TransactionStateType } from '@dimensiondev/maskbook-shared' import { useI18N, useRemoteControlledDialog } from '../../../utils' import { InjectedDialog, InjectedDialogProps } from '../../../components/shared/InjectedDialog' -import { ITO_CONSTANTS, ITO_MetaKey, MSG_DELIMITER } from '../constants' +import { ITO_MetaKey, MSG_DELIMITER } from '../constants' import { DialogTabs, JSON_PayloadInMask } from '../types' import { CreateForm } from './CreateForm' import AbstractTab, { AbstractTabProps } from '../../../components/shared/AbstractTab' @@ -13,10 +13,10 @@ import { payloadOutMask } from '../helpers' import { PoolList } from './PoolList' import { PluginITO_RPC } from '../messages' import Services from '../../../extension/service' -import { useChainId, useAccount, TransactionStateType, useConstant } from '@dimensiondev/web3-shared' import { PoolSettings, useFillCallback } from '../hooks/useFill' import { ConfirmDialog } from './ConfirmDialog' import { currentGasPriceSettings, currentGasNowSettings } from '../../Wallet/settings' +import { useITO_ContractAddress } from '../contracts/useITO_ContractAddress' import { EthereumMessages } from '../../Ethereum/messages' export enum ITOCreateFormPageStep { @@ -35,7 +35,7 @@ export function CompositionDialog(props: CompositionDialogProps) { const account = useAccount() const chainId = useChainId() - const ITO_CONTRACT_ADDRESS = useConstant(ITO_CONSTANTS, 'ITO_CONTRACT_ADDRESS') + const ITO_CONTRACT_ADDRESS = useITO_ContractAddress() //#region step const [step, setStep] = useState(ITOCreateFormPageStep.NewItoPage) diff --git a/packages/maskbook/src/plugins/ITO/UI/CreateForm.tsx b/packages/maskbook/src/plugins/ITO/UI/CreateForm.tsx index 0381a488fe62..4f39fab7b065 100644 --- a/packages/maskbook/src/plugins/ITO/UI/CreateForm.tsx +++ b/packages/maskbook/src/plugins/ITO/UI/CreateForm.tsx @@ -27,6 +27,7 @@ import { EthereumWalletConnectedBoundary } from '../../../web3/UI/EthereumWallet import { EthereumERC20TokenApprovedBoundary } from '../../../web3/UI/EthereumERC20TokenApprovedBoundary' import { AdvanceSetting } from './AdvanceSetting' import type { AdvanceSettingData } from './AdvanceSetting' +import { useITO_ContractAddress } from '../contracts/useITO_ContractAddress' import { useRegionSelect, regionCodes, encodeRegionCode, decodeRegionCode } from '../hooks/useRegion' import { RegionSelect } from './RegionSelect' import { DateTimePanel } from '../../../web3/UI/DateTimePanel' @@ -103,7 +104,7 @@ export function CreateForm(props: CreateFormProps) { const classes = useStylesExtends(useStyles(), props) const account = useAccount() - const ITO_CONTRACT_ADDRESS = useConstant(ITO_CONSTANTS, 'ITO_CONTRACT_ADDRESS') + const ITO_CONTRACT_ADDRESS = useITO_ContractAddress() const DEFAULT_QUALIFICATION_ADDRESS = useConstant(ITO_CONSTANTS, 'DEFAULT_QUALIFICATION_ADDRESS') const currentIdentity = useCurrentIdentity() diff --git a/packages/maskbook/src/plugins/ITO/UI/ITO.tsx b/packages/maskbook/src/plugins/ITO/UI/ITO.tsx index 0cadef2ef4e6..0cd77a672146 100644 --- a/packages/maskbook/src/plugins/ITO/UI/ITO.tsx +++ b/packages/maskbook/src/plugins/ITO/UI/ITO.tsx @@ -10,6 +10,10 @@ import { useChainId, useChainIdValid, useAccount, + useConstant, + TOKEN_CONSTANTS, + isSameAddress, + getChainDetailed, } from '@dimensiondev/web3-shared' import { WalletMessages } from '../../Wallet/messages' import { ITO_Status, JSON_PayloadInMask } from '../types' @@ -180,11 +184,17 @@ interface TokenItemProps { const TokenItem = ({ price, token, exchangeToken }: TokenItemProps) => { const classes = useStyles({}) + const NATIVE_TOKEN_ADDRESS = useConstant(TOKEN_CONSTANTS, 'NATIVE_TOKEN_ADDRESS') + return ( <> - {price} {exchangeToken.symbol} / {token.symbol} + {price}{' '} + {isSameAddress(exchangeToken.address, NATIVE_TOKEN_ADDRESS) + ? getChainDetailed(exchangeToken.chainId)?.nativeCurrency.symbol + : exchangeToken.symbol}{' '} + / {token.symbol} ) diff --git a/packages/maskbook/src/plugins/ITO/UI/PoolInList.tsx b/packages/maskbook/src/plugins/ITO/UI/PoolInList.tsx index 8246cf1a6eeb..7b14315fddce 100644 --- a/packages/maskbook/src/plugins/ITO/UI/PoolInList.tsx +++ b/packages/maskbook/src/plugins/ITO/UI/PoolInList.tsx @@ -15,7 +15,7 @@ import { import BigNumber from 'bignumber.js' import { useI18N } from '../../../utils' import ActionButton from '../../../extension/options-page/DashboardComponents/ActionButton' -import { useAccount } from '@dimensiondev/web3-shared' +import { useAccount, useConstant, TOKEN_CONSTANTS, isSameAddress, getChainDetailed } from '@dimensiondev/web3-shared' import { useAvailabilityComputed } from '../hooks/useAvailabilityComputed' import { usePoolTradeInfo } from '../hooks/usePoolTradeInfo' import { TokenIcon } from '../../../extension/options-page/DashboardComponents/TokenIcon' @@ -109,12 +109,9 @@ export function PoolInList(props: PoolInListProps) { const classes = useStyles() const { pool, exchange_in_volumes, exchange_out_volumes, onSend, onWithdraw } = props + const NATIVE_TOKEN_ADDRESS = useConstant(TOKEN_CONSTANTS, 'NATIVE_TOKEN_ADDRESS') const account = useAccount() - const { - value: availability, - computed: availabilityComputed, - loading: loadingAvailability, - } = useAvailabilityComputed(pool) + const { computed: availabilityComputed, loading: loadingAvailability } = useAvailabilityComputed(pool) const { value: tradeInfo, loading: loadingTradeInfo } = usePoolTradeInfo(pool.pid, account) const title = pool.message.split(MSG_DELIMITER)[1] ?? pool.message const noRemain = isZero(pool.total_remaining) @@ -232,7 +229,9 @@ export function PoolInList(props: PoolInListProps) { align="center" size="small" style={{ whiteSpace: 'nowrap' }}> - {token.symbol} + {isSameAddress(token.address, NATIVE_TOKEN_ADDRESS) + ? getChainDetailed(token.chainId)?.nativeCurrency.symbol + : token.symbol} {formatBalance( @@ -249,7 +248,10 @@ export function PoolInList(props: PoolInListProps) { token.decimals, 6, )}{' '} - {token.symbol} / {pool.token.symbol} + {isSameAddress(token.address, NATIVE_TOKEN_ADDRESS) + ? getChainDetailed(token.chainId)?.nativeCurrency.symbol + : token.symbol}{' '} + / {pool.token.symbol} ({ display: 'flex', alignItems: 'center', marginTop: theme.spacing(2), + padding: theme.spacing(2.5, 0, 3.5, 2), }, tokenIcon: { display: 'flex', diff --git a/packages/maskbook/src/plugins/ITO/UI/ShareDialog.tsx b/packages/maskbook/src/plugins/ITO/UI/ShareDialog.tsx index 1e2ce7c5a8a0..de44572991ef 100644 --- a/packages/maskbook/src/plugins/ITO/UI/ShareDialog.tsx +++ b/packages/maskbook/src/plugins/ITO/UI/ShareDialog.tsx @@ -73,31 +73,29 @@ export function ShareDialog(props: ShareDialogProps) { }, [shareSuccessLink, onClose]) return ( - <> - -
- - {amount} - - - {token.symbol} - - - {isZero(actualSwapAmount) ? t('plugin_ito_out_of_stock_hit') : t('plugin_ito_congratulations')} - - {shareSuccessLink ? ( - - {t('plugin_ito_dialog_swap_share_title')} - - ) : null} -
-
- + +
+ + {amount} + + + {token.symbol} + + + {isZero(actualSwapAmount) ? t('plugin_ito_out_of_stock_hit') : t('plugin_ito_congratulations')} + + {shareSuccessLink ? ( + + {t('plugin_ito_dialog_swap_share_title')} + + ) : null} +
+
) } diff --git a/packages/maskbook/src/plugins/ITO/UI/SwapDialog.tsx b/packages/maskbook/src/plugins/ITO/UI/SwapDialog.tsx index 952565f4b21f..220a3cb2e068 100644 --- a/packages/maskbook/src/plugins/ITO/UI/SwapDialog.tsx +++ b/packages/maskbook/src/plugins/ITO/UI/SwapDialog.tsx @@ -13,7 +13,6 @@ import { ChainId, TransactionStateType, useTokenBalance, - useConstant, resolveTransactionLinkOnExplorer, useChainId, isNative, @@ -24,9 +23,9 @@ import { TokenAmountPanel } from '../../../web3/UI/TokenAmountPanel' import { useSwapCallback } from '../hooks/useSwapCallback' import { useStylesExtends } from '../../../components/custom-ui-helper' import type { JSON_PayloadInMask } from '../types' -import { ITO_CONSTANTS } from '../constants' import { SwapStatus } from './SwapGuide' import { EthereumMessages } from '../../Ethereum/messages' +import { useITO_ContractAddress } from '../contracts/useITO_ContractAddress' import { EthereumERC20TokenApprovedBoundary } from '../../../web3/UI/EthereumERC20TokenApprovedBoundary' import { EthereumWalletConnectedBoundary } from '../../../web3/UI/EthereumWalletConnectedBoundary' import { useQualificationVerify } from '../hooks/useQualificationVerify' @@ -117,7 +116,7 @@ export function SwapDialog(props: SwapDialogProps) { const chainId = useChainId() const classes = useStylesExtends(useStyles(), props) - const ITO_CONTRACT_ADDRESS = useConstant(ITO_CONSTANTS, 'ITO_CONTRACT_ADDRESS') + const ITO_CONTRACT_ADDRESS = useITO_ContractAddress() const [ratio, setRatio] = useState( new BigNumber(payload.exchange_amounts[0 * 2]).dividedBy(payload.exchange_amounts[0 * 2 + 1]), diff --git a/packages/maskbook/src/plugins/ITO/UI/UnlockDialog.tsx b/packages/maskbook/src/plugins/ITO/UI/UnlockDialog.tsx index 91f917051449..32a2fa25a7ab 100644 --- a/packages/maskbook/src/plugins/ITO/UI/UnlockDialog.tsx +++ b/packages/maskbook/src/plugins/ITO/UI/UnlockDialog.tsx @@ -6,9 +6,7 @@ import { formatBalance, FormattedAddress, isGreaterThan, pow10 } from '@dimensio import { useRemoteControlledDialog, useI18N } from '../../../utils' import ActionButton from '../../../extension/options-page/DashboardComponents/ActionButton' import { - useAccount, useChainId, - useConstant, useTokenBalance, resolveAddressLinkOnExplorer, ERC20TokenDetailed, @@ -17,8 +15,8 @@ import { import { EthereumERC20TokenApprovedBoundary } from '../../../web3/UI/EthereumERC20TokenApprovedBoundary' import { EthereumWalletConnectedBoundary } from '../../../web3/UI/EthereumWalletConnectedBoundary' import { TokenAmountPanel } from '../../../web3/UI/TokenAmountPanel' +import { useITO_ContractAddress } from '../contracts/useITO_ContractAddress' import { SelectTokenDialogEvent, WalletMessages } from '../../Wallet/messages' -import { ITO_CONSTANTS } from '../constants' function isMoreThanMillion(allowance: string, decimals: number) { return isGreaterThan(allowance, `100000000000e${decimals}`) // 100 billion @@ -43,10 +41,8 @@ export function UnlockDialog(props: UnlockDialogProps) { const { tokens } = props const { t } = useI18N() const classes = useStyles() - const ITO_CONTRACT_ADDRESS = useConstant(ITO_CONSTANTS, 'ITO_CONTRACT_ADDRESS') + const ITO_CONTRACT_ADDRESS = useITO_ContractAddress() const recipientAddress = ITO_CONTRACT_ADDRESS - - const account = useAccount() const chainId = useChainId() //#region select token diff --git a/packages/maskbook/src/plugins/ITO/constants.ts b/packages/maskbook/src/plugins/ITO/constants.ts index f1b8c2e3649f..444b8bb4fd5f 100644 --- a/packages/maskbook/src/plugins/ITO/constants.ts +++ b/packages/maskbook/src/plugins/ITO/constants.ts @@ -13,9 +13,9 @@ export const ITO_CONSTANTS = { [ChainId.Kovan]: '', [ChainId.Gorli]: '', [ChainId.BSC]: '', - [ChainId.BSCT]: '0x153466dc03dd36b85c06cb51973a2e81397fca51', + [ChainId.BSCT]: '', [ChainId.Matic]: '', - [ChainId.Mumbai]: '0x153466dC03DD36b85c06Cb51973a2E81397fcA51', + [ChainId.Mumbai]: '', }, MASK_ITO_CONTRACT_ADDRESS: { [ChainId.Mainnet]: '0x86812da3A623ab9606976078588b80C315E55FA3', @@ -28,16 +28,27 @@ export const ITO_CONSTANTS = { [ChainId.Matic]: '', [ChainId.Mumbai]: '', }, + ITO_BSC_POLYGON_CONTRACT_ADDRESS: { + [ChainId.Mainnet]: '', + [ChainId.Ropsten]: '', + [ChainId.Rinkeby]: '', + [ChainId.Kovan]: '', + [ChainId.Gorli]: '', + [ChainId.BSC]: '0x54a0A221C25Fc0a347EC929cFC5db0be17fA2a2B', + [ChainId.BSCT]: '0x981be454a930479d92C91a0092D204b64845A5D6', + [ChainId.Matic]: '0x981be454a930479d92C91a0092D204b64845A5D6', + [ChainId.Mumbai]: '0x54a0A221C25Fc0a347EC929cFC5db0be17fA2a2B', + }, DEFAULT_QUALIFICATION_ADDRESS: { [ChainId.Mainnet]: '0x81b6ae377e360dcad63611846a2516f4ba8c88ac', [ChainId.Ropsten]: '0x050745919acaa000e5b116b2c499e6f4ed5ce5b6', [ChainId.Rinkeby]: '0x88AA0AB3B7cDE263073e1cBa1D06473adeC1b38E', [ChainId.Kovan]: '', [ChainId.Gorli]: '', - [ChainId.BSC]: '', - [ChainId.BSCT]: '0x0061E06c9f640a03C4981f43762d2AE5e03873c5', - [ChainId.Matic]: '', - [ChainId.Mumbai]: '0xe7a945e915E7c17f3263b03ac1bb84fb89410c3a', + [ChainId.BSC]: '0x5B966f3a32Db9C180843bCb40267A66b73E4f022', + [ChainId.BSCT]: '0x54a0A221C25Fc0a347EC929cFC5db0be17fA2a2B', + [ChainId.Matic]: '0x02Ea0720254F7fa4eca7d09A1b9C783F1020EbEF', + [ChainId.Mumbai]: '0x5B966f3a32Db9C180843bCb40267A66b73E4f022', }, SUBGRAPH_URL: { [ChainId.Mainnet]: 'https://api.thegraph.com/subgraphs/name/dimensiondev/mask-ito-mainnet', @@ -45,9 +56,9 @@ export const ITO_CONSTANTS = { [ChainId.Rinkeby]: '', [ChainId.Kovan]: '', [ChainId.Gorli]: '', - [ChainId.BSC]: '', + [ChainId.BSC]: 'https://api.thegraph.com/subgraphs/name/dimensiondev/mask-ito-bsc-mainnet', [ChainId.BSCT]: '', - [ChainId.Matic]: '', + [ChainId.Matic]: 'https://api.thegraph.com/subgraphs/name/dimensiondev/mask-ito-polygon', [ChainId.Mumbai]: '', }, } diff --git a/packages/maskbook/src/plugins/ITO/contracts/useITO_Contract.ts b/packages/maskbook/src/plugins/ITO/contracts/useITO_Contract.ts index 46ccf3ae0796..ce30df0f686a 100644 --- a/packages/maskbook/src/plugins/ITO/contracts/useITO_Contract.ts +++ b/packages/maskbook/src/plugins/ITO/contracts/useITO_Contract.ts @@ -1,10 +1,20 @@ import type { AbiItem } from 'web3-utils' import ITO_ABI from '@dimensiondev/contracts/abis/ITO.json' +import ITO_BSC_POLYGON_ABI from '@dimensiondev/contracts/abis/BscPolygonITO.json' import type { ITO } from '@dimensiondev/contracts/types/ITO' +import type { BscPolygonITO } from '@dimensiondev/contracts/types/BscPolygonITO' import { ITO_CONSTANTS } from '../constants' -import { useConstant, useContract } from '@dimensiondev/web3-shared' +import { useConstant, useContract, useNetworkType, NetworkType } from '@dimensiondev/web3-shared' export function useITO_Contract(contractAddress?: string) { const ITO_CONTRACT_ADDRESS = useConstant(ITO_CONSTANTS, 'ITO_CONTRACT_ADDRESS') - return useContract(contractAddress ?? ITO_CONTRACT_ADDRESS, ITO_ABI as AbiItem[]) + const ITO_BSC_POLYGON_CONTRACT_ADDRESS = useConstant(ITO_CONSTANTS, 'ITO_BSC_POLYGON_CONTRACT_ADDRESS') + const ITO_CONTRACT = useContract(contractAddress ?? ITO_CONTRACT_ADDRESS, ITO_ABI as AbiItem[]) + const ITO_BSC_POLYGON_CONTRACT = useContract( + contractAddress ?? ITO_BSC_POLYGON_CONTRACT_ADDRESS, + ITO_BSC_POLYGON_ABI as AbiItem[], + ) + const networkType = useNetworkType() + + return networkType === NetworkType.Ethereum ? ITO_CONTRACT : ITO_BSC_POLYGON_CONTRACT } diff --git a/packages/maskbook/src/plugins/ITO/contracts/useITO_ContractAddress.ts b/packages/maskbook/src/plugins/ITO/contracts/useITO_ContractAddress.ts new file mode 100644 index 000000000000..3dca7c2118e1 --- /dev/null +++ b/packages/maskbook/src/plugins/ITO/contracts/useITO_ContractAddress.ts @@ -0,0 +1,10 @@ +import { ITO_CONSTANTS } from '../constants' +import { useConstant, useNetworkType, NetworkType } from '@dimensiondev/web3-shared' + +export function useITO_ContractAddress() { + const ITO_CONTRACT_ADDRESS = useConstant(ITO_CONSTANTS, 'ITO_CONTRACT_ADDRESS') + const ITO_BSC_POLYGON_CONTRACT_ADDRESS = useConstant(ITO_CONSTANTS, 'ITO_BSC_POLYGON_CONTRACT_ADDRESS') + const networkType = useNetworkType() + + return networkType === NetworkType.Ethereum ? ITO_CONTRACT_ADDRESS : ITO_BSC_POLYGON_CONTRACT_ADDRESS +} diff --git a/packages/maskbook/src/social-network-adaptor/twitter.com/customization/custom.ts b/packages/maskbook/src/social-network-adaptor/twitter.com/customization/custom.ts index 19499d8b9f31..7cef591cd215 100644 --- a/packages/maskbook/src/social-network-adaptor/twitter.com/customization/custom.ts +++ b/packages/maskbook/src/social-network-adaptor/twitter.com/customization/custom.ts @@ -133,6 +133,7 @@ export const useInjectedDialogClassesOverwriteTwitter = makeStyles((theme) => ({ }, paper: { width: '600px !important', + maxWidth: 'none', boxShadow: 'none', backgroundImage: 'none', [`@media (max-width: ${theme.breakpoints.values.sm}px)`]: {