Skip to content

Commit 336a324

Browse files
authored
Merge pull request #7 from MeshJS/fix/get-balance-mesh
Fix/get balance mesh
2 parents 331fb84 + bae4aed commit 336a324

5 files changed

Lines changed: 55 additions & 8 deletions

File tree

package-lock.json

Lines changed: 11 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@meshsdk/wallet",
3-
"version": "2.0.0-beta.8",
3+
"version": "2.0.0-beta.9",
44
"description": "Wallets - https://meshjs.dev/apis/wallets",
55
"main": "./dist/index.cjs",
66
"browser": "./dist/index.js",
@@ -34,7 +34,8 @@
3434
"@ianvs/prettier-plugin-sort-imports": "^4.4.1",
3535
"@meshsdk/common": "1.9.0-beta.100",
3636
"@meshsdk/provider": "1.9.0-beta.99",
37-
"@types/jest": "^29.5.12",
37+
"@types/jest": "^29.5.14",
38+
"@types/mocha": "^10.0.10",
3839
"dotenv": "^16.4.5",
3940
"eslint": "^8.57.0",
4041
"jest": "^29.7.0",

src/cardano/wallet/mesh/mesh-wallet.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Cardano, Serialization } from "@cardano-sdk/core";
22
import { HexBlob } from "@cardano-sdk/util";
33

4-
import { Asset, UTxO } from "@meshsdk/common";
4+
import { Asset, MeshValue, UTxO } from "@meshsdk/common";
55

66
import { CardanoInMemoryBip32 } from "../../../bip32/cardano-in-memory-bip32";
77
import {
@@ -159,7 +159,9 @@ export class MeshCardanoHeadlessWallet extends CardanoHeadlessWallet {
159159
throw new Error("[CardanoWallet] No fetcher provided");
160160
}
161161
const utxos = await this.fetchAccountUtxos();
162-
return utxos.map((utxo) => utxo.output.amount).flat();
162+
const values = utxos.map((utxo) => utxo.output.amount).flat();
163+
const meshValue = MeshValue.fromAssets(values);
164+
return meshValue.toAssets();
163165
}
164166

165167
/**

test/utils/value.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { MeshValue } from "@meshsdk/common";
2+
3+
describe("Value", () => {
4+
it("conversion to and from mesh value should combine assets", () => {
5+
expect(
6+
MeshValue.fromAssets([
7+
{
8+
unit: "lovelace",
9+
quantity: "1172951349",
10+
},
11+
{
12+
unit: "lovelace",
13+
quantity: "998427280116",
14+
},
15+
{
16+
unit: "lovelace",
17+
quantity: "2000000",
18+
},
19+
{
20+
unit: "922827a68ed2e816886d8f271c03f8342dfb53a45bd0a9f5ccc0ed94",
21+
quantity: "1502000000",
22+
},
23+
]).toAssets(),
24+
).toEqual([
25+
{
26+
unit: "lovelace",
27+
quantity: "999602231465",
28+
},
29+
{
30+
unit: "922827a68ed2e816886d8f271c03f8342dfb53a45bd0a9f5ccc0ed94",
31+
quantity: "1502000000",
32+
},
33+
]);
34+
});
35+
});

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"display": "Default",
4-
"include": ["src/**/*"],
4+
"include": ["src/**/*", "test/**/*", "jest.config.ts"],
55
"exclude": ["dist", "node_modules"],
66
"compilerOptions": {
77
"target": "ES2020",
88
"lib": ["ES2020", "DOM"],
9+
"types": ["jest", "node"],
910
"module": "commonjs",
1011
"esModuleInterop": true,
1112
"allowSyntheticDefaultImports": true

0 commit comments

Comments
 (0)