File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -59,9 +59,10 @@ export const getWalletDetails = async (
5959
6060export const addWalletToDB = async (
6161 chainId : string ,
62+ dbInstance : Knex ,
6263 walletAddress : string ,
6364 slug : string ,
64- dbInstance : Knex ,
65+ walletType : string ,
6566) : Promise < void > => {
6667 try {
6768 const sdk = await getSDK ( chainId ) ;
@@ -76,7 +77,8 @@ export const addWalletToDB = async (
7677 blockchainNonce : BigNumber . from ( walletNonce ?? 0 ) . toNumber ( ) ,
7778 lastSyncedTimestamp : new Date ( ) ,
7879 lastUsedNonce : - 1 ,
79- walletType : slug ,
80+ walletType,
81+ slug,
8082 } ;
8183
8284 await insertIntoWallets ( walletData , dbInstance ) ;
@@ -176,3 +178,19 @@ export const addWalletDataWithSupportChainsNonceToDB = async (
176178 throw error ;
177179 }
178180} ;
181+
182+ export const getWalletDetailsWithoutChain = async (
183+ walletAddress : string ,
184+ database : Knex ,
185+ ) : Promise < any > => {
186+ try {
187+ const walletDetails = await database ( "wallets" )
188+ . select ( "*" )
189+ . where ( { walletAddress : walletAddress . toLowerCase ( ) } )
190+ . first ( ) ;
191+
192+ return walletDetails ;
193+ } catch ( error ) {
194+ throw error ;
195+ }
196+ } ;
Original file line number Diff line number Diff line change @@ -10,7 +10,12 @@ import { FastifyInstance, FastifyRequest } from "fastify";
1010import { StatusCodes } from "http-status-codes" ;
1111import { Knex } from "knex" ;
1212import { v4 as uuid } from "uuid" ;
13- import { connectToDatabase , getWalletDetails } from "../../core" ;
13+ import {
14+ addWalletToDB ,
15+ connectToDatabase ,
16+ getWalletDetails ,
17+ getWalletDetailsWithoutChain ,
18+ } from "../../core" ;
1419import { createCustomError } from "../../core/error/customError" ;
1520import {
1621 TransactionSchema ,
@@ -63,15 +68,22 @@ export const queueTransaction = async (
6368 ) ;
6469
6570 if ( ! walletDetails ) {
66- // await addWalletToDB(
67- // chainId,
68- // dbInstance,
69- // walletAddress,
70- // chainData.slug,
71- // getWalletType(),
72- // );
73- throw new Error (
74- `Import Wallet Address ${ walletAddress } to DB using /wallet/import end-point` ,
71+ const walletData = await getWalletDetailsWithoutChain (
72+ walletAddress . toLowerCase ( ) ,
73+ dbInstance ,
74+ ) ;
75+
76+ if ( ! walletData ) {
77+ throw new Error (
78+ `Import Wallet Address ${ walletAddress } to DB using /wallet/import end-point.` ,
79+ ) ;
80+ }
81+ await addWalletToDB (
82+ chainId ,
83+ dbInstance ,
84+ walletAddress ,
85+ chainData . slug ,
86+ walletData . walletType ,
7587 ) ;
7688 }
7789 // encode tx
You can’t perform that action at this time.
0 commit comments