File tree Expand file tree Collapse file tree 2 files changed +42
-12
lines changed Expand file tree Collapse file tree 2 files changed +42
-12
lines changed Original file line number Diff line number Diff line change @@ -59,9 +59,10 @@ export const getWalletDetails = async (
59
59
60
60
export const addWalletToDB = async (
61
61
chainId : string ,
62
+ dbInstance : Knex ,
62
63
walletAddress : string ,
63
64
slug : string ,
64
- dbInstance : Knex ,
65
+ walletType : string ,
65
66
) : Promise < void > => {
66
67
try {
67
68
const sdk = await getSDK ( chainId ) ;
@@ -76,7 +77,8 @@ export const addWalletToDB = async (
76
77
blockchainNonce : BigNumber . from ( walletNonce ?? 0 ) . toNumber ( ) ,
77
78
lastSyncedTimestamp : new Date ( ) ,
78
79
lastUsedNonce : - 1 ,
79
- walletType : slug ,
80
+ walletType,
81
+ slug,
80
82
} ;
81
83
82
84
await insertIntoWallets ( walletData , dbInstance ) ;
@@ -176,3 +178,19 @@ export const addWalletDataWithSupportChainsNonceToDB = async (
176
178
throw error ;
177
179
}
178
180
} ;
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";
10
10
import { StatusCodes } from "http-status-codes" ;
11
11
import { Knex } from "knex" ;
12
12
import { v4 as uuid } from "uuid" ;
13
- import { connectToDatabase , getWalletDetails } from "../../core" ;
13
+ import {
14
+ addWalletToDB ,
15
+ connectToDatabase ,
16
+ getWalletDetails ,
17
+ getWalletDetailsWithoutChain ,
18
+ } from "../../core" ;
14
19
import { createCustomError } from "../../core/error/customError" ;
15
20
import {
16
21
TransactionSchema ,
@@ -63,15 +68,22 @@ export const queueTransaction = async (
63
68
) ;
64
69
65
70
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 ,
75
87
) ;
76
88
}
77
89
// encode tx
You can’t perform that action at this time.
0 commit comments