Skip to content

Commit

Permalink
Merge branch 'main' of github.com:baicaiyihao/rooch into main
Browse files Browse the repository at this point in the history
  • Loading branch information
stom authored and stom committed Nov 13, 2024
2 parents d0d46ce + f280ef8 commit e3363d5
Show file tree
Hide file tree
Showing 66 changed files with 9,899 additions and 302 deletions.
415 changes: 213 additions & 202 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ rand = "0.8.5"
rand_core = { version = "0.6.3", default-features = false }
reqwest = { version = "0.12", features = ["json", "stream"] }
schemars = { version = "0.8.21", features = ["either"] }
serde = { version = "1.0.214", features = ["derive", "rc"] }
serde = { version = "1.0.215", features = ["derive", "rc"] }
serde_bytes = "0.11.15"
serde_json = { version = "1.0.132", features = ["preserve_order"] }
serde_yaml = "0.9"
Expand Down Expand Up @@ -331,7 +331,7 @@ ciborium = "0.2.1"
pprof = { version = "0.13.0", features = ["flamegraph", "criterion", "cpp", "frame-pointer", "protobuf-codec"] }
celestia-rpc = { git = "https://github.com/eigerco/celestia-node-rs.git", rev = "129272e8d926b4c7badf27a26dea915323dd6489" }
celestia-types = { git = "https://github.com/eigerco/celestia-node-rs.git", rev = "129272e8d926b4c7badf27a26dea915323dd6489" }
opendal = { version = "0.47.3", features = ["services-fs", "services-gcs"] }
opendal = { version = "0.50.2", features = ["services-fs", "services-gcs"] }
toml = "0.8.19"
tabled = "0.16.0"
csv = "1.3.1"
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-da/src/backend/openda/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub(crate) async fn new_operator(
let operator: Box<dyn Operator> = match scheme {
OpenDAScheme::Avail => Box::new(AvailClient::new(&config["endpoint"])?),
_ => {
let mut op = opendal::Operator::via_map(Scheme::from(scheme), config)?;
let mut op = opendal::Operator::via_iter(Scheme::from(scheme), config)?;
let max_times = max_retry_times.unwrap_or(DEFAULT_MAX_RETRY_TIMES);
op = op
.layer(RetryLayer::new().with_max_times(max_times))
Expand Down
2 changes: 1 addition & 1 deletion infra/rooch-portal-v2/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = {
'react/jsx-no-useless-fragment': [1, { allowExpressions: true }],
'react/no-unstable-nested-components': [1, { allowAsProps: true }],
'react/jsx-no-duplicate-props': [1, { ignoreCase: false }],
'react-refresh/only-export-components': 'warn',
'react-refresh/only-export-components': 0,
// jsx-a11y
'jsx-a11y/anchor-is-valid': 0,
'jsx-a11y/control-has-associated-label': 0,
Expand Down
4 changes: 4 additions & 0 deletions infra/rooch-portal-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@tanstack/react-query": "^5.51.11",
"@types/react-copy-to-clipboard": "^5.0.7",
"@types/react-syntax-highlighter": "^15.5.13",
"ahooks": "^3.8.1",
"autoprefixer": "^10.4.19",
"autosuggest-highlight": "^3.3.4",
"axios": "^1.7.7",
Expand All @@ -59,10 +60,13 @@
"postcss": "^8.4.39",
"react": "^18.3.1",
"react-copy-to-clipboard": "^5.1.0",
"react-countup": "^6.5.3",
"react-dom": "^18.3.1",
"react-hook-form": "^7.51.5",
"react-spinners": "^0.14.1",
"react-syntax-highlighter": "^15.5.0",
"react-use": "^17.5.1",
"react-use-pagination": "^2.0.1",
"simplebar-react": "^3.2.5",
"sonner": "^1.5.0",
"stylis": "^4.3.2",
Expand Down
13 changes: 13 additions & 0 deletions infra/rooch-portal-v2/src/app/trade/[tick]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import MarketplaceView from 'src/sections/trade/view';

export const metadata = {
title: 'Market | Orderbook',
};

export default function Page({ params }: { params: { tick: string } }) {
// if (!Object.keys(NETWORK_PACKAGE[NETWORK].tickInfo).includes(tick)) {
// return <NotMarketplaceFoundView />;
// }

return <MarketplaceView params={params} />;
}
11 changes: 11 additions & 0 deletions infra/rooch-portal-v2/src/app/trade/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import HomeView from 'src/sections/trade/home-view';

// ----------------------------------------------------------------------

export const metadata = {
title: 'Market | Orderbook',
};

export default function Page() {
return <HomeView />;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import type { ReactNode } from 'react';

import { useState, useEffect } from 'react';
import {
useRemoveSession,
useCurrentSession,
useCreateSessionKey,
} from '@roochnetwork/rooch-sdk-kit';
import { useCurrentSession, useCreateSessionKey } from '@roochnetwork/rooch-sdk-kit';

import { LoadingButton } from '@mui/lab';

Expand All @@ -16,7 +12,6 @@ import { toast } from 'src/components/snackbar';
export default function SessionKeyGuardButton({ children }: { children: ReactNode }) {
const sessionKey = useCurrentSession();
const { mutateAsync: createSessionKey } = useCreateSessionKey();
const { mutateAsync: removeSessionKey } = useRemoveSession();
const [sessionKeyLoading, setSessionKeyLoading] = useState(false);

const [isCurrentSessionExpired, setIsCurrentSessionExpired] = useState(false);
Expand Down
279 changes: 279 additions & 0 deletions infra/rooch-portal-v2/src/components/market/accept-bid-dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
import type { BalanceInfoView } from '@roochnetwork/rooch-sdk';
import type { BidItem } from 'src/hooks/trade/use-market-data';

import { useMemo } from 'react';
import BigNumber from 'bignumber.js';
import { Args, Transaction } from '@roochnetwork/rooch-sdk';
import { useCurrentAddress, UseSignAndExecuteTransaction } from '@roochnetwork/rooch-sdk-kit';

import { LoadingButton } from '@mui/lab';
import { yellow } from '@mui/material/colors';
import {
Card,
Chip,
Stack,
Dialog,
Button,
Typography,
DialogTitle,
DialogContent,
DialogActions,
} from '@mui/material';

import { fNumber } from 'src/utils/format-number';
import { fromDust, formatNumber } from 'src/utils/number';

import { secondary } from 'src/theme/core';
import { TESTNET_ORDERBOOK_PACKAGE } from 'src/config/constant';

import { toast } from 'src/components/snackbar';
import { Iconify } from 'src/components/iconify';

import InscriptionShopCard from './inscription-shop-card';

export type AcceptBidDialogProps = {
open: boolean;
acceptBidItem: BidItem;
tokenBalance: string;
tick: string;
fromCoinBalanceInfo: BalanceInfoView;
toCoinBalanceInfo: BalanceInfoView;
refreshBidList: () => Promise<void>;
close: () => void;
};

// function makeAcceptBidTxb(
// targetAmount: number,
// userOwnedTickInscription: InscriptionObject[],
// selectedBid: BidItemObject,
// address: string,
// tick: string
// ) {
// const tx = new Transaction();
// const sortedData = userOwnedTickInscription.sort(
// (a, b) => Number(b.data.content.fields.amount) - Number(a.data.content.fields.amount)
// );
// const firstItem = sortedData[0];
// const opSortedData = sortedData.length === 1 ? [sortedData[0]] : sortedData.slice(1);
// let currentTotal = new BigNumber(firstItem.data.content.fields.amount);
// let inputInscription:
// | {
// index: number;
// resultIndex: number;
// kind: 'NestedResult';
// }
// | undefined;
// // eslint-disable-next-line no-restricted-syntax
// for (const inscription of opSortedData) {
// const inscriptionData = inscription.data.content.fields;
// if (new BigNumber(currentTotal).isLessThanOrEqualTo(targetAmount)) {
// tx.callFunction({
// target: `${NETWORK_PACKAGE[NETWORK].MOVESCRIPTIONS_PACKAGE_ID}::movescription::merge`,
// args: [Args.objectId(firstItem.data.objectId), Args.objectId(inscription.data.objectId)],
// });
// currentTotal = currentTotal.plus(inscriptionData.amount);

// if (currentTotal.isEqualTo(targetAmount)) {
// break;
// }
// } else {
// const remainingAmt = new BigNumber(targetAmount).minus(currentTotal);
// if (remainingAmt.isLessThan(0)) {
// const [final] = tx.callFunction({
// target: `${NETWORK_PACKAGE[NETWORK].MOVESCRIPTIONS_PACKAGE_ID}::movescription::do_split`,
// arguments: [Args.objectId(firstItem.data.objectId), Args.u64(BigInt(targetAmount))],
// });
// inputInscription = final;
// break;
// }
// }
// }

// txb.moveCall({
// target: `${NETWORK_PACKAGE[NETWORK].MARKET_PACKAGE_ID}::market::accept_bid`,
// arguments: [
// txb.object(NETWORK_PACKAGE[NETWORK].tickInfo[tick].MARKET_OBJECT_ID),
// txb.object(inputInscription || firstItem.data.objectId),
// txb.pure(selectedBid.bidder),
// txb.pure(selectedBid.bidId),
// txb.object('0x6'),
// ],
// });

// if (inputInscription) {
// txb.transferObjects([firstItem.data.objectId], address);
// }

// return txb;
// }

export default function AcceptBidDialog({
open,
acceptBidItem,
tick,
fromCoinBalanceInfo,
toCoinBalanceInfo,
tokenBalance,
refreshBidList,
close,
}: AcceptBidDialogProps) {
const { mutate: signAndExecuteTransaction, isPending } = UseSignAndExecuteTransaction();

const price = useMemo(
() => new BigNumber(acceptBidItem.unit_price).times(acceptBidItem.quantity).toString(),
[acceptBidItem.quantity, acceptBidItem.unit_price]
);

const account = useCurrentAddress();

return (
<Dialog
open={open}
onClose={close}
sx={{
'& .MuiDialog-paper': {
minWidth: {
xs: '360px',
sm: '360px',
md: '480px',
lg: '480px',
},
},
}}
>
<DialogTitle>Accept Bid</DialogTitle>

<DialogContent>
<Card
variant="outlined"
sx={{
p: 2,
}}
>
<InscriptionShopCard
objectId={acceptBidItem.order_id}
tick={tick}
// isVerified={tick.toLowerCase() === 'move'}
isVerified
amount={acceptBidItem.quantity}
price={price}
unitPrice={acceptBidItem.unit_price}
// acc={item.acc}
fromCoinBalanceInfo={fromCoinBalanceInfo}
toCoinBalanceInfo={toCoinBalanceInfo}
seller={acceptBidItem.owner}
selectMode={false}
type="list"
/>
</Card>

<Stack
direction="row"
alignItems="center"
justifyContent="space-between"
sx={{ mt: 3, mb: 0.25 }}
>
<Chip
label={
<Stack direction="row" alignItems="center">
<Iconify
icon="solar:wallet-bold"
color={yellow.A200}
width={18}
sx={{
mr: 0.5,
}}
/>
<Typography
sx={{
fontWeight: 600,
fontSize: '0.875rem',
}}
>
{tick.toUpperCase()} Balance:{' '}
{fNumber(fromDust(tokenBalance, toCoinBalanceInfo.decimals).toNumber())}
</Typography>
</Stack>
}
size="small"
variant="filled"
color="secondary"
/>
</Stack>

<Typography sx={{ mt: 3, mb: 0.5 }}>
You will receive:{' '}
<span
style={{
fontWeight: 600,
fontSize: '1.25rem',
color: secondary.light,
}}
>
{new BigNumber(price).isNaN()
? '--'
: formatNumber(fromDust(price, fromCoinBalanceInfo.decimals).toNumber())}
</span>{' '}
{fromCoinBalanceInfo.symbol}
</Typography>
</DialogContent>

<DialogActions>
<Button
onClick={() => {
close();
}}
variant="outlined"
color="inherit"
>
Cancel
</Button>
<LoadingButton
loading={isPending}
disabled={!account || new BigNumber(acceptBidItem.quantity).isGreaterThan(tokenBalance)}
onClick={() => {
if (!account || new BigNumber(acceptBidItem.quantity).isGreaterThan(tokenBalance)) {
return;
}
console.log('🚀 ~ file: accept-bid-dialog.tsx:237 ~ acceptBidItem:', acceptBidItem);

const tx = new Transaction();
tx.callFunction({
target: `${TESTNET_ORDERBOOK_PACKAGE}::market_v2::accept_bid`,
args: [
Args.objectId('0x156d9a5bfa4329f999115b5febde94eed4a37cde10637ad8eed1ba91e89e0bb7'),
Args.u64(BigInt(acceptBidItem.order_id)),
Args.address(acceptBidItem.owner),
Args.bool(true),
Args.address(account.genRoochAddress().toStr()),
],
typeArgs: [
'0x3::gas_coin::RGas',
'0x1d6f6657fc996008a1e43b8c13805e969a091560d4cea57b1db9f3ce4450d977::fixed_supply_coin::FSC',
],
});

signAndExecuteTransaction(
{
transaction: tx,
},
{
async onSuccess(data) {
toast.success('Accept bid success');
close();
refreshBidList();
},
onError(error) {
toast.error(String(error));
},
}
);
}}
variant="contained"
>
Submit
</LoadingButton>
</DialogActions>
</Dialog>
);
}
Loading

0 comments on commit e3363d5

Please sign in to comment.