Skip to content

Commit 361e5eb

Browse files
authored
Merge pull request #177 from shawakash/go2
chore: change the txn table attributes to hold Txn Type present in @paybox/mote
2 parents 4aa3bd2 + 4056d42 commit 361e5eb

File tree

39 files changed

+638
-1297
lines changed

39 files changed

+638
-1297
lines changed

apps/web/app/txn/components/columns.tsx

+3-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const columns: ColumnDef<TxnType>[] = [
4949
// make the cluster dynamic
5050
<Link
5151
target="_blank"
52-
href={getTransactionUrl(row.original.network, row.original.signature[0], row.original.cluster)}
52+
href={getTransactionUrl(row.original.network, row.original.hash, row.original.cluster)}
5353
>
5454
<div className="w-[80px]">
5555
Txn-{(row.getValue("id") as string).split("-")[1]}
@@ -154,9 +154,7 @@ export const columns: ColumnDef<TxnType>[] = [
154154
<DataTableColumnHeader column={column} title="Block Date" />
155155
),
156156
cell: ({ row }) => {
157-
const blockTimeMilliseconds = row.original.blockTime * 1000;
158-
159-
const blockDate = new Date(blockTimeMilliseconds);
157+
const blockDate = new Date(row.original.time);
160158
const formattedDate = format(blockDate, "do MMM yy");
161159
return (
162160
<div className="flex items-center space-x-2">
@@ -175,7 +173,7 @@ export const columns: ColumnDef<TxnType>[] = [
175173
<DataTableColumnHeader column={column} title="Block Time" />
176174
),
177175
cell: ({ row }) => {
178-
const blockTimeMilliseconds = row.original.blockTime * 1000;
176+
const blockTimeMilliseconds = row.original.time * 1000;
179177

180178
const blockDate = new Date(blockTimeMilliseconds);
181179
const formattedTime = format(blockDate, "h:mm a");

backend/api/src/db/transaction.ts

+21-41
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,16 @@ const chain = Chain(HASURA_URL, {
3434
*/
3535
export const insertTxn = async ({
3636
clientId,
37-
blockTime,
37+
time,
3838
amount,
3939
fee,
4040
from,
4141
to,
42-
postBalances,
43-
preBalances,
44-
recentBlockhash,
45-
signature,
42+
blockHash,
43+
hash,
4644
network,
4745
slot,
4846
cluster,
49-
nonce,
5047
chainId,
5148
}: InsertTxnType): Promise<{
5249
status: dbResStatus;
@@ -58,19 +55,15 @@ export const insertTxn = async ({
5855
{
5956
object: {
6057
clientId,
61-
signature,
6258
network,
59+
hash,
6360
slot,
6461
amount,
65-
blockTime,
6662
fee,
6763
from,
6864
to,
69-
preBalances,
70-
postBalances,
71-
recentBlockhash,
65+
blockHash,
7266
cluster,
73-
nonce,
7467
chainId,
7568
},
7669
},
@@ -120,22 +113,18 @@ export const getTxns = async ({
120113
},
121114
{
122115
id: true,
123-
//@ts-ignore
124-
signature: true,
116+
hash: true,
125117
amount: true,
126-
blockTime: true,
118+
time: true,
127119
clientId: true,
128120
fee: true,
129-
time: true,
130121
from: true,
131122
network: true,
132-
//@ts-ignore
133-
postBalances: true,
134-
//@ts-ignore
135-
preBalances: true,
136-
recentBlockhash: true,
123+
blockHash: true,
137124
slot: true,
138125
to: true,
126+
cluster: true,
127+
status: true
139128
},
140129
],
141130
},
@@ -160,7 +149,7 @@ export const getTxns = async ({
160149
*/
161150
export const getTxnByHash = async ({
162151
network,
163-
sign,
152+
hash,
164153
clientId,
165154
}: TxnQuerySignType): Promise<{
166155
status: dbResStatus;
@@ -172,29 +161,25 @@ export const getTxnByHash = async ({
172161
transactions: [
173162
{
174163
where: {
175-
signature: { _contains: sign },
164+
hash: { _eq: hash },
176165
clientId: { _eq: clientId },
177166
network: { _eq: network },
178167
},
179168
},
180169
{
181170
id: true,
182-
//@ts-ignore
183-
signature: true,
184171
amount: true,
185-
blockTime: true,
172+
time: true,
186173
clientId: true,
187174
fee: true,
188-
time: true,
189175
from: true,
190176
network: true,
191-
//@ts-ignore
192-
postBalances: true,
193-
//@ts-ignore
194-
preBalances: true,
195-
recentBlockhash: true,
177+
blockHash: true,
196178
slot: true,
197179
to: true,
180+
hash: true,
181+
cluster: true,
182+
status: true
198183
},
199184
],
200185
},
@@ -236,23 +221,18 @@ export const getAllTxn = async ({
236221
},
237222
{
238223
id: true,
239-
//@ts-ignore
240-
signature: true,
224+
hash: true,
241225
amount: true,
242-
blockTime: true,
226+
time: true,
243227
clientId: true,
244228
fee: true,
245-
time: true,
246229
from: true,
247230
network: true,
248-
//@ts-ignore
249-
postBalances: true,
250-
//@ts-ignore
251-
preBalances: true,
252-
recentBlockhash: true,
231+
blockHash: true,
253232
slot: true,
254233
to: true,
255234
cluster: true,
235+
status: true
256236
},
257237
],
258238
},

backend/api/src/routes/transaction.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,16 @@ txnRouter.get("/get", async (req, res) => {
128128
//@ts-ignore
129129
const id = req.id as string;
130130
if (id) {
131-
let { network, sign } = TxnQeuryByHash.parse(req.query);
131+
let { network, hash } = TxnQeuryByHash.parse(req.query);
132132
/**
133133
* Cache
134134
*/
135-
const isTxn = await cache.txn.cacheGetTxnBySign(sign);
135+
const isTxn = await cache.txn.cacheGetTxnBySign(hash);
136136
if (isTxn) {
137137
return res.status(302).json({ txn: isTxn, status: responseStatus.Ok });
138138
}
139139
//Db query
140-
const txn = await getTxnByHash({ network, sign, clientId: id });
140+
const txn = await getTxnByHash({ network, hash, clientId: id });
141141
if (txn.status == dbResStatus.Error) {
142142
return res
143143
.status(503)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
comment on column "public"."transactions"."blockTime" is E'transactions table ';
2+
alter table "public"."transactions" add constraint "transactions_block_time_key" unique (blockTime);
3+
alter table "public"."transactions" alter column "blockTime" drop not null;
4+
alter table "public"."transactions" add column "blockTime" int8;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alter table "public"."transactions" drop column "blockTime" cascade;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
comment on column "public"."transactions"."preBalances" is E'transactions table ';
2+
alter table "public"."transactions" alter column "preBalances" drop not null;
3+
alter table "public"."transactions" add column "preBalances" jsonb;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alter table "public"."transactions" drop column "preBalances" cascade;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
comment on column "public"."transactions"."postBalances" is E'transactions table ';
2+
alter table "public"."transactions" alter column "postBalances" drop not null;
3+
alter table "public"."transactions" add column "postBalances" jsonb;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alter table "public"."transactions" drop column "postBalances" cascade;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alter table "public"."transactions" rename column "blockHash" to "recentBlockhash";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alter table "public"."transactions" rename column "recentBlockhash" to "blockHash";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
comment on column "public"."transactions"."signature" is E'transactions table ';
2+
alter table "public"."transactions" alter column "signature" drop not null;
3+
alter table "public"."transactions" add column "signature" jsonb;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alter table "public"."transactions" drop column "signature" cascade;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alter table "public"."transactions" alter column "hash" drop not null;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alter table "public"."transactions" alter column "hash" set not null;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
alter table "public"."transactions" drop constraint "transactions_clientId_fkey",
2+
add constraint "transactions_client_id_fkey"
3+
foreign key ("clientId")
4+
references "public"."client"
5+
("id") on update restrict on delete restrict;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
alter table "public"."transactions" drop constraint "transactions_client_id_fkey",
2+
add constraint "transactions_clientId_fkey"
3+
foreign key ("clientId")
4+
references "public"."client"
5+
("id") on update restrict on delete restrict;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alter table "public"."transactions" drop constraint "transactions_hash_key";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alter table "public"."transactions" add constraint "transactions_hash_key" unique ("hash");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
comment on column "public"."transactions"."nonce" is E'transactions table ';
2+
alter table "public"."transactions" alter column "nonce" drop not null;
3+
alter table "public"."transactions" add column "nonce" int4;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alter table "public"."transactions" drop column "nonce" cascade;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Could not auto-generate a down migration.
2+
-- Please write an appropriate down migration for the SQL below:
3+
-- alter table "public"."transactions" add column "nonce" bigint
4+
-- null;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
alter table "public"."transactions" add column "nonce" bigint
2+
null;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
comment on column "public"."transactions"."nonce" is E'transactions table ';
2+
alter table "public"."transactions" alter column "nonce" drop not null;
3+
alter table "public"."transactions" add column "nonce" int8;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alter table "public"."transactions" drop column "nonce" cascade;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Could not auto-generate a down migration.
2+
-- Please write an appropriate down migration for the SQL below:
3+
-- alter table "public"."transactions" add column "nonce" bigint
4+
-- null;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
alter table "public"."transactions" add column "nonce" bigint
2+
null;

0 commit comments

Comments
 (0)