Skip to content

Commit 0597755

Browse files
committed
refactor: txById should return the height
1 parent c784767 commit 0597755

File tree

2 files changed

+43
-40
lines changed

2 files changed

+43
-40
lines changed

packages/wallet-service/src/db/index.ts

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
TxByIdToken,
4040
PushDeviceSettings,
4141
FullNodeApiVersionResponse,
42+
TxInfo,
4243
} from '@src/types';
4344
import {
4445
getUnixTimestamp,
@@ -426,7 +427,7 @@ export const getWalletAddressDetail = async (mysql: ServerlessMysql, walletId: s
426427
FROM \`address\`
427428
WHERE \`wallet_id\` = ?
428429
AND \`address\` = ?`,
429-
[walletId, address]);
430+
[walletId, address]);
430431

431432
if (results.length > 0) {
432433
const data = results[0];
@@ -1160,12 +1161,12 @@ export const updateAddressLockedBalance = async (
11601161
\`unlocked_authorities\` = (unlocked_authorities | ?)
11611162
WHERE \`address\` = ?
11621163
AND \`token_id\` = ?`, [
1163-
tokenBalance.unlockedAmount,
1164-
tokenBalance.unlockedAmount,
1165-
tokenBalance.unlockedAuthorities.toInteger(),
1166-
address,
1167-
token,
1168-
],
1164+
tokenBalance.unlockedAmount,
1165+
tokenBalance.unlockedAmount,
1166+
tokenBalance.unlockedAuthorities.toInteger(),
1167+
address,
1168+
token,
1169+
],
11691170
);
11701171

11711172
// if any authority has been unlocked, we have to refresh the locked authorities
@@ -1201,7 +1202,7 @@ export const updateAddressLockedBalance = async (
12011202
)
12021203
WHERE \`address\` = ?
12031204
AND \`token_id\` = ?`,
1204-
[address, token, address, token]);
1205+
[address, token, address, token]);
12051206
}
12061207
}
12071208
}
@@ -1233,7 +1234,7 @@ export const updateWalletLockedBalance = async (
12331234
WHERE \`wallet_id\` = ?
12341235
AND \`token_id\` = ?`,
12351236
[tokenBalance.unlockedAmount, tokenBalance.unlockedAmount,
1236-
tokenBalance.unlockedAuthorities.toInteger(), walletId, token],
1237+
tokenBalance.unlockedAuthorities.toInteger(), walletId, token],
12371238
);
12381239

12391240
// if any authority has been unlocked, we have to refresh the locked authorities
@@ -1418,7 +1419,7 @@ export const getWalletTokens = async (
14181419
);
14191420

14201421
for (const result of results) {
1421-
tokenList.push(<string> result.token_id);
1422+
tokenList.push(<string>result.token_id);
14221423
}
14231424

14241425
return tokenList;
@@ -1464,7 +1465,7 @@ LEFT OUTER JOIN transaction ON transaction.tx_id = wallet_tx_history.tx_id
14641465
ORDER BY wallet_tx_history.timestamp
14651466
DESC
14661467
LIMIT ?, ?`,
1467-
[walletId, tokenId, skip, count]);
1468+
[walletId, tokenId, skip, count]);
14681469

14691470
for (const result of results) {
14701471
const tx: TxTokenBalance = {
@@ -2080,7 +2081,7 @@ export const markUtxosAsVoided = async (
20802081
UPDATE \`tx_output\`
20812082
SET \`voided\` = TRUE
20822083
WHERE \`tx_id\` IN (?)`,
2083-
[txIds]);
2084+
[txIds]);
20842085
};
20852086

