Skip to content

Commit

Permalink
Remove contracts related code (#66)
Browse files Browse the repository at this point in the history
* Remove contract related code

* remove everything contract related

* lint
  • Loading branch information
Szegoo authored Apr 15, 2024
1 parent b08d6aa commit 3e32e97
Show file tree
Hide file tree
Showing 31 changed files with 97 additions and 4,625 deletions.
3 changes: 0 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
WS_CORETIME_CHAIN="WSS endpoint of the coretime chain"
WS_RELAY_CHAIN="WSS endpoint of the coretime relay chain"
WS_CONTRACTS_CHAIN="WSS endpoint of the contracts chain"
CONTRACT_XC_REGIONS="AddressOfXcRegionsContract"
CONTRACT_MARKET="AddressOfCoretimeMarketContract"
10 changes: 9 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ module.exports = {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-var-requires': 'off',
'react/display-name': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{
vars: 'all',
varsIgnorePattern: '^_',
args: 'after-used',
argsIgnorePattern: '^_',
},
],
//#region //*=========== Unused Import ===========
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': [
Expand Down
6 changes: 0 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ COPY . .
# Set the necessary environment variables
ENV WS_CORETIME_CHAIN="ws://127.0.0.1:9910"
ENV WS_RELAY_CHAIN="ws://127.0.0.1:9900"
ENV WS_CONTRACTS_CHAIN="ws://127.0.0.1:9920"

# Given that Coretime-Mock deploys the contract with no salt we can be sure
# this is the address as long as it is not modified.
ENV CONTRACT_XC_REGIONS="bA3hAXgbErTUWg8uSkcPhuqqHyF1em6AfPbATH9g9QM4HJP"
ENV CONTRACT_MARKET="WdSbRZeLbQm1CqFwWhHoGTvH51Fs1rbQTLHhRDSqDpq4a2b"

RUN apk add --no-cache libc6-compat

Expand Down
3 changes: 0 additions & 3 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ const nextConfig = {
env: {
WS_CORETIME_CHAIN: process.env.WS_CORETIME_CHAIN || '',
WS_RELAY_CHAIN: process.env.WS_RELAY_CHAIN,
WS_CONTRACTS_CHAIN: process.env.WS_CONTRACTS_CHAIN,
CONTRACT_XC_REGIONS: process.env.CONTRACT_XC_REGIONS,
CONTRACT_MARKET: process.env.CONTRACT_MARKET,
},
};

Expand Down
4 changes: 2 additions & 2 deletions src/components/Elements/RegionCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ const RegionCardInner = ({
};

const locationToLabel = (location: RegionLocation): string => {
if (location === RegionLocation.CONTRACTS_CHAIN) {
return 'Contracts Chain';
if (location === RegionLocation.REGIONX_CHAIN) {
return 'RegionX Chain';
} else if (location === RegionLocation.MARKET) {
return 'Listed on Market';
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Elements/Selectors/ChainSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const ChainSelector = ({ chain, setChain }: ChainSelectorProps) => {
onChange={(e) => setChain(e.target.value)}
>
<MenuItem value='CoretimeChain'>Coretime Chain</MenuItem>
<MenuItem value='ContractsChain'>Contracts Chain</MenuItem>
<MenuItem value='RegionXChain'>RegionX Chain</MenuItem>
</Select>
</FormControl>
);
Expand Down
27 changes: 4 additions & 23 deletions src/components/Modals/Purchase/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import {
DialogContent,
Stack,
} from '@mui/material';
import { contractTx, useContract, useInkathon } from '@scio-labs/use-inkathon';
import { useInkathon } from '@scio-labs/use-inkathon';
import { useState } from 'react';

import { ListingCard } from '@/components/Elements/ListingCard';

import { CONTRACT_MARKET } from '@/contexts/apis/consts';
import { useToast } from '@/contexts/toast';
import MarketMetadata from '@/contracts/market.json';
import { Listing } from '@/models';

interface PurchaseModalProps {
Expand All @@ -27,38 +25,21 @@ export const PurchaseModal = ({
onClose,
listing,
}: PurchaseModalProps) => {
const { activeAccount, api: contractsApi } = useInkathon();

const { contract: marketContract } = useContract(
MarketMetadata,
CONTRACT_MARKET
);
const { activeAccount, api } = useInkathon();

const { toastError, toastSuccess } = useToast();

const [working, setWorking] = useState(false);

const purchaseRegion = async () => {
if (!contractsApi || !activeAccount || !marketContract) {
if (!api || !activeAccount) {
return;
}

try {
setWorking(true);
const rawRegionId = listing.region.getEncodedRegionId(contractsApi);

const id = contractsApi.createType('Id', {
U128: rawRegionId.toString(),
});

await contractTx(
contractsApi,
activeAccount.address,
marketContract,
'purchase_region',
{ value: listing.currentPrice },
[id, listing.region.getMetadataVersion()]
);
// TODO

toastSuccess(`Successfully purchased region from sale.`);
onClose();
Expand Down
61 changes: 11 additions & 50 deletions src/components/Modals/Sell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@ import {
Stack,
Typography,
} from '@mui/material';
import { contractTx, useContract, useInkathon } from '@scio-labs/use-inkathon';
import { useInkathon } from '@scio-labs/use-inkathon';
import { Region } from 'coretime-utils';
import { useEffect, useState } from 'react';

import { AmountInput, RegionCard } from '@/components/Elements';
import { RecipientSelector } from '@/components/Elements/Selectors/RecipientSelector';

import { CONTRACT_MARKET, CONTRACT_XC_REGIONS } from '@/contexts/apis/consts';
import { useRegions } from '@/contexts/regions';
import { useToast } from '@/contexts/toast';
import MarketMetadata from '@/contracts/market.json';
import XcRegionsMetadata from '@/contracts/xc_regions.json';
import { CONTRACT_DECIMALS, LISTING_DEPOSIT, RegionMetadata } from '@/models';
import { RegionMetadata } from '@/models';

interface SellModalProps {
open: boolean;
Expand All @@ -33,16 +30,7 @@ export const SellModal = ({
onClose,
regionMetadata,
}: SellModalProps) => {
const { activeAccount, api: contractsApi } = useInkathon();

const { contract: xcRegionsContract } = useContract(
XcRegionsMetadata,
CONTRACT_XC_REGIONS
);
const { contract: marketContract } = useContract(
MarketMetadata,
CONTRACT_MARKET
);
const { activeAccount, api } = useInkathon();

const { fetchRegions } = useRegions();
const { toastError, toastSuccess } = useToast();
Expand All @@ -62,24 +50,15 @@ export const SellModal = ({
await listRegion(regionMetadata.region);
};

const approveXcRegion = async (region: Region) => {
if (!contractsApi || !activeAccount || !xcRegionsContract) {
const approveXcRegion = async (_region: Region) => {
if (!api || !activeAccount) {
return;
}

try {
setWorking(true);
const rawRegionId = region.getEncodedRegionId(contractsApi);
const id = contractsApi.createType('Id', { U128: rawRegionId });

await contractTx(
contractsApi,
activeAccount.address,
xcRegionsContract,
'PSP34::approve',
{},
[CONTRACT_MARKET, id, true]
);

// TODO

toastSuccess(`Successfully approved region to the market.`);
setWorking(false);
Expand All @@ -93,33 +72,15 @@ export const SellModal = ({
}
};

const listRegion = async (region: Region) => {
if (!contractsApi || !activeAccount || !marketContract) {
const listRegion = async (_region: Region) => {
if (!api || !activeAccount) {
return;
}

try {
setWorking(true);
const rawRegionId = region.getEncodedRegionId(contractsApi);

const id = contractsApi.createType('Id', {
U128: rawRegionId.toString(),
});
const regionDuration = region.getEnd() - region.getBegin();
const timeslicePrice = (
(Number(regionPrice) * Math.pow(10, CONTRACT_DECIMALS)) /
regionDuration /
region.coreOccupancy()
).toFixed(0);

await contractTx(
contractsApi,
activeAccount.address,
marketContract,
'list_region',
{ value: LISTING_DEPOSIT },
[id, timeslicePrice, saleRecipient ? saleRecipient : null]
);

// TODO

toastSuccess(`Successfully listed region on sale.`);
onClose();
Expand Down
42 changes: 3 additions & 39 deletions src/components/Modals/Transfer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,17 @@ import {
TextField,
Typography,
} from '@mui/material';
import { useContract, useInkathon } from '@scio-labs/use-inkathon';
import { useInkathon } from '@scio-labs/use-inkathon';
import { Region } from 'coretime-utils';
import { useEffect, useState } from 'react';

import {
transferRegionOnContractsChain,
transferRegionOnCoretimeChain,
} from '@/utils/native/transfer';
import { transferRegionOnCoretimeChain } from '@/utils/native/transfer';

import { RegionCard } from '@/components/Elements';

import { useCoretimeApi } from '@/contexts/apis';
import { CONTRACT_XC_REGIONS } from '@/contexts/apis/consts';
import { useRegions } from '@/contexts/regions';
import { useToast } from '@/contexts/toast';
import XcRegionsMetadata from '@/contracts/xc_regions.json';
import { RegionLocation, RegionMetadata } from '@/models';

interface TransferModalProps {
Expand All @@ -38,8 +33,7 @@ export const TransferModal = ({
onClose,
regionMetadata,
}: TransferModalProps) => {
const { activeAccount, activeSigner, api: contractsApi } = useInkathon();
const { contract } = useContract(XcRegionsMetadata, CONTRACT_XC_REGIONS);
const { activeAccount, activeSigner } = useInkathon();

const { fetchRegions } = useRegions();
const { toastError, toastInfo, toastSuccess } = useToast();
Expand All @@ -53,8 +47,6 @@ export const TransferModal = ({
const onTransfer = () => {
if (regionMetadata.location === RegionLocation.CORETIME_CHAIN) {
transferCoretimeRegion(regionMetadata.region);
} else if (regionMetadata.location === RegionLocation.CONTRACTS_CHAIN) {
transferXcRegion(regionMetadata.region);
}
};

Expand Down Expand Up @@ -89,34 +81,6 @@ export const TransferModal = ({
);
};

const transferXcRegion = async (region: Region) => {
if (!contractsApi || !activeAccount || !contract) {
return;
}

setWorking(true);
transferRegionOnContractsChain(
{ contractsApi, xcRegionsContract: contract, marketContract: undefined },
region,
activeAccount.address,
newOwner,
{
ready: () => toastInfo('Transaction was initiated.'),
inBlock: () => toastInfo(`In Block`),
finalized: () => setWorking(false),
success: () => {
toastSuccess('Successfully transferred the region.');
onClose();
fetchRegions();
},
error: () => {
toastError(`Failed to transfer the region.`);
setWorking(false);
},
}
);
};

useEffect(() => {
setNewOwner('');
}, [open]);
Expand Down
29 changes: 5 additions & 24 deletions src/components/Modals/Unlist/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ import {
DialogContent,
Stack,
} from '@mui/material';
import { contractTx, useContract, useInkathon } from '@scio-labs/use-inkathon';
import { useInkathon } from '@scio-labs/use-inkathon';
import { Region } from 'coretime-utils';
import { useState } from 'react';

import { RegionCard } from '@/components/Elements';

import { CONTRACT_MARKET } from '@/contexts/apis/consts';
import { useMarket } from '@/contexts/market';
import { useRegions } from '@/contexts/regions';
import { useToast } from '@/contexts/toast';
import MarketMetadata from '@/contracts/market.json';
import { RegionMetadata } from '@/models';

interface UnlistModalProps {
Expand All @@ -30,40 +28,23 @@ export const UnlistModal = ({
onClose,
regionMetadata,
}: UnlistModalProps) => {
const { activeAccount, api: contractsApi } = useInkathon();

const { contract: marketContract } = useContract(
MarketMetadata,
CONTRACT_MARKET
);
const { activeAccount, api } = useInkathon();

const { fetchRegions } = useRegions();
const { fetchMarket } = useMarket();
const { toastError, toastSuccess } = useToast();

const [working, setWorking] = useState(false);

const unlistRegion = async (region: Region) => {
if (!contractsApi || !activeAccount || !marketContract) {
const unlistRegion = async (_region: Region) => {
if (!api || !activeAccount) {
return;
}

try {
setWorking(true);
const rawRegionId = region.getEncodedRegionId(contractsApi);

const id = contractsApi.createType('Id', {
U128: rawRegionId.toString(),
});

await contractTx(
contractsApi,
activeAccount.address,
marketContract,
'unlist_region',
{},
[id]
);
// TODO

toastSuccess(`Successfully unlisted region from sale.`);
onClose();
Expand Down
2 changes: 1 addition & 1 deletion src/components/Modals/WalletConnect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
List,
ListItemButton,
} from '@mui/material';
import { isWalletInstalled,SubstrateWallet } from '@scio-labs/use-inkathon';
import { isWalletInstalled, SubstrateWallet } from '@scio-labs/use-inkathon';
import { allSubstrateWallets, useInkathon } from '@scio-labs/use-inkathon';
import Image from 'next/image';

Expand Down
Loading

0 comments on commit 3e32e97

Please sign in to comment.