Skip to content

Commit

Permalink
Merge pull request #177 from shawakash/go2
Browse files Browse the repository at this point in the history
chore: change the txn table attributes to hold Txn Type present in @paybox/mote
  • Loading branch information
shawakash authored Mar 7, 2024
2 parents 4aa3bd2 + 4056d42 commit 361e5eb
Show file tree
Hide file tree
Showing 39 changed files with 638 additions and 1,297 deletions.
8 changes: 3 additions & 5 deletions apps/web/app/txn/components/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const columns: ColumnDef<TxnType>[] = [
// make the cluster dynamic
<Link
target="_blank"
href={getTransactionUrl(row.original.network, row.original.signature[0], row.original.cluster)}
href={getTransactionUrl(row.original.network, row.original.hash, row.original.cluster)}
>
<div className="w-[80px]">
Txn-{(row.getValue("id") as string).split("-")[1]}
Expand Down Expand Up @@ -154,9 +154,7 @@ export const columns: ColumnDef<TxnType>[] = [
<DataTableColumnHeader column={column} title="Block Date" />
),
cell: ({ row }) => {
const blockTimeMilliseconds = row.original.blockTime * 1000;

const blockDate = new Date(blockTimeMilliseconds);
const blockDate = new Date(row.original.time);
const formattedDate = format(blockDate, "do MMM yy");
return (
<div className="flex items-center space-x-2">
Expand All @@ -175,7 +173,7 @@ export const columns: ColumnDef<TxnType>[] = [
<DataTableColumnHeader column={column} title="Block Time" />
),
cell: ({ row }) => {
const blockTimeMilliseconds = row.original.blockTime * 1000;
const blockTimeMilliseconds = row.original.time * 1000;

const blockDate = new Date(blockTimeMilliseconds);
const formattedTime = format(blockDate, "h:mm a");
Expand Down
62 changes: 21 additions & 41 deletions backend/api/src/db/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,16 @@ const chain = Chain(HASURA_URL, {
*/
export const insertTxn = async ({
clientId,
blockTime,
time,
amount,
fee,
from,
to,
postBalances,
preBalances,
recentBlockhash,
signature,
blockHash,
hash,
network,
slot,
cluster,
nonce,
chainId,
}: InsertTxnType): Promise<{
status: dbResStatus;
Expand All @@ -58,19 +55,15 @@ export const insertTxn = async ({
{
object: {
clientId,
signature,
network,
hash,
slot,
amount,
blockTime,
fee,
from,
to,
preBalances,
postBalances,
recentBlockhash,
blockHash,
cluster,
nonce,
chainId,
},
},
Expand Down Expand Up @@ -120,22 +113,18 @@ export const getTxns = async ({
},
{
id: true,
//@ts-ignore
signature: true,
hash: true,
amount: true,
blockTime: true,
time: true,
clientId: true,
fee: true,
time: true,
from: true,
network: true,
//@ts-ignore
postBalances: true,
//@ts-ignore
preBalances: true,
recentBlockhash: true,
blockHash: true,
slot: true,
to: true,
cluster: true,
status: true
},
],
},
Expand All @@ -160,7 +149,7 @@ export const getTxns = async ({
*/
export const getTxnByHash = async ({
network,
sign,
hash,
clientId,
}: TxnQuerySignType): Promise<{
status: dbResStatus;
Expand All @@ -172,29 +161,25 @@ export const getTxnByHash = async ({
transactions: [
{
where: {
signature: { _contains: sign },
hash: { _eq: hash },
clientId: { _eq: clientId },
network: { _eq: network },
},
},
{
id: true,
//@ts-ignore
signature: true,
amount: true,
blockTime: true,
time: true,
clientId: true,
fee: true,
time: true,
from: true,
network: true,
//@ts-ignore
postBalances: true,
//@ts-ignore
preBalances: true,
recentBlockhash: true,
blockHash: true,
slot: true,
to: true,
hash: true,
cluster: true,
status: true
},
],
},
Expand Down Expand Up @@ -236,23 +221,18 @@ export const getAllTxn = async ({
},
{
id: true,
//@ts-ignore
signature: true,
hash: true,
amount: true,
blockTime: true,
time: true,
clientId: true,
fee: true,
time: true,
from: true,
network: true,
//@ts-ignore
postBalances: true,
//@ts-ignore
preBalances: true,
recentBlockhash: true,
blockHash: true,
slot: true,
to: true,
cluster: true,
status: true
},
],
},
Expand Down
6 changes: 3 additions & 3 deletions backend/api/src/routes/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ txnRouter.get("/get", async (req, res) => {
//@ts-ignore
const id = req.id as string;
if (id) {
let { network, sign } = TxnQeuryByHash.parse(req.query);
let { network, hash } = TxnQeuryByHash.parse(req.query);
/**
* Cache
*/
const isTxn = await cache.txn.cacheGetTxnBySign(sign);
const isTxn = await cache.txn.cacheGetTxnBySign(hash);
if (isTxn) {
return res.status(302).json({ txn: isTxn, status: responseStatus.Ok });
}
//Db query
const txn = await getTxnByHash({ network, sign, clientId: id });
const txn = await getTxnByHash({ network, hash, clientId: id });
if (txn.status == dbResStatus.Error) {
return res
.status(503)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
comment on column "public"."transactions"."blockTime" is E'transactions table ';
alter table "public"."transactions" add constraint "transactions_block_time_key" unique (blockTime);
alter table "public"."transactions" alter column "blockTime" drop not null;
alter table "public"."transactions" add column "blockTime" int8;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."transactions" drop column "blockTime" cascade;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
comment on column "public"."transactions"."preBalances" is E'transactions table ';
alter table "public"."transactions" alter column "preBalances" drop not null;
alter table "public"."transactions" add column "preBalances" jsonb;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."transactions" drop column "preBalances" cascade;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
comment on column "public"."transactions"."postBalances" is E'transactions table ';
alter table "public"."transactions" alter column "postBalances" drop not null;
alter table "public"."transactions" add column "postBalances" jsonb;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."transactions" drop column "postBalances" cascade;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."transactions" rename column "blockHash" to "recentBlockhash";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."transactions" rename column "recentBlockhash" to "blockHash";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
comment on column "public"."transactions"."signature" is E'transactions table ';
alter table "public"."transactions" alter column "signature" drop not null;
alter table "public"."transactions" add column "signature" jsonb;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."transactions" drop column "signature" cascade;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."transactions" alter column "hash" drop not null;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."transactions" alter column "hash" set not null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
alter table "public"."transactions" drop constraint "transactions_clientId_fkey",
add constraint "transactions_client_id_fkey"
foreign key ("clientId")
references "public"."client"
("id") on update restrict on delete restrict;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
alter table "public"."transactions" drop constraint "transactions_client_id_fkey",
add constraint "transactions_clientId_fkey"
foreign key ("clientId")
references "public"."client"
("id") on update restrict on delete restrict;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."transactions" drop constraint "transactions_hash_key";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."transactions" add constraint "transactions_hash_key" unique ("hash");
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
comment on column "public"."transactions"."nonce" is E'transactions table ';
alter table "public"."transactions" alter column "nonce" drop not null;
alter table "public"."transactions" add column "nonce" int4;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."transactions" drop column "nonce" cascade;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."transactions" add column "nonce" bigint
-- null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."transactions" add column "nonce" bigint
null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
comment on column "public"."transactions"."nonce" is E'transactions table ';
alter table "public"."transactions" alter column "nonce" drop not null;
alter table "public"."transactions" add column "nonce" int8;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."transactions" drop column "nonce" cascade;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."transactions" add column "nonce" bigint
-- null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."transactions" add column "nonce" bigint
null;
Loading

0 comments on commit 361e5eb

Please sign in to comment.