@pax2pay/model-banking 0.1.388 → 0.1.389

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.
@@ -20,20 +20,31 @@ export interface Transaction extends ModelTransaction.Creatable {
20
20
  export namespace Transaction {
21
21
  export function from(
22
22
  accountName: string,
23
- transaction: ModelTransaction.Creatable & { counterpart: Address },
23
+ transaction: (ModelTransaction.Creatable & { counterpart: Address }) | ModelTransaction,
24
24
  kind: Rule.Base.Kind,
25
25
  stage: "finalize" | "initiate"
26
26
  ): Transaction {
27
+ const [amount, total] =
28
+ "state" in transaction
29
+ ? [
30
+ transaction.state?.transaction.original.amount ?? transaction.amount,
31
+ isoly.Currency.subtract(
32
+ transaction.currency,
33
+ transaction.state?.transaction.original.total ?? transaction.amount,
34
+ stage === "finalize" ? transaction.state?.transaction.original.reserve ?? 0 : 0
35
+ ),
36
+ ]
37
+ : [transaction.amount, transaction.amount]
27
38
  return {
28
39
  ...transaction,
29
40
  stage,
30
41
  kind,
31
- amount: Math.abs(transaction.amount),
42
+ amount: Math.abs(amount),
32
43
  type: ModelTransaction.getType(transaction.counterpart, accountName),
33
44
  original: {
34
45
  currency: transaction.currency,
35
- amount: Math.abs(transaction.amount),
36
- total: Math.abs(transaction.amount),
46
+ amount: Math.abs(amount),
47
+ total: Math.abs(total),
37
48
  },
38
49
  }
39
50
  }
@@ -20,7 +20,7 @@ export interface Transaction extends ModelTransaction.Creatable {
20
20
  };
21
21
  }
22
22
  export declare namespace Transaction {
23
- function from(accountName: string, transaction: ModelTransaction.Creatable & {
23
+ function from(accountName: string, transaction: (ModelTransaction.Creatable & {
24
24
  counterpart: Address;
25
- }, kind: Rule.Base.Kind, stage: "finalize" | "initiate"): Transaction;
25
+ }) | ModelTransaction, kind: Rule.Base.Kind, stage: "finalize" | "initiate"): Transaction;
26
26
  }
@@ -1,17 +1,24 @@
1
+ import { isoly } from "isoly";
1
2
  import { Transaction as ModelTransaction } from "../../Transaction";
2
3
  export var Transaction;
3
4
  (function (Transaction) {
4
5
  function from(accountName, transaction, kind, stage) {
6
+ const [amount, total] = "state" in transaction
7
+ ? [
8
+ transaction.state?.transaction.original.amount ?? transaction.amount,
9
+ isoly.Currency.subtract(transaction.currency, transaction.state?.transaction.original.total ?? transaction.amount, stage === "finalize" ? transaction.state?.transaction.original.reserve ?? 0 : 0),
10
+ ]
11
+ : [transaction.amount, transaction.amount];
5
12
  return {
6
13
  ...transaction,
7
14
  stage,
8
15
  kind,
9
- amount: Math.abs(transaction.amount),
16
+ amount: Math.abs(amount),
10
17
  type: ModelTransaction.getType(transaction.counterpart, accountName),
11
18
  original: {
12
19
  currency: transaction.currency,
13
- amount: Math.abs(transaction.amount),
14
- total: Math.abs(transaction.amount),
20
+ amount: Math.abs(amount),
21
+ total: Math.abs(total),
15
22
  },
16
23
  };
17
24
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Transaction.js","sourceRoot":"../","sources":["Rule/State/Transaction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,IAAI,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAiBnE,MAAM,KAAW,WAAW,CAoB3B;AApBD,WAAiB,WAAW;IAC3B,SAAgB,IAAI,CACnB,WAAmB,EACnB,WAAkE,EAClE,IAAoB,EACpB,KAA8B;QAE9B,OAAO;YACN,GAAG,WAAW;YACd,KAAK;YACL,IAAI;YACJ,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC;YACpC,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC,WAAW,CAAC,WAAW,EAAE,WAAW,CAAC;YACpE,QAAQ,EAAE;gBACT,QAAQ,EAAE,WAAW,CAAC,QAAQ;gBAC9B,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC;gBACpC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC;aACnC;SACD,CAAA;IACF,CA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M,CAAC;gBACxB,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;aACtB;SACD,CAAA;IACF,CAAC;IA7Be,gBAAI,OA6BnB,CAAA;AACF,CAAC,EA/BgB,WAAW,KAAX,WAAW,QA+B3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pax2pay/model-banking",
3
- "version": "0.1.388",
3
+ "version": "0.1.389",
4
4
  "description": "Library containing data model types and functions for the Pax2Pay Banking API.",
5
5
  "author": "Pax2Pay Ltd",
6
6
  "license": "MIT",