20862087
/**
@@ -2818,15 +2819,15 @@ export const existsPushDevice = async (
28182819
mysql: ServerlessMysql,
28192820
deviceId: string,
28202821
walletId: string,
2821-
) : Promise<boolean> => {
2822+
): Promise<boolean> => {
28222823
const [{ count }] = await mysql.query(
28232824
`
28242825
SELECT COUNT(1) as \`count\`
28252826
FROM \`push_devices\` pd
28262827
WHERE device_id = ?
28272828
AND wallet_id = ?`,
28282829
[deviceId, walletId],
2829-
) as unknown as Array<{count}>;
2830+
) as unknown as Array<{ count }>;
28302831

28312832
return count > 0;
28322833
};
@@ -2846,7 +2847,7 @@ export const registerPushDevice = async (
28462847
enablePush: boolean,
28472848
enableShowAmounts: boolean,
28482849
},
2849-
) : Promise<void> => {
2850+
): Promise<void> => {
28502851
await mysql.query(
28512852
`
28522853
INSERT
@@ -2895,7 +2896,7 @@ export const updatePushDevice = async (
28952896
enablePush: boolean,
28962897
enableShowAmounts: boolean,
28972898
},
2898-
) : Promise<void> => {
2899+
): Promise<void> => {
28992900
await mysql.query(
29002901
`
29012902
UPDATE \`push_devices\`
@@ -2918,7 +2919,7 @@ export const unregisterPushDevice = async (
29182919
mysql: ServerlessMysql,
29192920
deviceId: string,
29202921
walletId?: string,
2921-
) : Promise<void> => {
2922+
): Promise<void> => {
29222923
if (walletId) {
29232924
await mysql.query(
29242925
`
@@ -2952,39 +2953,40 @@ export const getTransactionById = async (
29522953
txId: string,
29532954
walletId: string,
29542955
): Promise<TxByIdToken[]> => {
2955-
const result = await mysql.query(`
2956+
const result = await mysql.query<TxByIdToken[]>(`
29562957
SELECT
2957-
transaction.tx_id AS tx_id
2958+
transaction.tx_id AS txId
29582959
, transaction.timestamp AS timestamp
29592960
, transaction.version AS version
29602961
, transaction.voided AS voided
29612962
, transaction.height AS height
29622963
, transaction.weight AS weight
29632964
, wallet_tx_history.balance AS balance
2964-
, wallet_tx_history.token_id AS token_id
2965-
, token.name AS name
2966-
, token.symbol AS symbol
2965+
, wallet_tx_history.token_id AS tokenId
2966+
, token.name AS tokenName
2967+
, token.symbol AS tokenSymbol
29672968
FROM wallet_tx_history
2968-
INNER JOIN transaction ON transaction.tx_id = wallet_tx_history.tx_id
2969+
INNER JOIN transaction ON transaction.tx_id = wallet_tx_history.txId
29692970
INNER JOIN token ON wallet_tx_history.token_id = token.id
29702971
WHERE transaction.tx_id = ?
29712972
AND transaction.voided = FALSE
29722973
AND wallet_tx_history.wallet_id = ?`,
2973-
// eslint-disable-next-line camelcase
2974-
[txId, walletId]) as Array<{tx_id, timestamp, version, voided, weight, balance, token_id, name, symbol }>;
2974+
// eslint-disable-next-line camelcase
2975+
[txId, walletId]);
29752976

29762977
const txTokens = [];
29772978
result.forEach((eachTxToken) => {
29782979
const txToken = {
2979-
txId: eachTxToken.tx_id,
2980+
txId: eachTxToken.txId,
29802981
timestamp: eachTxToken.timestamp,
29812982
version: eachTxToken.version,
29822983
voided: !!eachTxToken.voided,
29832984
weight: eachTxToken.weight,
2985+
height: eachTxToken.height,
29842986
balance: eachTxToken.balance,
2985-
tokenId: eachTxToken.token_id,
2986-
tokenName: eachTxToken.name,
2987-
tokenSymbol: eachTxToken.symbol,
2987+
tokenId: eachTxToken.tokenId,
2988+
tokenName: eachTxToken.tokenName,
2989+
tokenSymbol: eachTxToken.tokenSymbol,
29882990
} as TxByIdToken;
29892991
txTokens.push(txToken);
29902992
});
@@ -3001,7 +3003,7 @@ export const getTransactionById = async (
30013003
export const existsWallet = async (
30023004
mysql: ServerlessMysql,
30033005
walletId: string,
3004-
) : Promise<boolean> => {
3006+
): Promise<boolean> => {
30053007
const [{ count }] = (await mysql.query(
30063008
`
30073009
SELECT COUNT(1) as \`count\`
@@ -3022,15 +3024,15 @@ export const existsWallet = async (
30223024
export const getPushDevice = async (
30233025
mysql: ServerlessMysql,
30243026
deviceId: string,
3025-
) : Promise<PushDevice|null> => {
3027+
): Promise<PushDevice | null> => {
30263028
const [pushDevice] = await mysql.query(
30273029
`
30283030
SELECT *
30293031
FROM \`push_devices\`
30303032
WHERE device_id = ?`,
30313033
[deviceId],
3032-
// eslint-disable-next-line camelcase
3033-
) as Array<{wallet_id, device_id, push_provider, enable_push, enable_show_amounts}>;
3034+
// eslint-disable-next-line camelcase
3035+
) as Array<{ wallet_id, device_id, push_provider, enable_push, enable_show_amounts }>;
30343036

30353037
if (!pushDevice) {
30363038
return null;
@@ -3055,7 +3057,7 @@ export const getPushDevice = async (
30553057
export const getPushDeviceSettingsList = async (
30563058
mysql: ServerlessMysql,
30573059
walletIdList: string[],
3058-
) : Promise<PushDeviceSettings[]> => {
3060+
): Promise<PushDeviceSettings[]> => {
30593061
const pushDeviceSettingsResult = await mysql.query(
30603062
`
30613063
SELECT wallet_id
@@ -3065,8 +3067,8 @@ export const getPushDeviceSettingsList = async (
30653067
FROM \`push_devices\`
30663068
WHERE wallet_id in (?)`,
30673069
[walletIdList],
3068-
// eslint-disable-next-line camelcase
3069-
) as Array<{wallet_id, device_id, enable_push, enable_show_amounts}>;
3070+
// eslint-disable-next-line camelcase
3071+
) as Array<{ wallet_id, device_id, enable_push, enable_show_amounts }>;
30703072

30713073
const pushDeviceSettignsList = pushDeviceSettingsResult.map((each) => ({
30723074
walletId: each.wallet_id,
@@ -3127,7 +3129,7 @@ export const getTokenSymbols = async (
31273129
);
31283130

31293131
if (results.length === 0) return null;
3130-
return results.reduce((prev: Record<string, string>, token: { id: string, symbol: string}) => {
3132+
return results.reduce((prev: Record<string, string>, token: { id: string, symbol: string }) => {
31313133
// eslint-disable-next-line no-param-reassign
31323134
prev[token.id] = token.symbol;
31333135
return prev;

packages/wallet-service/src/types.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ export interface EnvironmentConfig {
7474
firebaseTokenUri: string;
7575
firebaseAuthProviderX509CertUrl: string;
7676
firebaseClientX509CertUrl: string;
77-
firebasePrivateKey: string|null;
77+
firebasePrivateKey: string | null;
7878
maxLoadWalletRetries: number;
7979
logLevel: string;
8080
createNftMaxRetries: number;
8181
warnMaxReorgSize: number;
82-
};
82+
}
8383

8484
/**
8585
* Fullnode converted version data.
@@ -118,7 +118,7 @@ export interface FullNodeApiVersionResponse {
118118
genesis_block_hash: string,
119119
genesis_tx1_hash: string,
120120
genesis_tx2_hash: string,
121-
native_token: { name: string, symbol: string};
121+
native_token: { name: string, symbol: string };
122122
}
123123

124124
export interface TxProposal {
@@ -744,6 +744,7 @@ export interface TxByIdToken {
744744
timestamp: number;
745745
version: number;
746746
voided: boolean;
747+
height: number | null;
747748
weight: number;
748749
balance: Balance;
749750
tokenId: string;

0 commit comments

Comments
 (0)