@dynamic-labs/midnight 4.80.0 → 4.82.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/CHANGELOG.md +38 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +6 -6
- package/src/constants.cjs +6 -0
- package/src/constants.d.ts +5 -0
- package/src/constants.js +6 -1
- package/src/index.cjs +8 -2
- package/src/index.d.ts +1 -0
- package/src/index.js +3 -2
- package/src/utils/formatMidnightAtomicBalance/formatMidnightAtomicBalance.cjs +29 -0
- package/src/utils/formatMidnightAtomicBalance/formatMidnightAtomicBalance.d.ts +5 -0
- package/src/utils/formatMidnightAtomicBalance/formatMidnightAtomicBalance.js +25 -0
- package/src/utils/formatMidnightAtomicBalance/index.d.ts +1 -0
- package/src/utils/formatMidnightConnectorDustBalance/formatMidnightConnectorDustBalance.cjs +20 -0
- package/src/utils/formatMidnightConnectorDustBalance/formatMidnightConnectorDustBalance.d.ts +9 -0
- package/src/utils/formatMidnightConnectorDustBalance/formatMidnightConnectorDustBalance.js +16 -0
- package/src/utils/formatMidnightConnectorDustBalance/index.d.ts +1 -0
- package/src/utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.cjs +2 -19
- package/src/utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.js +2 -19
- package/src/wallet/MidnightWallet.cjs +19 -2
- package/src/wallet/MidnightWallet.d.ts +2 -1
- package/src/wallet/MidnightWallet.js +19 -2
- package/src/wallet/isMidnightWallet/isMidnightWallet.d.ts +1 -3
- package/src/wallet/isMidnightWallet/isMidnightWallet.cjs +0 -8
- package/src/wallet/isMidnightWallet/isMidnightWallet.js +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,42 @@
|
|
|
1
1
|
|
|
2
|
+
## [4.82.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.81.0...v4.82.0) (2026-05-11)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* adds react-native embedded webview ([#11168](https://github.com/dynamic-labs/dynamic-auth/issues/11168)) ([31c17e3](https://github.com/dynamic-labs/dynamic-auth/commit/31c17e34e198efc806299011ab286bf48a244908))
|
|
8
|
+
* **aleo:** expose WaaS-specific methods directly on AleoWallet ([#11174](https://github.com/dynamic-labs/dynamic-auth/issues/11174)) ([ccfb8f4](https://github.com/dynamic-labs/dynamic-auth/commit/ccfb8f4de690ee4a30b6c20e037fef51a69df8e1))
|
|
9
|
+
* **aleo:** two-step Exchange Send (unshield → public→public) ([#11172](https://github.com/dynamic-labs/dynamic-auth/issues/11172)) ([02a992c](https://github.com/dynamic-labs/dynamic-auth/commit/02a992c3239519ed283a9804f092bffca9ba4d18))
|
|
10
|
+
* **demo:** registry-driven Aleo transactions form ([#11105](https://github.com/dynamic-labs/dynamic-auth/issues/11105)) ([766949e](https://github.com/dynamic-labs/dynamic-auth/commit/766949e7bb9f613e157418ed4221cac43fbf0394))
|
|
11
|
+
* **sdk-react-core:** add ActiveMidnightWalletAddresses widget ([#11083](https://github.com/dynamic-labs/dynamic-auth/issues/11083)) ([1858292](https://github.com/dynamic-labs/dynamic-auth/commit/18582926348420332f89a3d1b2c2ca2cd453f69e))
|
|
12
|
+
* **widget:** auto-merge + auto-shield sponsored Aleo tokens on wallet load ([#11157](https://github.com/dynamic-labs/dynamic-auth/issues/11157)) ([cda1de1](https://github.com/dynamic-labs/dynamic-auth/commit/cda1de1f04789eb24bba2fbe0a49b5f42f6a609d))
|
|
13
|
+
* **widget:** auto-shield indicator + post-shield balance refresh polling ([#11173](https://github.com/dynamic-labs/dynamic-auth/issues/11173)) ([f49d480](https://github.com/dynamic-labs/dynamic-auth/commit/f49d480dc5ef85efd7d201687d9b0309090a69c8))
|
|
14
|
+
* **widget:** wire Aleo curated prices into the Shielded balance tab ([#11178](https://github.com/dynamic-labs/dynamic-auth/issues/11178)) ([eab1606](https://github.com/dynamic-labs/dynamic-auth/commit/eab16062140a0474d14a2cc43fd0a1624e4da92e))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **ci:** wire dd-trace ci visibility env vars for [@demov1](https://github.com/demov1) playwright task ([#11199](https://github.com/dynamic-labs/dynamic-auth/issues/11199)) ([9af4827](https://github.com/dynamic-labs/dynamic-auth/commit/9af48271e4721dac54d495097d43522f76ec724d))
|
|
20
|
+
* **playwright:** expose raw auth token for stable JWT reads ([#11204](https://github.com/dynamic-labs/dynamic-auth/issues/11204)) ([b002dfb](https://github.com/dynamic-labs/dynamic-auth/commit/b002dfb642755830c6c9c813ebb4d749882518d6))
|
|
21
|
+
* **playwright:** replace waitForTimeout in networkControl + reinitialize spec ([#11161](https://github.com/dynamic-labs/dynamic-auth/issues/11161)) ([5e72371](https://github.com/dynamic-labs/dynamic-auth/commit/5e723713ceb8c804d253c261be86abb997daeabd))
|
|
22
|
+
* remediate high-severity dependency vulnerabilities ([#11171](https://github.com/dynamic-labs/dynamic-auth/issues/11171)) ([285e7cb](https://github.com/dynamic-labs/dynamic-auth/commit/285e7cb0d07f957a97e8d9ef4fab0b8d2d24e031))
|
|
23
|
+
|
|
24
|
+
## [4.81.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.80.0...v4.81.0) (2026-05-07)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Features
|
|
28
|
+
|
|
29
|
+
* **react-native:** add waitForAuthSuccess() to auth module ([#11137](https://github.com/dynamic-labs/dynamic-auth/issues/11137)) ([089a566](https://github.com/dynamic-labs/dynamic-auth/commit/089a5663283639e7e425eead291b135010c8b398))
|
|
30
|
+
* **waas:** hook Aleo into DynamicWaasMixin ([#11102](https://github.com/dynamic-labs/dynamic-auth/issues/11102)) ([ff42df9](https://github.com/dynamic-labs/dynamic-auth/commit/ff42df99d8993e22894caee3c0570cd9c332a3d1))
|
|
31
|
+
* **widget:** shielded/unshielded tabs + Shield Manually CTA on ActiveWalletBalance for Aleo ([#11103](https://github.com/dynamic-labs/dynamic-auth/issues/11103)) ([e278836](https://github.com/dynamic-labs/dynamic-auth/commit/e278836bfcb19c13828c10483ebb87d165f5d00d))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Bug Fixes
|
|
35
|
+
|
|
36
|
+
* **ethereum-aa:** return hex chain ids from EIP-5792 getCapabilities ([#11146](https://github.com/dynamic-labs/dynamic-auth/issues/11146)) ([b32dc8f](https://github.com/dynamic-labs/dynamic-auth/commit/b32dc8f6fdee3722073921787c4f77908ab4f740))
|
|
37
|
+
* remediate high-severity dependency vulnerabilities ([#11151](https://github.com/dynamic-labs/dynamic-auth/issues/11151)) ([1d84ef1](https://github.com/dynamic-labs/dynamic-auth/commit/1d84ef12e10544be0b2a80dbbbd63f615b03adc3))
|
|
38
|
+
* **wagmi-connector:** emit change unconditionally on MM accountsChanged DYNT-549 ([#11131](https://github.com/dynamic-labs/dynamic-auth/issues/11131)) ([348ee6f](https://github.com/dynamic-labs/dynamic-auth/commit/348ee6ff9a22cb55ef0cb84c4b8f8d2e843bd10e)), closes [#11043](https://github.com/dynamic-labs/dynamic-auth/issues/11043)
|
|
39
|
+
|
|
2
40
|
## [4.80.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.79.2...v4.80.0) (2026-05-05)
|
|
3
41
|
|
|
4
42
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/midnight",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.82.0",
|
|
4
4
|
"description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
|
|
5
5
|
"author": "Dynamic Labs, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://www.dynamic.xyz/",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dynamic-labs/assert-package-version": "4.
|
|
21
|
+
"@dynamic-labs/assert-package-version": "4.82.0",
|
|
22
22
|
"@dynamic-labs/sdk-api-core": "0.0.964",
|
|
23
23
|
"@midnight-ntwrk/dapp-connector-api": "4.0.1",
|
|
24
|
-
"@dynamic-labs/types": "4.
|
|
25
|
-
"@dynamic-labs/utils": "4.
|
|
26
|
-
"@dynamic-labs/wallet-book": "4.
|
|
27
|
-
"@dynamic-labs/wallet-connector-core": "4.
|
|
24
|
+
"@dynamic-labs/types": "4.82.0",
|
|
25
|
+
"@dynamic-labs/utils": "4.82.0",
|
|
26
|
+
"@dynamic-labs/wallet-book": "4.82.0",
|
|
27
|
+
"@dynamic-labs/wallet-connector-core": "4.82.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {}
|
|
30
30
|
}
|
package/src/constants.cjs
CHANGED
|
@@ -30,6 +30,11 @@ const MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE = [
|
|
|
30
30
|
* dapp connector API (ledger smallest-unit representation).
|
|
31
31
|
*/
|
|
32
32
|
const MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS = 6;
|
|
33
|
+
/**
|
|
34
|
+
* Ledger DUST `balance` from `getDustBalance()` / `getBalances().dust.balance` is in Specks
|
|
35
|
+
* (1 DUST = 10^15 Specks). The `cap` uses the same 10^6 atomic scale as unshielded NIGHT.
|
|
36
|
+
*/
|
|
37
|
+
const MIDNIGHT_DUST_BALANCE_SPECK_DECIMALS = 15;
|
|
33
38
|
/**
|
|
34
39
|
* Midnight blockchain network identifiers.
|
|
35
40
|
* mainnet = 0, testnet = 1 (mirrors the chainId mapping).
|
|
@@ -40,6 +45,7 @@ const MIDNIGHT_NETWORKS = {
|
|
|
40
45
|
};
|
|
41
46
|
|
|
42
47
|
exports.MIDNIGHT_CHAIN = MIDNIGHT_CHAIN;
|
|
48
|
+
exports.MIDNIGHT_DUST_BALANCE_SPECK_DECIMALS = MIDNIGHT_DUST_BALANCE_SPECK_DECIMALS;
|
|
43
49
|
exports.MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE = MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE;
|
|
44
50
|
exports.MIDNIGHT_NATIVE_TOKEN_TYPE = MIDNIGHT_NATIVE_TOKEN_TYPE;
|
|
45
51
|
exports.MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS = MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS;
|
package/src/constants.d.ts
CHANGED
|
@@ -16,6 +16,11 @@ export declare const MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE: string;
|
|
|
16
16
|
* dapp connector API (ledger smallest-unit representation).
|
|
17
17
|
*/
|
|
18
18
|
export declare const MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS = 6;
|
|
19
|
+
/**
|
|
20
|
+
* Ledger DUST `balance` from `getDustBalance()` / `getBalances().dust.balance` is in Specks
|
|
21
|
+
* (1 DUST = 10^15 Specks). The `cap` uses the same 10^6 atomic scale as unshielded NIGHT.
|
|
22
|
+
*/
|
|
23
|
+
export declare const MIDNIGHT_DUST_BALANCE_SPECK_DECIMALS = 15;
|
|
19
24
|
/**
|
|
20
25
|
* Midnight blockchain network identifiers.
|
|
21
26
|
* mainnet = 0, testnet = 1 (mirrors the chainId mapping).
|
package/src/constants.js
CHANGED
|
@@ -26,6 +26,11 @@ const MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE = [
|
|
|
26
26
|
* dapp connector API (ledger smallest-unit representation).
|
|
27
27
|
*/
|
|
28
28
|
const MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS = 6;
|
|
29
|
+
/**
|
|
30
|
+
* Ledger DUST `balance` from `getDustBalance()` / `getBalances().dust.balance` is in Specks
|
|
31
|
+
* (1 DUST = 10^15 Specks). The `cap` uses the same 10^6 atomic scale as unshielded NIGHT.
|
|
32
|
+
*/
|
|
33
|
+
const MIDNIGHT_DUST_BALANCE_SPECK_DECIMALS = 15;
|
|
29
34
|
/**
|
|
30
35
|
* Midnight blockchain network identifiers.
|
|
31
36
|
* mainnet = 0, testnet = 1 (mirrors the chainId mapping).
|
|
@@ -35,4 +40,4 @@ const MIDNIGHT_NETWORKS = {
|
|
|
35
40
|
TESTNET: 'midnight:testnet',
|
|
36
41
|
};
|
|
37
42
|
|
|
38
|
-
export { MIDNIGHT_CHAIN, MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE, MIDNIGHT_NATIVE_TOKEN_TYPE, MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS, MIDNIGHT_NETWORKS };
|
|
43
|
+
export { MIDNIGHT_CHAIN, MIDNIGHT_DUST_BALANCE_SPECK_DECIMALS, MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE, MIDNIGHT_NATIVE_TOKEN_TYPE, MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS, MIDNIGHT_NETWORKS };
|
package/src/index.cjs
CHANGED
|
@@ -15,7 +15,8 @@ var getConnectorConstructorInjectedWallet = require('./utils/getConnectorConstru
|
|
|
15
15
|
var toMidnightNetworks = require('./utils/toMidnightNetworks/toMidnightNetworks.cjs');
|
|
16
16
|
var constants = require('./constants.cjs');
|
|
17
17
|
var formatMidnightNativeUnshieldedBalance = require('./utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.cjs');
|
|
18
|
-
var
|
|
18
|
+
var formatMidnightConnectorDustBalance = require('./utils/formatMidnightConnectorDustBalance/formatMidnightConnectorDustBalance.cjs');
|
|
19
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
19
20
|
|
|
20
21
|
/* istanbul ignore file */
|
|
21
22
|
/* istanbul ignore next */
|
|
@@ -31,9 +32,14 @@ exports.injectedWalletOverrides = fetchInjectedWalletConnectors.injectedWalletOv
|
|
|
31
32
|
exports.getConnectorConstructorInjectedWallet = getConnectorConstructorInjectedWallet.getConnectorConstructorInjectedWallet;
|
|
32
33
|
exports.toMidnightNetworks = toMidnightNetworks.toMidnightNetworks;
|
|
33
34
|
exports.MIDNIGHT_CHAIN = constants.MIDNIGHT_CHAIN;
|
|
35
|
+
exports.MIDNIGHT_DUST_BALANCE_SPECK_DECIMALS = constants.MIDNIGHT_DUST_BALANCE_SPECK_DECIMALS;
|
|
34
36
|
exports.MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE = constants.MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE;
|
|
35
37
|
exports.MIDNIGHT_NATIVE_TOKEN_TYPE = constants.MIDNIGHT_NATIVE_TOKEN_TYPE;
|
|
36
38
|
exports.MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS = constants.MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS;
|
|
37
39
|
exports.MIDNIGHT_NETWORKS = constants.MIDNIGHT_NETWORKS;
|
|
38
40
|
exports.formatMidnightNativeUnshieldedBalance = formatMidnightNativeUnshieldedBalance.formatMidnightNativeUnshieldedBalance;
|
|
39
|
-
exports.
|
|
41
|
+
exports.formatMidnightConnectorDustBalance = formatMidnightConnectorDustBalance.formatMidnightConnectorDustBalance;
|
|
42
|
+
Object.defineProperty(exports, 'isMidnightWallet', {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () { return walletConnectorCore.isMidnightWallet; }
|
|
45
|
+
});
|
package/src/index.d.ts
CHANGED
|
@@ -8,5 +8,6 @@ export * from './utils/getConnectorConstructorInjectedWallet';
|
|
|
8
8
|
export * from './utils/toMidnightNetworks';
|
|
9
9
|
export * from './constants';
|
|
10
10
|
export { formatMidnightNativeUnshieldedBalance } from './utils/formatMidnightNativeUnshieldedBalance';
|
|
11
|
+
export { formatMidnightConnectorDustBalance } from './utils/formatMidnightConnectorDustBalance';
|
|
11
12
|
export * from './types';
|
|
12
13
|
export { isMidnightWallet } from './wallet/isMidnightWallet';
|
package/src/index.js
CHANGED
|
@@ -9,9 +9,10 @@ export { InjectedWalletBase } from './injected/InjectedWalletBase/InjectedWallet
|
|
|
9
9
|
export { fetchInjectedWalletConnectors, injectedWalletOverrides } from './injected/fetchInjectedWalletConnectors/fetchInjectedWalletConnectors.js';
|
|
10
10
|
export { getConnectorConstructorInjectedWallet } from './utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.js';
|
|
11
11
|
export { toMidnightNetworks } from './utils/toMidnightNetworks/toMidnightNetworks.js';
|
|
12
|
-
export { MIDNIGHT_CHAIN, MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE, MIDNIGHT_NATIVE_TOKEN_TYPE, MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS, MIDNIGHT_NETWORKS } from './constants.js';
|
|
12
|
+
export { MIDNIGHT_CHAIN, MIDNIGHT_DUST_BALANCE_SPECK_DECIMALS, MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE, MIDNIGHT_NATIVE_TOKEN_TYPE, MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS, MIDNIGHT_NETWORKS } from './constants.js';
|
|
13
13
|
export { formatMidnightNativeUnshieldedBalance } from './utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.js';
|
|
14
|
-
export {
|
|
14
|
+
export { formatMidnightConnectorDustBalance } from './utils/formatMidnightConnectorDustBalance/formatMidnightConnectorDustBalance.js';
|
|
15
|
+
export { isMidnightWallet } from '@dynamic-labs/wallet-connector-core';
|
|
15
16
|
|
|
16
17
|
/* istanbul ignore file */
|
|
17
18
|
/* istanbul ignore next */
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Converts a ledger atomic amount (bigint) to a decimal string for display
|
|
8
|
+
* (no thousands separators), using the given number of fractional decimal places.
|
|
9
|
+
*/
|
|
10
|
+
const formatMidnightAtomicBalance = (atomicAmount, decimals) => {
|
|
11
|
+
const base = BigInt(Math.pow(10, decimals));
|
|
12
|
+
const negative = atomicAmount < BigInt(0);
|
|
13
|
+
const abs = negative ? -atomicAmount : atomicAmount;
|
|
14
|
+
const whole = abs / base;
|
|
15
|
+
const frac = abs % base;
|
|
16
|
+
const paddedFrac = frac.toString(10).padStart(decimals, '0');
|
|
17
|
+
let end = paddedFrac.length;
|
|
18
|
+
while (end > 0 && paddedFrac[end - 1] === '0') {
|
|
19
|
+
end -= 1;
|
|
20
|
+
}
|
|
21
|
+
const fracStr = paddedFrac.slice(0, end);
|
|
22
|
+
const sign = negative ? '-' : '';
|
|
23
|
+
if (fracStr.length === 0) {
|
|
24
|
+
return `${sign}${whole.toString(10)}`;
|
|
25
|
+
}
|
|
26
|
+
return `${sign}${whole.toString(10)}.${fracStr}`;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.formatMidnightAtomicBalance = formatMidnightAtomicBalance;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a ledger atomic amount (bigint) to a decimal string for display
|
|
3
|
+
* (no thousands separators), using the given number of fractional decimal places.
|
|
4
|
+
*/
|
|
5
|
+
export declare const formatMidnightAtomicBalance: (atomicAmount: bigint, decimals: number) => string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
/**
|
|
3
|
+
* Converts a ledger atomic amount (bigint) to a decimal string for display
|
|
4
|
+
* (no thousands separators), using the given number of fractional decimal places.
|
|
5
|
+
*/
|
|
6
|
+
const formatMidnightAtomicBalance = (atomicAmount, decimals) => {
|
|
7
|
+
const base = BigInt(Math.pow(10, decimals));
|
|
8
|
+
const negative = atomicAmount < BigInt(0);
|
|
9
|
+
const abs = negative ? -atomicAmount : atomicAmount;
|
|
10
|
+
const whole = abs / base;
|
|
11
|
+
const frac = abs % base;
|
|
12
|
+
const paddedFrac = frac.toString(10).padStart(decimals, '0');
|
|
13
|
+
let end = paddedFrac.length;
|
|
14
|
+
while (end > 0 && paddedFrac[end - 1] === '0') {
|
|
15
|
+
end -= 1;
|
|
16
|
+
}
|
|
17
|
+
const fracStr = paddedFrac.slice(0, end);
|
|
18
|
+
const sign = negative ? '-' : '';
|
|
19
|
+
if (fracStr.length === 0) {
|
|
20
|
+
return `${sign}${whole.toString(10)}`;
|
|
21
|
+
}
|
|
22
|
+
return `${sign}${whole.toString(10)}.${fracStr}`;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { formatMidnightAtomicBalance };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { formatMidnightAtomicBalance } from './formatMidnightAtomicBalance';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var constants = require('../../constants.cjs');
|
|
7
|
+
var formatMidnightAtomicBalance = require('../formatMidnightAtomicBalance/formatMidnightAtomicBalance.cjs');
|
|
8
|
+
var formatMidnightNativeUnshieldedBalance = require('../formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.cjs');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Formats ConnectedAPI `getDustBalance()` fields for display.
|
|
12
|
+
* Wallets report `balance` in ledger Specks (1 DUST = 10^15 Specks) and `cap` in the
|
|
13
|
+
* same micro-unit scale as unshielded NIGHT (1 display unit = 10^6 atoms).
|
|
14
|
+
*/
|
|
15
|
+
const formatMidnightConnectorDustBalance = (balanceSpecks, capMicroDust) => ({
|
|
16
|
+
balance: formatMidnightAtomicBalance.formatMidnightAtomicBalance(balanceSpecks, constants.MIDNIGHT_DUST_BALANCE_SPECK_DECIMALS),
|
|
17
|
+
cap: formatMidnightNativeUnshieldedBalance.formatMidnightNativeUnshieldedBalance(capMicroDust),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
exports.formatMidnightConnectorDustBalance = formatMidnightConnectorDustBalance;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats ConnectedAPI `getDustBalance()` fields for display.
|
|
3
|
+
* Wallets report `balance` in ledger Specks (1 DUST = 10^15 Specks) and `cap` in the
|
|
4
|
+
* same micro-unit scale as unshielded NIGHT (1 display unit = 10^6 atoms).
|
|
5
|
+
*/
|
|
6
|
+
export declare const formatMidnightConnectorDustBalance: (balanceSpecks: bigint, capMicroDust: bigint) => {
|
|
7
|
+
balance: string;
|
|
8
|
+
cap: string;
|
|
9
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { MIDNIGHT_DUST_BALANCE_SPECK_DECIMALS } from '../../constants.js';
|
|
3
|
+
import { formatMidnightAtomicBalance } from '../formatMidnightAtomicBalance/formatMidnightAtomicBalance.js';
|
|
4
|
+
import { formatMidnightNativeUnshieldedBalance } from '../formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Formats ConnectedAPI `getDustBalance()` fields for display.
|
|
8
|
+
* Wallets report `balance` in ledger Specks (1 DUST = 10^15 Specks) and `cap` in the
|
|
9
|
+
* same micro-unit scale as unshielded NIGHT (1 display unit = 10^6 atoms).
|
|
10
|
+
*/
|
|
11
|
+
const formatMidnightConnectorDustBalance = (balanceSpecks, capMicroDust) => ({
|
|
12
|
+
balance: formatMidnightAtomicBalance(balanceSpecks, MIDNIGHT_DUST_BALANCE_SPECK_DECIMALS),
|
|
13
|
+
cap: formatMidnightNativeUnshieldedBalance(capMicroDust),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export { formatMidnightConnectorDustBalance };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { formatMidnightConnectorDustBalance } from './formatMidnightConnectorDustBalance';
|
package/src/utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.cjs
CHANGED
|
@@ -4,29 +4,12 @@
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
6
|
var constants = require('../../constants.cjs');
|
|
7
|
+
var formatMidnightAtomicBalance = require('../formatMidnightAtomicBalance/formatMidnightAtomicBalance.cjs');
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Converts a native unshielded balance from ledger atomic units to a decimal string
|
|
10
11
|
* for display (no thousands separators), e.g. 999999999n → "999.999999".
|
|
11
12
|
*/
|
|
12
|
-
const formatMidnightNativeUnshieldedBalance = (atomicAmount) =>
|
|
13
|
-
const decimals = constants.MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS;
|
|
14
|
-
const base = BigInt(Math.pow(10, decimals));
|
|
15
|
-
const negative = atomicAmount < BigInt(0);
|
|
16
|
-
const abs = negative ? -atomicAmount : atomicAmount;
|
|
17
|
-
const whole = abs / base;
|
|
18
|
-
const frac = abs % base;
|
|
19
|
-
const paddedFrac = frac.toString(10).padStart(decimals, '0');
|
|
20
|
-
let end = paddedFrac.length;
|
|
21
|
-
while (end > 0 && paddedFrac[end - 1] === '0') {
|
|
22
|
-
end -= 1;
|
|
23
|
-
}
|
|
24
|
-
const fracStr = paddedFrac.slice(0, end);
|
|
25
|
-
const sign = negative ? '-' : '';
|
|
26
|
-
if (fracStr.length === 0) {
|
|
27
|
-
return `${sign}${whole.toString(10)}`;
|
|
28
|
-
}
|
|
29
|
-
return `${sign}${whole.toString(10)}.${fracStr}`;
|
|
30
|
-
};
|
|
13
|
+
const formatMidnightNativeUnshieldedBalance = (atomicAmount) => formatMidnightAtomicBalance.formatMidnightAtomicBalance(atomicAmount, constants.MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS);
|
|
31
14
|
|
|
32
15
|
exports.formatMidnightNativeUnshieldedBalance = formatMidnightNativeUnshieldedBalance;
|
package/src/utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.js
CHANGED
|
@@ -1,28 +1,11 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS } from '../../constants.js';
|
|
3
|
+
import { formatMidnightAtomicBalance } from '../formatMidnightAtomicBalance/formatMidnightAtomicBalance.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Converts a native unshielded balance from ledger atomic units to a decimal string
|
|
6
7
|
* for display (no thousands separators), e.g. 999999999n → "999.999999".
|
|
7
8
|
*/
|
|
8
|
-
const formatMidnightNativeUnshieldedBalance = (atomicAmount) =>
|
|
9
|
-
const decimals = MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS;
|
|
10
|
-
const base = BigInt(Math.pow(10, decimals));
|
|
11
|
-
const negative = atomicAmount < BigInt(0);
|
|
12
|
-
const abs = negative ? -atomicAmount : atomicAmount;
|
|
13
|
-
const whole = abs / base;
|
|
14
|
-
const frac = abs % base;
|
|
15
|
-
const paddedFrac = frac.toString(10).padStart(decimals, '0');
|
|
16
|
-
let end = paddedFrac.length;
|
|
17
|
-
while (end > 0 && paddedFrac[end - 1] === '0') {
|
|
18
|
-
end -= 1;
|
|
19
|
-
}
|
|
20
|
-
const fracStr = paddedFrac.slice(0, end);
|
|
21
|
-
const sign = negative ? '-' : '';
|
|
22
|
-
if (fracStr.length === 0) {
|
|
23
|
-
return `${sign}${whole.toString(10)}`;
|
|
24
|
-
}
|
|
25
|
-
return `${sign}${whole.toString(10)}.${fracStr}`;
|
|
26
|
-
};
|
|
9
|
+
const formatMidnightNativeUnshieldedBalance = (atomicAmount) => formatMidnightAtomicBalance(atomicAmount, MIDNIGHT_NATIVE_UNSHIELDED_DECIMALS);
|
|
27
10
|
|
|
28
11
|
export { formatMidnightNativeUnshieldedBalance };
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
6
6
|
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
7
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
8
|
var constants = require('../constants.cjs');
|
|
9
|
+
var formatMidnightConnectorDustBalance = require('../utils/formatMidnightConnectorDustBalance/formatMidnightConnectorDustBalance.cjs');
|
|
9
10
|
var formatMidnightNativeUnshieldedBalance = require('../utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.cjs');
|
|
10
11
|
|
|
11
12
|
class MidnightWallet extends walletConnectorCore.Wallet {
|
|
@@ -59,9 +60,25 @@ class MidnightWallet extends walletConnectorCore.Wallet {
|
|
|
59
60
|
getDustBalance() {
|
|
60
61
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
61
62
|
const { balance, cap } = yield this._connector.getDustBalance();
|
|
63
|
+
return formatMidnightConnectorDustBalance.formatMidnightConnectorDustBalance(balance, cap);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
getFormattedBalances() {
|
|
67
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const raw = yield this._connector.getBalances();
|
|
69
|
+
const shieldedRaw = raw.shielded[constants.MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE];
|
|
70
|
+
const unshieldedRaw = raw.unshielded[constants.MIDNIGHT_NATIVE_TOKEN_TYPE];
|
|
71
|
+
const dustEmpty = raw.dust.balance === BigInt(0) && raw.dust.cap === BigInt(0);
|
|
62
72
|
return {
|
|
63
|
-
|
|
64
|
-
|
|
73
|
+
dustBalance: dustEmpty
|
|
74
|
+
? undefined
|
|
75
|
+
: formatMidnightConnectorDustBalance.formatMidnightConnectorDustBalance(raw.dust.balance, raw.dust.cap),
|
|
76
|
+
shieldedBalance: shieldedRaw !== undefined
|
|
77
|
+
? formatMidnightNativeUnshieldedBalance.formatMidnightNativeUnshieldedBalance(shieldedRaw)
|
|
78
|
+
: undefined,
|
|
79
|
+
unshieldedBalance: unshieldedRaw !== undefined
|
|
80
|
+
? formatMidnightNativeUnshieldedBalance.formatMidnightNativeUnshieldedBalance(unshieldedRaw)
|
|
81
|
+
: undefined,
|
|
65
82
|
};
|
|
66
83
|
});
|
|
67
84
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TokenType } from '@midnight-ntwrk/dapp-connector-api';
|
|
2
|
-
import { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
import { type MidnightFormattedBalances, Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
3
3
|
import { WalletAddressType } from '@dynamic-labs/sdk-api-core';
|
|
4
4
|
import { MidnightWalletConnector } from '../connectors/MidnightWalletConnector';
|
|
5
5
|
export declare class MidnightWallet extends Wallet<MidnightWalletConnector> {
|
|
@@ -27,4 +27,5 @@ export declare class MidnightWallet extends Wallet<MidnightWalletConnector> {
|
|
|
27
27
|
balance: string;
|
|
28
28
|
cap: string;
|
|
29
29
|
}>;
|
|
30
|
+
getFormattedBalances(): Promise<MidnightFormattedBalances>;
|
|
30
31
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
3
|
import { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
4
4
|
import { MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE, MIDNIGHT_NATIVE_TOKEN_TYPE } from '../constants.js';
|
|
5
|
+
import { formatMidnightConnectorDustBalance } from '../utils/formatMidnightConnectorDustBalance/formatMidnightConnectorDustBalance.js';
|
|
5
6
|
import { formatMidnightNativeUnshieldedBalance } from '../utils/formatMidnightNativeUnshieldedBalance/formatMidnightNativeUnshieldedBalance.js';
|
|
6
7
|
|
|
7
8
|
class MidnightWallet extends Wallet {
|
|
@@ -55,9 +56,25 @@ class MidnightWallet extends Wallet {
|
|
|
55
56
|
getDustBalance() {
|
|
56
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
58
|
const { balance, cap } = yield this._connector.getDustBalance();
|
|
59
|
+
return formatMidnightConnectorDustBalance(balance, cap);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
getFormattedBalances() {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
const raw = yield this._connector.getBalances();
|
|
65
|
+
const shieldedRaw = raw.shielded[MIDNIGHT_NATIVE_SHIELDED_TOKEN_TYPE];
|
|
66
|
+
const unshieldedRaw = raw.unshielded[MIDNIGHT_NATIVE_TOKEN_TYPE];
|
|
67
|
+
const dustEmpty = raw.dust.balance === BigInt(0) && raw.dust.cap === BigInt(0);
|
|
58
68
|
return {
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
dustBalance: dustEmpty
|
|
70
|
+
? undefined
|
|
71
|
+
: formatMidnightConnectorDustBalance(raw.dust.balance, raw.dust.cap),
|
|
72
|
+
shieldedBalance: shieldedRaw !== undefined
|
|
73
|
+
? formatMidnightNativeUnshieldedBalance(shieldedRaw)
|
|
74
|
+
: undefined,
|
|
75
|
+
unshieldedBalance: unshieldedRaw !== undefined
|
|
76
|
+
? formatMidnightNativeUnshieldedBalance(unshieldedRaw)
|
|
77
|
+
: undefined,
|
|
61
78
|
};
|
|
62
79
|
});
|
|
63
80
|
}
|
|
@@ -1,3 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { MidnightWallet } from '../MidnightWallet';
|
|
3
|
-
export declare const isMidnightWallet: (wallet: Wallet) => wallet is MidnightWallet;
|
|
1
|
+
export { isMidnightWallet } from '@dynamic-labs/wallet-connector-core';
|