Skip to content

Commit

Permalink
sort by asc price working
Browse files Browse the repository at this point in the history
RedBeardEth committed Dec 15, 2023
1 parent 1164062 commit 2dbb58d
Showing 4 changed files with 33 additions and 15 deletions.
15 changes: 8 additions & 7 deletions apps/nextjs/src/app/collection/[id]/(list)/L2ERC721Card.tsx
Original file line number Diff line number Diff line change
@@ -45,9 +45,7 @@ export const L2ERC721Card = ({
<TokenDetails
token={token}
isGrid={isGrid}
starkName={useStarkDisplayName(
token.transfers?.[0]?.toAddress ?? token.minter ?? "",
)}
starkName={useStarkDisplayName(token.owner ?? token.minter ?? "")}
/>
</Link>
</div>
@@ -126,10 +124,13 @@ const Price = ({
<div>{token?.price}</div>
</div>
)}
<div>
<h6 className="uppercase">Last price</h6>
<div>100</div>
</div>
{/*TODO Add last price sold */}
{/*token?.lastPrice && (
<div>
<h6 className="uppercase">Last price</h6>
<div>100</div>
</div>
)*/}
</div>
);
};
1 change: 1 addition & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
"dependencies": {
"@realms-world/auth": "workspace:*",
"@realms-world/db": "workspace:*",
"@realms-world/utils": "workspace:*",
"@trpc/client": "^10.44.1",
"@trpc/server": "^10.44.1",
"superjson": "2.2.1",
15 changes: 9 additions & 6 deletions packages/api/src/router/erc721Tokens.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { padAddress } from "@/utils/utils";
import { sql } from "drizzle-orm";
import { z } from "zod";

import type { SQL } from "@realms-world/db";
import { and, asc, desc, eq, gte, lte, schema } from "@realms-world/db";
import { padAddress } from "@realms-world/utils";

import { createTRPCRouter, publicProcedure } from "../trpc";

@@ -27,16 +27,19 @@ export const erc721TokensRouter = createTRPCRouter({
const { cursor, contractAddress, owner, orderBy, block, direction } =
input;
const whereFilter: SQL[] = [];
const orderByFilter: SQL[] = [];

const orderByVariable =
orderBy == "floorAskPrice"
? schema.erc721Tokens.price
: schema.erc721Tokens.token_id;
if (direction === "asc") {
orderByFilter.push(asc(orderByVariable));
const orderByFilter: SQL =
direction === "asc" ? asc(orderByVariable) : desc(orderByVariable);

/*if (direction === "asc") {
orderByFilter = asc(orderByVariable);
} else {
orderByFilter.push(desc(orderByVariable));
}
orderByFilter = desc(orderByVariable);
}*/

if (contractAddress) {
whereFilter.push(
17 changes: 15 additions & 2 deletions packages/utils/src/number.ts
Original file line number Diff line number Diff line change
@@ -152,5 +152,18 @@ function formatBN(
: "";
}
}

export { formatBN, formatNumber, toFixed };
function padAddress(address?: string) {
if (address) {
const length = address.length;
const neededLength = 66 - length;
let zeros = "";
for (let i = 0; i < neededLength; i++) {
zeros += "0";
}
const newHex = address?.substring(0, 2) + zeros + address.substring(2);
return newHex;
} else {
return "";
}
}
export { formatBN, formatNumber, toFixed, padAddress };

0 comments on commit 2dbb58d

Please sign in to comment.