@otoplo/wallet-common 0.6.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +88 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +233 -126
- package/dist/index.js.map +1 -1
- package/package.json +3 -4
- package/src/services/asset.ts +3 -3
- package/src/services/market.ts +4 -1
- package/src/services/rostrum.ts +322 -274
- package/src/services/transaction.ts +2 -2
- package/src/services/wallet.ts +7 -3
- package/src/types/rostrum.types.ts +11 -0
- package/src/utils/amount.ts +112 -0
- package/src/utils/common.ts +202 -183
- package/src/utils/index.ts +1 -0
- package/src/utils/vault.ts +6 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@otoplo/wallet-common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Shared common library for internal use in Otoplo wallet",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "vgrunner",
|
|
@@ -32,12 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@otoplo/electrum-client": "^2.0.0",
|
|
35
|
-
"@scure/bip39": "^2.4.0"
|
|
36
|
-
"js-big-decimal": "^2.2.0"
|
|
35
|
+
"@scure/bip39": "^2.4.0"
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
|
39
38
|
"eslint": "^10.16.0",
|
|
40
|
-
"tsdown": "^0.23.
|
|
39
|
+
"tsdown": "^0.23.8",
|
|
41
40
|
"typescript": "^6.0.3",
|
|
42
41
|
"typescript-eslint": "^8.74.0"
|
|
43
42
|
},
|
package/src/services/asset.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { NftEntity, TokenEntity } from "../types/db.types";
|
|
2
2
|
import { getAssetFileUrl, getAssetMetadataUrl } from "../utils/asset";
|
|
3
|
-
import { currentTimestamp, tokenIdToHex } from "../utils/common";
|
|
3
|
+
import { balanceTotal, currentTimestamp, tokenIdToHex } from "../utils/common";
|
|
4
4
|
import type { WalletDB } from "../persistence/wallet-db";
|
|
5
5
|
import type { WalletCache } from "./cache";
|
|
6
6
|
import type { AssetInfo, Balance } from "../types/wallet.types";
|
|
@@ -76,7 +76,7 @@ export class AssetService {
|
|
|
76
76
|
public async syncTokens(accountId: number, tokenBalances: Record<string, Balance>): Promise<void> {
|
|
77
77
|
for (const tokenId in tokenBalances) {
|
|
78
78
|
const balance = tokenBalances[tokenId];
|
|
79
|
-
if (balance &&
|
|
79
|
+
if (balance && balanceTotal(balance) > 0n) {
|
|
80
80
|
const token = await this.getAssetInfo(tokenId);
|
|
81
81
|
if (token && token.type == 'token') {
|
|
82
82
|
const tokenEntity: TokenEntity = {
|
|
@@ -102,7 +102,7 @@ export class AssetService {
|
|
|
102
102
|
|
|
103
103
|
for (const [token, balance] of Object.entries(tokensBalance)) {
|
|
104
104
|
const tokenId = tokenIdToHex(token);
|
|
105
|
-
const hasBalance = balance &&
|
|
105
|
+
const hasBalance = balance && balanceTotal(balance) > 0n;
|
|
106
106
|
const isAssetExist = internalAssets?.some(a => a.tokenIdHex == tokenId);
|
|
107
107
|
if ((!hasBalance && !isAssetExist) || (hasBalance && isAssetExist)) {
|
|
108
108
|
continue;
|
package/src/services/market.ts
CHANGED
|
@@ -21,6 +21,9 @@ interface MarketDataResponse {
|
|
|
21
21
|
total_volume?: number | null;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
/** Key of NEXA in the market data (`market_data_updated`'s `data`). */
|
|
25
|
+
export const NEXA_MARKET_ID = 'nexa';
|
|
26
|
+
|
|
24
27
|
export type MarketEvent =
|
|
25
28
|
| { type: 'market_data_updated'; currency: CurrencyCode; data: Record<string, MarketData> }
|
|
26
29
|
| { type: 'currency_updated'; currency: CurrencyCode };
|
|
@@ -32,7 +35,7 @@ export class MarketService {
|
|
|
32
35
|
private static readonly POLL_INTERVAL_MS = 2 * 60 * 1000;
|
|
33
36
|
private static readonly CURRENCY_SETTING = "market-currency";
|
|
34
37
|
private static readonly SUPPORTED_TOKENS: Record<string, string> = {
|
|
35
|
-
nexacoin:
|
|
38
|
+
nexacoin: NEXA_MARKET_ID
|
|
36
39
|
};
|
|
37
40
|
|
|
38
41
|
private readonly walletDb: WalletDB;
|