@metamask-previews/client-utils 1.3.1-preview-2296abeaf → 1.3.1-preview-6c92d881a
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 +0 -4
- package/dist/index.cjs +1 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +0 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +1 -1
- package/dist/mappers/helpers/caip.cjs +0 -3
- package/dist/mappers/helpers/caip.cjs.map +1 -1
- package/dist/mappers/helpers/caip.d.cts.map +1 -1
- package/dist/mappers/helpers/caip.d.mts.map +1 -1
- package/dist/mappers/helpers/caip.mjs +0 -3
- package/dist/mappers/helpers/caip.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +2 -30
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +2 -30
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/mappers/ramps-order-mapper.cjs +0 -141
- package/dist/mappers/ramps-order-mapper.cjs.map +0 -1
- package/dist/mappers/ramps-order-mapper.d.cts +0 -49
- package/dist/mappers/ramps-order-mapper.d.cts.map +0 -1
- package/dist/mappers/ramps-order-mapper.d.mts +0 -49
- package/dist/mappers/ramps-order-mapper.d.mts.map +0 -1
- package/dist/mappers/ramps-order-mapper.mjs +0 -137
- package/dist/mappers/ramps-order-mapper.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,10 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
### Added
|
|
11
|
-
|
|
12
|
-
- Add `mapRampsOrder` for mapping ramps buy/sell orders into the shared activity item shape, and add `rampBuy`/`rampSell` to `ActivityKind` and `ActivityItem` ([#9650](https://github.com/MetaMask/core/pull/9650))
|
|
13
|
-
|
|
14
10
|
## [1.3.1]
|
|
15
11
|
|
|
16
12
|
### Changed
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.mapLocalTransaction = exports.mapKeyringTransaction = exports.mapApiTransaction = exports.createFormatters = void 0;
|
|
4
4
|
var create_formatters_js_1 = require("./formatters/create-formatters.cjs");
|
|
5
5
|
Object.defineProperty(exports, "createFormatters", { enumerable: true, get: function () { return create_formatters_js_1.createFormatters; } });
|
|
6
6
|
var api_transaction_mapper_js_1 = require("./mappers/api-transaction-mapper.cjs");
|
|
@@ -9,6 +9,4 @@ var keyring_transaction_mapper_js_1 = require("./mappers/keyring-transaction-map
|
|
|
9
9
|
Object.defineProperty(exports, "mapKeyringTransaction", { enumerable: true, get: function () { return keyring_transaction_mapper_js_1.mapKeyringTransaction; } });
|
|
10
10
|
var local_transaction_mapper_js_1 = require("./mappers/local-transaction-mapper.cjs");
|
|
11
11
|
Object.defineProperty(exports, "mapLocalTransaction", { enumerable: true, get: function () { return local_transaction_mapper_js_1.mapLocalTransaction; } });
|
|
12
|
-
var ramps_order_mapper_js_1 = require("./mappers/ramps-order-mapper.cjs");
|
|
13
|
-
Object.defineProperty(exports, "mapRampsOrder", { enumerable: true, get: function () { return ramps_order_mapper_js_1.mapRampsOrder; } });
|
|
14
12
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2EAAqE;AAA5D,wHAAA,gBAAgB,OAAA;AAGzB,kFAAwE;AAA/D,8HAAA,iBAAiB,OAAA;AAC1B,0FAAgF;AAAvE,sIAAA,qBAAqB,OAAA;AAC9B,sFAA4E;AAAnE,kIAAA,mBAAmB,OAAA
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2EAAqE;AAA5D,wHAAA,gBAAgB,OAAA;AAGzB,kFAAwE;AAA/D,8HAAA,iBAAiB,OAAA;AAC1B,0FAAgF;AAAvE,sIAAA,qBAAqB,OAAA;AAC9B,sFAA4E;AAAnE,kIAAA,mBAAmB,OAAA","sourcesContent":["export { createFormatters } from './formatters/create-formatters.js';\nexport type { Formatters } from './formatters/create-formatters.js';\n\nexport { mapApiTransaction } from './mappers/api-transaction-mapper.js';\nexport { mapKeyringTransaction } from './mappers/keyring-transaction-mapper.js';\nexport { mapLocalTransaction } from './mappers/local-transaction-mapper.js';\n\nexport type * from './types.js';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -3,7 +3,5 @@ export type { Formatters } from "./formatters/create-formatters.cjs";
|
|
|
3
3
|
export { mapApiTransaction } from "./mappers/api-transaction-mapper.cjs";
|
|
4
4
|
export { mapKeyringTransaction } from "./mappers/keyring-transaction-mapper.cjs";
|
|
5
5
|
export { mapLocalTransaction } from "./mappers/local-transaction-mapper.cjs";
|
|
6
|
-
export { mapRampsOrder } from "./mappers/ramps-order-mapper.cjs";
|
|
7
|
-
export type { RampsOrderLike } from "./mappers/ramps-order-mapper.cjs";
|
|
8
6
|
export type * from "./types.cjs";
|
|
9
7
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,2CAA0C;AACrE,YAAY,EAAE,UAAU,EAAE,2CAA0C;AAEpE,OAAO,EAAE,iBAAiB,EAAE,6CAA4C;AACxE,OAAO,EAAE,qBAAqB,EAAE,iDAAgD;AAChF,OAAO,EAAE,mBAAmB,EAAE,+CAA8C;
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,2CAA0C;AACrE,YAAY,EAAE,UAAU,EAAE,2CAA0C;AAEpE,OAAO,EAAE,iBAAiB,EAAE,6CAA4C;AACxE,OAAO,EAAE,qBAAqB,EAAE,iDAAgD;AAChF,OAAO,EAAE,mBAAmB,EAAE,+CAA8C;AAE5E,iCAAgC"}
|
package/dist/index.d.mts
CHANGED
|
@@ -3,7 +3,5 @@ export type { Formatters } from "./formatters/create-formatters.mjs";
|
|
|
3
3
|
export { mapApiTransaction } from "./mappers/api-transaction-mapper.mjs";
|
|
4
4
|
export { mapKeyringTransaction } from "./mappers/keyring-transaction-mapper.mjs";
|
|
5
5
|
export { mapLocalTransaction } from "./mappers/local-transaction-mapper.mjs";
|
|
6
|
-
export { mapRampsOrder } from "./mappers/ramps-order-mapper.mjs";
|
|
7
|
-
export type { RampsOrderLike } from "./mappers/ramps-order-mapper.mjs";
|
|
8
6
|
export type * from "./types.mjs";
|
|
9
7
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,2CAA0C;AACrE,YAAY,EAAE,UAAU,EAAE,2CAA0C;AAEpE,OAAO,EAAE,iBAAiB,EAAE,6CAA4C;AACxE,OAAO,EAAE,qBAAqB,EAAE,iDAAgD;AAChF,OAAO,EAAE,mBAAmB,EAAE,+CAA8C;
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,2CAA0C;AACrE,YAAY,EAAE,UAAU,EAAE,2CAA0C;AAEpE,OAAO,EAAE,iBAAiB,EAAE,6CAA4C;AACxE,OAAO,EAAE,qBAAqB,EAAE,iDAAgD;AAChF,OAAO,EAAE,mBAAmB,EAAE,+CAA8C;AAE5E,iCAAgC"}
|
package/dist/index.mjs
CHANGED
|
@@ -2,5 +2,4 @@ export { createFormatters } from "./formatters/create-formatters.mjs";
|
|
|
2
2
|
export { mapApiTransaction } from "./mappers/api-transaction-mapper.mjs";
|
|
3
3
|
export { mapKeyringTransaction } from "./mappers/keyring-transaction-mapper.mjs";
|
|
4
4
|
export { mapLocalTransaction } from "./mappers/local-transaction-mapper.mjs";
|
|
5
|
-
export { mapRampsOrder } from "./mappers/ramps-order-mapper.mjs";
|
|
6
5
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,2CAA0C;AAGrE,OAAO,EAAE,iBAAiB,EAAE,6CAA4C;AACxE,OAAO,EAAE,qBAAqB,EAAE,iDAAgD;AAChF,OAAO,EAAE,mBAAmB,EAAE,+CAA8C
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,2CAA0C;AAGrE,OAAO,EAAE,iBAAiB,EAAE,6CAA4C;AACxE,OAAO,EAAE,qBAAqB,EAAE,iDAAgD;AAChF,OAAO,EAAE,mBAAmB,EAAE,+CAA8C","sourcesContent":["export { createFormatters } from './formatters/create-formatters.js';\nexport type { Formatters } from './formatters/create-formatters.js';\n\nexport { mapApiTransaction } from './mappers/api-transaction-mapper.js';\nexport { mapKeyringTransaction } from './mappers/keyring-transaction-mapper.js';\nexport { mapLocalTransaction } from './mappers/local-transaction-mapper.js';\n\nexport type * from './types.js';\n"]}
|
|
@@ -22,9 +22,6 @@ function formatChainIdToCaip(chainId) {
|
|
|
22
22
|
const reference = Number.parseInt(chainId, 16);
|
|
23
23
|
return Number.isNaN(reference) ? undefined : `eip155:${reference}`;
|
|
24
24
|
}
|
|
25
|
-
if (chainId === '') {
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
25
|
const reference = Number(chainId);
|
|
29
26
|
return Number.isNaN(reference) ? undefined : `eip155:${reference}`;
|
|
30
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip.cjs","sourceRoot":"","sources":["../../../src/mappers/helpers/caip.ts"],"names":[],"mappings":";;;AAAA,iEAAkE;AAElE,2CAKyB;AAEzB,mDAAqD;AAErD;;;;;;GAMG;AACH,SAAgB,mBAAmB,CACjC,OAAwB;IAExB,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,UAAU,OAAO,EAAE,CAAC;IAC7B,CAAC;IAED,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,OAAsB,CAAC;IAChC,CAAC;IAED,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7B,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAC/C,OAAO,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,SAAS,EAAE,CAAC;IACrE,CAAC;IAED,
|
|
1
|
+
{"version":3,"file":"caip.cjs","sourceRoot":"","sources":["../../../src/mappers/helpers/caip.ts"],"names":[],"mappings":";;;AAAA,iEAAkE;AAElE,2CAKyB;AAEzB,mDAAqD;AAErD;;;;;;GAMG;AACH,SAAgB,mBAAmB,CACjC,OAAwB;IAExB,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,UAAU,OAAO,EAAE,CAAC;IAC7B,CAAC;IAED,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1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AAkB,CAAC,EAAE,CAAC;QAC3C,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;IAE/D,OAAO,IAAA,uBAAe,EAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC;AAC5E,CAAC;AA3BD,wDA2BC","sourcesContent":["import { toChecksumHexAddress } from '@metamask/controller-utils';\nimport type { CaipAssetType, CaipChainId, Hex } from '@metamask/utils';\nimport {\n isCaipAssetType,\n isStrictHexString,\n parseCaipChainId,\n toCaipAssetType,\n} from '@metamask/utils';\n\nimport { nativeTokenAddress } from '../constants.js';\n\n/**\n * Normalizes a hex, decimal, numeric, or CAIP chain id to its CAIP-2 form.\n * Only EVM (eip155) chains are normalized here; CAIP ids are returned as-is.\n *\n * @param chainId - Hex (`0x1`), numeric, decimal string, or CAIP chain id.\n * @returns The CAIP-2 chain id, or `undefined` when it can't be normalized.\n */\nexport function formatChainIdToCaip(\n chainId: string | number,\n): CaipChainId | undefined {\n if (typeof chainId === 'number') {\n return `eip155:${chainId}`;\n }\n\n if (chainId.includes(':')) {\n return chainId as CaipChainId;\n }\n\n if (chainId.startsWith('0x')) {\n const reference = Number.parseInt(chainId, 16);\n return Number.isNaN(reference) ? undefined : `eip155:${reference}`;\n }\n\n const reference = Number(chainId);\n return Number.isNaN(reference) ? undefined : `eip155:${reference}`;\n}\n\nfunction isNativeAddress(address: string): boolean {\n const normalized = address.toLowerCase();\n return (\n normalized === nativeTokenAddress ||\n normalized === '0x0' ||\n /^0x0+$/u.test(normalized)\n );\n}\n\n/**\n * Encodes an EVM token address + chain id into a CAIP-19 asset id.\n *\n * @param address - Hex contract address, native sentinel, or CAIP asset id.\n * @param chainId - CAIP-2 or hex chain id.\n * @returns The CAIP-19 asset id, or `undefined` when it can't be encoded.\n */\nexport function formatAddressToAssetId(\n address: Hex | CaipAssetType | string,\n chainId?: CaipChainId | Hex,\n): CaipAssetType | undefined {\n if (isCaipAssetType(address)) {\n return address;\n }\n\n const caipChainId = chainId ? formatChainIdToCaip(chainId) : undefined;\n\n if (!caipChainId) {\n return undefined;\n }\n\n if (isNativeAddress(address)) {\n return undefined;\n }\n\n const checksummedAddress = toChecksumHexAddress(address);\n\n if (!isStrictHexString(checksummedAddress)) {\n return undefined;\n }\n\n const { namespace, reference } = parseCaipChainId(caipChainId);\n\n return toCaipAssetType(namespace, reference, 'erc20', checksummedAddress);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip.d.cts","sourceRoot":"","sources":["../../../src/mappers/helpers/caip.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAUvE;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,GAAG,MAAM,GACvB,WAAW,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"caip.d.cts","sourceRoot":"","sources":["../../../src/mappers/helpers/caip.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAUvE;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,GAAG,MAAM,GACvB,WAAW,GAAG,SAAS,CAgBzB;AAWD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,GAAG,GAAG,aAAa,GAAG,MAAM,EACrC,OAAO,CAAC,EAAE,WAAW,GAAG,GAAG,GAC1B,aAAa,GAAG,SAAS,CAwB3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip.d.mts","sourceRoot":"","sources":["../../../src/mappers/helpers/caip.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAUvE;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,GAAG,MAAM,GACvB,WAAW,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"caip.d.mts","sourceRoot":"","sources":["../../../src/mappers/helpers/caip.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAUvE;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,GAAG,MAAM,GACvB,WAAW,GAAG,SAAS,CAgBzB;AAWD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,GAAG,GAAG,aAAa,GAAG,MAAM,EACrC,OAAO,CAAC,EAAE,WAAW,GAAG,GAAG,GAC1B,aAAa,GAAG,SAAS,CAwB3B"}
|
|
@@ -19,9 +19,6 @@ export function formatChainIdToCaip(chainId) {
|
|
|
19
19
|
const reference = Number.parseInt(chainId, 16);
|
|
20
20
|
return Number.isNaN(reference) ? undefined : `eip155:${reference}`;
|
|
21
21
|
}
|
|
22
|
-
if (chainId === '') {
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
22
|
const reference = Number(chainId);
|
|
26
23
|
return Number.isNaN(reference) ? undefined : `eip155:${reference}`;
|
|
27
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip.mjs","sourceRoot":"","sources":["../../../src/mappers/helpers/caip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,mCAAmC;AAElE,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EAChB,wBAAwB;AAEzB,OAAO,EAAE,kBAAkB,EAAE,yBAAwB;AAErD;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,OAAwB;IAExB,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,UAAU,OAAO,EAAE,CAAC;IAC7B,CAAC;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,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,SAAS,EAAE,CAAC;AACrE,CAAC;AAED,SAAS,eAAe,CAAC,OAAe;IACtC,MAAM,UAAU,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IACzC,OAAO,CACL,UAAU,KAAK,kBAAkB;QACjC,UAAU,KAAK,KAAK;QACpB,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAC3B,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CACpC,OAAqC,EACrC,OAA2B;IAE3B,IAAI,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAEvE,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,kBAAkB,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAEzD,IAAI,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAC3C,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAE/D,OAAO,eAAe,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["import { toChecksumHexAddress } from '@metamask/controller-utils';\nimport type { CaipAssetType, CaipChainId, Hex } from '@metamask/utils';\nimport {\n isCaipAssetType,\n isStrictHexString,\n parseCaipChainId,\n toCaipAssetType,\n} from '@metamask/utils';\n\nimport { nativeTokenAddress } from '../constants.js';\n\n/**\n * Normalizes a hex, decimal, numeric, or CAIP chain id to its CAIP-2 form.\n * Only EVM (eip155) chains are normalized here; CAIP ids are returned as-is.\n *\n * @param chainId - Hex (`0x1`), numeric, decimal string, or CAIP chain id.\n * @returns The CAIP-2 chain id, or `undefined` when it can't be normalized.\n */\nexport function formatChainIdToCaip(\n chainId: string | number,\n): CaipChainId | undefined {\n if (typeof chainId === 'number') {\n return `eip155:${chainId}`;\n }\n\n if (chainId.includes(':')) {\n return chainId as CaipChainId;\n }\n\n if (chainId.startsWith('0x')) {\n const reference = Number.parseInt(chainId, 16);\n return Number.isNaN(reference) ? undefined : `eip155:${reference}`;\n }\n\n const reference = Number(chainId);\n return Number.isNaN(reference) ? undefined : `eip155:${reference}`;\n}\n\nfunction isNativeAddress(address: string): boolean {\n const normalized = address.toLowerCase();\n return (\n normalized === nativeTokenAddress ||\n normalized === '0x0' ||\n /^0x0+$/u.test(normalized)\n );\n}\n\n/**\n * Encodes an EVM token address + chain id into a CAIP-19 asset id.\n *\n * @param address - Hex contract address, native sentinel, or CAIP asset id.\n * @param chainId - CAIP-2 or hex chain id.\n * @returns The CAIP-19 asset id, or `undefined` when it can't be encoded.\n */\nexport function formatAddressToAssetId(\n address: Hex | CaipAssetType | string,\n chainId?: CaipChainId | Hex,\n): CaipAssetType | undefined {\n if (isCaipAssetType(address)) {\n return address;\n }\n\n const caipChainId = chainId ? formatChainIdToCaip(chainId) : undefined;\n\n if (!caipChainId) {\n return undefined;\n }\n\n if (isNativeAddress(address)) {\n return undefined;\n }\n\n const checksummedAddress = toChecksumHexAddress(address);\n\n if (!isStrictHexString(checksummedAddress)) {\n return undefined;\n }\n\n const { namespace, reference } = parseCaipChainId(caipChainId);\n\n return toCaipAssetType(namespace, reference, 'erc20', checksummedAddress);\n}\n"]}
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ValueTransfer as _ValueTransfer } from '@metamask/core-backend';\nimport type { CaipChainId } from '@metamask/utils';\n\nexport type ActivityKind =\n | 'receive'\n | 'sell'\n | 'buy'\n | 'deposit'\n | 'swap'\n | 'claim'\n | 'claimMusdBonus'\n | 'send'\n | 'wrap'\n | 'unwrap'\n | 'approveSpendingCap'\n | 'revokeSpendingCap'\n | 'increaseSpendingCap'\n | 'contractInteraction'\n | 'contractDeployment'\n | 'bridge'\n | 'convert'\n | 'nftBuy'\n | 'nftMint'\n | 'nftSell'\n | 'smartAccountUpgrade'\n | 'lendingDeposit'\n | 'lendingWithdrawal'\n | 'predictionsAddFunds'\n | 'predictionsWithdrawFunds'\n | 'predictionClaimWinnings'\n | 'predictionCashedOut'\n | 'predictionPlaced'\n | 'perpsAddFunds'\n | 'perpsWithdraw'\n | 'perpsOpenLong'\n | 'perpsCloseLong'\n | 'perpsCloseLongLiquidated'\n | 'perpsCloseLongStopLoss'\n | 'perpsOpenShort'\n | 'perpsCloseShort'\n | 'perpsCloseShortLiquidated'\n | 'perpsCloseShortStopLoss'\n | 'perpsPaidFundingFees'\n | 'perpsReceivedFundingFees'\n | 'perpsCloseShortTakeProfit'\n | 'perpsCloseLongTakeProfit'\n | 'marketShort'\n | 'stopMarketCloseShort'\n | 'marketCloseShort'\n | 'assetActivation'\n | 'assetDeactivation'
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ValueTransfer as _ValueTransfer } from '@metamask/core-backend';\nimport type { CaipChainId } from '@metamask/utils';\n\nexport type ActivityKind =\n | 'receive'\n | 'sell'\n | 'buy'\n | 'deposit'\n | 'swap'\n | 'claim'\n | 'claimMusdBonus'\n | 'send'\n | 'wrap'\n | 'unwrap'\n | 'approveSpendingCap'\n | 'revokeSpendingCap'\n | 'increaseSpendingCap'\n | 'contractInteraction'\n | 'contractDeployment'\n | 'bridge'\n | 'convert'\n | 'nftBuy'\n | 'nftMint'\n | 'nftSell'\n | 'smartAccountUpgrade'\n | 'lendingDeposit'\n | 'lendingWithdrawal'\n | 'predictionsAddFunds'\n | 'predictionsWithdrawFunds'\n | 'predictionClaimWinnings'\n | 'predictionCashedOut'\n | 'predictionPlaced'\n | 'perpsAddFunds'\n | 'perpsWithdraw'\n | 'perpsOpenLong'\n | 'perpsCloseLong'\n | 'perpsCloseLongLiquidated'\n | 'perpsCloseLongStopLoss'\n | 'perpsOpenShort'\n | 'perpsCloseShort'\n | 'perpsCloseShortLiquidated'\n | 'perpsCloseShortStopLoss'\n | 'perpsPaidFundingFees'\n | 'perpsReceivedFundingFees'\n | 'perpsCloseShortTakeProfit'\n | 'perpsCloseLongTakeProfit'\n | 'marketShort'\n | 'stopMarketCloseShort'\n | 'marketCloseShort'\n | 'assetActivation'\n | 'assetDeactivation';\n\nexport type Status = 'pending' | 'success' | 'failed' | 'cancelled';\n\nexport type AssetType = 'native' | 'erc20' | 'erc721' | 'erc1155';\n\nexport type TokenAmount = {\n amount?: string;\n decimals?: number;\n symbol?: string;\n assetId?: string;\n assetType?: AssetType;\n direction: 'in' | 'out';\n};\n\nexport type FiatAmount = {\n amount: string;\n currency?: string;\n};\n\nexport type Fee = {\n type: string;\n amount?: string;\n decimals?: number;\n symbol?: string;\n assetId?: string;\n assetType?: AssetType;\n};\n\ntype ActivityData<Type extends ActivityKind, Data> = {\n type: Type;\n chainId: CaipChainId;\n status: Status;\n timestamp: number;\n hash?: string;\n data: Data;\n};\n\nexport type ActivityItem =\n | ActivityData<\n 'approveSpendingCap' | 'revokeSpendingCap' | 'increaseSpendingCap',\n {\n from?: string;\n token?: TokenAmount;\n fees?: Fee[];\n }\n >\n | ActivityData<\n 'assetActivation' | 'assetDeactivation',\n {\n from?: string;\n token?: TokenAmount;\n fees?: Fee[];\n }\n >\n | ActivityData<\n 'send' | 'receive',\n {\n from: string;\n to: string;\n token?: TokenAmount;\n fees?: Fee[];\n }\n >\n | ActivityData<\n 'nftBuy' | 'nftMint' | 'nftSell',\n {\n from?: string;\n to?: string;\n token?: TokenAmount;\n paymentToken?: TokenAmount;\n }\n >\n | ActivityData<\n | 'swap'\n | 'bridge'\n | 'convert'\n | 'lendingDeposit'\n | 'lendingWithdrawal'\n | 'wrap'\n | 'unwrap',\n {\n from?: string;\n sourceToken?: TokenAmount;\n destinationToken?: TokenAmount;\n fees?: Fee[];\n }\n >\n | ActivityData<\n 'buy' | 'claim' | 'deposit' | 'claimMusdBonus',\n {\n from?: string;\n token?: TokenAmount;\n }\n >\n | ActivityData<\n 'perpsAddFunds' | 'perpsWithdraw',\n {\n from?: string;\n fiat?: FiatAmount;\n networkFee?: FiatAmount;\n token?: TokenAmount;\n }\n >\n | ActivityData<\n 'contractInteraction',\n {\n from: string;\n to: string;\n token?: TokenAmount;\n fees?: Fee[];\n methodId?: string;\n transactionCategory?: string;\n transactionProtocol?: string;\n }\n >;\n\n// Note: Update core-backend\nexport type ValueTransfer = _ValueTransfer & {\n contractAddress: string;\n symbol: string;\n name: string;\n};\n"]}
|
package/dist/types.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ValueTransfer as _ValueTransfer } from "@metamask/core-backend";
|
|
2
2
|
import type { CaipChainId } from "@metamask/utils";
|
|
3
|
-
export type ActivityKind = 'receive' | 'sell' | 'buy' | 'deposit' | 'swap' | 'claim' | 'claimMusdBonus' | 'send' | 'wrap' | 'unwrap' | 'approveSpendingCap' | 'revokeSpendingCap' | 'increaseSpendingCap' | 'contractInteraction' | 'contractDeployment' | 'bridge' | 'convert' | 'nftBuy' | 'nftMint' | 'nftSell' | 'smartAccountUpgrade' | 'lendingDeposit' | 'lendingWithdrawal' | 'predictionsAddFunds' | 'predictionsWithdrawFunds' | 'predictionClaimWinnings' | 'predictionCashedOut' | 'predictionPlaced' | 'perpsAddFunds' | 'perpsWithdraw' | 'perpsOpenLong' | 'perpsCloseLong' | 'perpsCloseLongLiquidated' | 'perpsCloseLongStopLoss' | 'perpsOpenShort' | 'perpsCloseShort' | 'perpsCloseShortLiquidated' | 'perpsCloseShortStopLoss' | 'perpsPaidFundingFees' | 'perpsReceivedFundingFees' | 'perpsCloseShortTakeProfit' | 'perpsCloseLongTakeProfit' | 'marketShort' | 'stopMarketCloseShort' | 'marketCloseShort' | 'assetActivation' | 'assetDeactivation'
|
|
3
|
+
export type ActivityKind = 'receive' | 'sell' | 'buy' | 'deposit' | 'swap' | 'claim' | 'claimMusdBonus' | 'send' | 'wrap' | 'unwrap' | 'approveSpendingCap' | 'revokeSpendingCap' | 'increaseSpendingCap' | 'contractInteraction' | 'contractDeployment' | 'bridge' | 'convert' | 'nftBuy' | 'nftMint' | 'nftSell' | 'smartAccountUpgrade' | 'lendingDeposit' | 'lendingWithdrawal' | 'predictionsAddFunds' | 'predictionsWithdrawFunds' | 'predictionClaimWinnings' | 'predictionCashedOut' | 'predictionPlaced' | 'perpsAddFunds' | 'perpsWithdraw' | 'perpsOpenLong' | 'perpsCloseLong' | 'perpsCloseLongLiquidated' | 'perpsCloseLongStopLoss' | 'perpsOpenShort' | 'perpsCloseShort' | 'perpsCloseShortLiquidated' | 'perpsCloseShortStopLoss' | 'perpsPaidFundingFees' | 'perpsReceivedFundingFees' | 'perpsCloseShortTakeProfit' | 'perpsCloseLongTakeProfit' | 'marketShort' | 'stopMarketCloseShort' | 'marketCloseShort' | 'assetActivation' | 'assetDeactivation';
|
|
4
4
|
export type Status = 'pending' | 'success' | 'failed' | 'cancelled';
|
|
5
5
|
export type AssetType = 'native' | 'erc20' | 'erc721' | 'erc1155';
|
|
6
6
|
export type TokenAmount = {
|
|
@@ -31,19 +31,6 @@ type ActivityData<Type extends ActivityKind, Data> = {
|
|
|
31
31
|
hash?: string;
|
|
32
32
|
data: Data;
|
|
33
33
|
};
|
|
34
|
-
/**
|
|
35
|
-
* Bank transfer instruction fields attached to a ramp order by providers
|
|
36
|
-
* that require manual payment (e.g. SEPA, wire transfer).
|
|
37
|
-
*/
|
|
38
|
-
export type RampOrderPaymentDetail = {
|
|
39
|
-
fiatCurrency: string;
|
|
40
|
-
paymentMethod: string;
|
|
41
|
-
fields: {
|
|
42
|
-
name: string;
|
|
43
|
-
id: string;
|
|
44
|
-
value: string;
|
|
45
|
-
}[];
|
|
46
|
-
};
|
|
47
34
|
export type ActivityItem = ActivityData<'approveSpendingCap' | 'revokeSpendingCap' | 'increaseSpendingCap', {
|
|
48
35
|
from?: string;
|
|
49
36
|
token?: TokenAmount;
|
|
@@ -83,22 +70,7 @@ export type ActivityItem = ActivityData<'approveSpendingCap' | 'revokeSpendingCa
|
|
|
83
70
|
methodId?: string;
|
|
84
71
|
transactionCategory?: string;
|
|
85
72
|
transactionProtocol?: string;
|
|
86
|
-
}
|
|
87
|
-
from?: string;
|
|
88
|
-
fiat?: FiatAmount;
|
|
89
|
-
token?: TokenAmount;
|
|
90
|
-
fees?: Fee[];
|
|
91
|
-
provider?: {
|
|
92
|
-
id?: string;
|
|
93
|
-
name?: string;
|
|
94
|
-
orderLink?: string;
|
|
95
|
-
};
|
|
96
|
-
statusDescription?: string;
|
|
97
|
-
paymentDetails?: RampOrderPaymentDetail[];
|
|
98
|
-
id?: string;
|
|
99
|
-
}>, 'chainId'> & {
|
|
100
|
-
chainId?: CaipChainId;
|
|
101
|
-
});
|
|
73
|
+
}>;
|
|
102
74
|
export type ValueTransfer = _ValueTransfer & {
|
|
103
75
|
contractAddress: string;
|
|
104
76
|
symbol: string;
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,IAAI,cAAc,EAAE,+BAA+B;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAEnD,MAAM,MAAM,YAAY,GACpB,SAAS,GACT,MAAM,GACN,KAAK,GACL,SAAS,GACT,MAAM,GACN,OAAO,GACP,gBAAgB,GAChB,MAAM,GACN,MAAM,GACN,QAAQ,GACR,oBAAoB,GACpB,mBAAmB,GACnB,qBAAqB,GACrB,qBAAqB,GACrB,oBAAoB,GACpB,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,SAAS,GACT,SAAS,GACT,qBAAqB,GACrB,gBAAgB,GAChB,mBAAmB,GACnB,qBAAqB,GACrB,0BAA0B,GAC1B,yBAAyB,GACzB,qBAAqB,GACrB,kBAAkB,GAClB,eAAe,GACf,eAAe,GACf,eAAe,GACf,gBAAgB,GAChB,0BAA0B,GAC1B,wBAAwB,GACxB,gBAAgB,GAChB,iBAAiB,GACjB,2BAA2B,GAC3B,yBAAyB,GACzB,sBAAsB,GACtB,0BAA0B,GAC1B,2BAA2B,GAC3B,0BAA0B,GAC1B,aAAa,GACb,sBAAsB,GACtB,kBAAkB,GAClB,iBAAiB,GACjB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,IAAI,cAAc,EAAE,+BAA+B;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAEnD,MAAM,MAAM,YAAY,GACpB,SAAS,GACT,MAAM,GACN,KAAK,GACL,SAAS,GACT,MAAM,GACN,OAAO,GACP,gBAAgB,GAChB,MAAM,GACN,MAAM,GACN,QAAQ,GACR,oBAAoB,GACpB,mBAAmB,GACnB,qBAAqB,GACrB,qBAAqB,GACrB,oBAAoB,GACpB,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,SAAS,GACT,SAAS,GACT,qBAAqB,GACrB,gBAAgB,GAChB,mBAAmB,GACnB,qBAAqB,GACrB,0BAA0B,GAC1B,yBAAyB,GACzB,qBAAqB,GACrB,kBAAkB,GAClB,eAAe,GACf,eAAe,GACf,eAAe,GACf,gBAAgB,GAChB,0BAA0B,GAC1B,wBAAwB,GACxB,gBAAgB,GAChB,iBAAiB,GACjB,2BAA2B,GAC3B,yBAAyB,GACzB,sBA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,CAAC,EAAE,UAAU,CAAC;IACxB,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,CACF,GACD,YAAY,CACV,qBAAqB,EACrB;IACE,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CACF,CAAC;AAGN,MAAM,MAAM,aAAa,GAAG,cAAc,GAAG;IAC3C,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ValueTransfer as _ValueTransfer } from "@metamask/core-backend";
|
|
2
2
|
import type { CaipChainId } from "@metamask/utils";
|
|
3
|
-
export type ActivityKind = 'receive' | 'sell' | 'buy' | 'deposit' | 'swap' | 'claim' | 'claimMusdBonus' | 'send' | 'wrap' | 'unwrap' | 'approveSpendingCap' | 'revokeSpendingCap' | 'increaseSpendingCap' | 'contractInteraction' | 'contractDeployment' | 'bridge' | 'convert' | 'nftBuy' | 'nftMint' | 'nftSell' | 'smartAccountUpgrade' | 'lendingDeposit' | 'lendingWithdrawal' | 'predictionsAddFunds' | 'predictionsWithdrawFunds' | 'predictionClaimWinnings' | 'predictionCashedOut' | 'predictionPlaced' | 'perpsAddFunds' | 'perpsWithdraw' | 'perpsOpenLong' | 'perpsCloseLong' | 'perpsCloseLongLiquidated' | 'perpsCloseLongStopLoss' | 'perpsOpenShort' | 'perpsCloseShort' | 'perpsCloseShortLiquidated' | 'perpsCloseShortStopLoss' | 'perpsPaidFundingFees' | 'perpsReceivedFundingFees' | 'perpsCloseShortTakeProfit' | 'perpsCloseLongTakeProfit' | 'marketShort' | 'stopMarketCloseShort' | 'marketCloseShort' | 'assetActivation' | 'assetDeactivation'
|
|
3
|
+
export type ActivityKind = 'receive' | 'sell' | 'buy' | 'deposit' | 'swap' | 'claim' | 'claimMusdBonus' | 'send' | 'wrap' | 'unwrap' | 'approveSpendingCap' | 'revokeSpendingCap' | 'increaseSpendingCap' | 'contractInteraction' | 'contractDeployment' | 'bridge' | 'convert' | 'nftBuy' | 'nftMint' | 'nftSell' | 'smartAccountUpgrade' | 'lendingDeposit' | 'lendingWithdrawal' | 'predictionsAddFunds' | 'predictionsWithdrawFunds' | 'predictionClaimWinnings' | 'predictionCashedOut' | 'predictionPlaced' | 'perpsAddFunds' | 'perpsWithdraw' | 'perpsOpenLong' | 'perpsCloseLong' | 'perpsCloseLongLiquidated' | 'perpsCloseLongStopLoss' | 'perpsOpenShort' | 'perpsCloseShort' | 'perpsCloseShortLiquidated' | 'perpsCloseShortStopLoss' | 'perpsPaidFundingFees' | 'perpsReceivedFundingFees' | 'perpsCloseShortTakeProfit' | 'perpsCloseLongTakeProfit' | 'marketShort' | 'stopMarketCloseShort' | 'marketCloseShort' | 'assetActivation' | 'assetDeactivation';
|
|
4
4
|
export type Status = 'pending' | 'success' | 'failed' | 'cancelled';
|
|
5
5
|
export type AssetType = 'native' | 'erc20' | 'erc721' | 'erc1155';
|
|
6
6
|
export type TokenAmount = {
|
|
@@ -31,19 +31,6 @@ type ActivityData<Type extends ActivityKind, Data> = {
|
|
|
31
31
|
hash?: string;
|
|
32
32
|
data: Data;
|
|
33
33
|
};
|
|
34
|
-
/**
|
|
35
|
-
* Bank transfer instruction fields attached to a ramp order by providers
|
|
36
|
-
* that require manual payment (e.g. SEPA, wire transfer).
|
|
37
|
-
*/
|
|
38
|
-
export type RampOrderPaymentDetail = {
|
|
39
|
-
fiatCurrency: string;
|
|
40
|
-
paymentMethod: string;
|
|
41
|
-
fields: {
|
|
42
|
-
name: string;
|
|
43
|
-
id: string;
|
|
44
|
-
value: string;
|
|
45
|
-
}[];
|
|
46
|
-
};
|
|
47
34
|
export type ActivityItem = ActivityData<'approveSpendingCap' | 'revokeSpendingCap' | 'increaseSpendingCap', {
|
|
48
35
|
from?: string;
|
|
49
36
|
token?: TokenAmount;
|
|
@@ -83,22 +70,7 @@ export type ActivityItem = ActivityData<'approveSpendingCap' | 'revokeSpendingCa
|
|
|
83
70
|
methodId?: string;
|
|
84
71
|
transactionCategory?: string;
|
|
85
72
|
transactionProtocol?: string;
|
|
86
|
-
}
|
|
87
|
-
from?: string;
|
|
88
|
-
fiat?: FiatAmount;
|
|
89
|
-
token?: TokenAmount;
|
|
90
|
-
fees?: Fee[];
|
|
91
|
-
provider?: {
|
|
92
|
-
id?: string;
|
|
93
|
-
name?: string;
|
|
94
|
-
orderLink?: string;
|
|
95
|
-
};
|
|
96
|
-
statusDescription?: string;
|
|
97
|
-
paymentDetails?: RampOrderPaymentDetail[];
|
|
98
|
-
id?: string;
|
|
99
|
-
}>, 'chainId'> & {
|
|
100
|
-
chainId?: CaipChainId;
|
|
101
|
-
});
|
|
73
|
+
}>;
|
|
102
74
|
export type ValueTransfer = _ValueTransfer & {
|
|
103
75
|
contractAddress: string;
|
|
104
76
|
symbol: string;
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,IAAI,cAAc,EAAE,+BAA+B;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAEnD,MAAM,MAAM,YAAY,GACpB,SAAS,GACT,MAAM,GACN,KAAK,GACL,SAAS,GACT,MAAM,GACN,OAAO,GACP,gBAAgB,GAChB,MAAM,GACN,MAAM,GACN,QAAQ,GACR,oBAAoB,GACpB,mBAAmB,GACnB,qBAAqB,GACrB,qBAAqB,GACrB,oBAAoB,GACpB,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,SAAS,GACT,SAAS,GACT,qBAAqB,GACrB,gBAAgB,GAChB,mBAAmB,GACnB,qBAAqB,GACrB,0BAA0B,GAC1B,yBAAyB,GACzB,qBAAqB,GACrB,kBAAkB,GAClB,eAAe,GACf,eAAe,GACf,eAAe,GACf,gBAAgB,GAChB,0BAA0B,GAC1B,wBAAwB,GACxB,gBAAgB,GAChB,iBAAiB,GACjB,2BAA2B,GAC3B,yBAAyB,GACzB,sBAAsB,GACtB,0BAA0B,GAC1B,2BAA2B,GAC3B,0BAA0B,GAC1B,aAAa,GACb,sBAAsB,GACtB,kBAAkB,GAClB,iBAAiB,GACjB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,IAAI,cAAc,EAAE,+BAA+B;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAEnD,MAAM,MAAM,YAAY,GACpB,SAAS,GACT,MAAM,GACN,KAAK,GACL,SAAS,GACT,MAAM,GACN,OAAO,GACP,gBAAgB,GAChB,MAAM,GACN,MAAM,GACN,QAAQ,GACR,oBAAoB,GACpB,mBAAmB,GACnB,qBAAqB,GACrB,qBAAqB,GACrB,oBAAoB,GACpB,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,SAAS,GACT,SAAS,GACT,qBAAqB,GACrB,gBAAgB,GAChB,mBAAmB,GACnB,qBAAqB,GACrB,0BAA0B,GAC1B,yBAAyB,GACzB,qBAAqB,GACrB,kBAAkB,GAClB,eAAe,GACf,eAAe,GACf,eAAe,GACf,gBAAgB,GAChB,0BAA0B,GAC1B,wBAAwB,GACxB,gBAAgB,GAChB,iBAAiB,GACjB,2BAA2B,GAC3B,yBAAyB,GACzB,sBAAsB,GACtB,0BAA0B,GAC1B,2BAA2B,GAC3B,0BAA0B,GAC1B,aAAa,GACb,sBAAsB,GACtB,kBAAkB,GAClB,iBAAiB,GACjB,mBAAmB,CAAC;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AAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CACF,CAAC;AAGN,MAAM,MAAM,aAAa,GAAG,cAAc,GAAG;IAC3C,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
|
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ValueTransfer as _ValueTransfer } from '@metamask/core-backend';\nimport type { CaipChainId } from '@metamask/utils';\n\nexport type ActivityKind =\n | 'receive'\n | 'sell'\n | 'buy'\n | 'deposit'\n | 'swap'\n | 'claim'\n | 'claimMusdBonus'\n | 'send'\n | 'wrap'\n | 'unwrap'\n | 'approveSpendingCap'\n | 'revokeSpendingCap'\n | 'increaseSpendingCap'\n | 'contractInteraction'\n | 'contractDeployment'\n | 'bridge'\n | 'convert'\n | 'nftBuy'\n | 'nftMint'\n | 'nftSell'\n | 'smartAccountUpgrade'\n | 'lendingDeposit'\n | 'lendingWithdrawal'\n | 'predictionsAddFunds'\n | 'predictionsWithdrawFunds'\n | 'predictionClaimWinnings'\n | 'predictionCashedOut'\n | 'predictionPlaced'\n | 'perpsAddFunds'\n | 'perpsWithdraw'\n | 'perpsOpenLong'\n | 'perpsCloseLong'\n | 'perpsCloseLongLiquidated'\n | 'perpsCloseLongStopLoss'\n | 'perpsOpenShort'\n | 'perpsCloseShort'\n | 'perpsCloseShortLiquidated'\n | 'perpsCloseShortStopLoss'\n | 'perpsPaidFundingFees'\n | 'perpsReceivedFundingFees'\n | 'perpsCloseShortTakeProfit'\n | 'perpsCloseLongTakeProfit'\n | 'marketShort'\n | 'stopMarketCloseShort'\n | 'marketCloseShort'\n | 'assetActivation'\n | 'assetDeactivation'
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ValueTransfer as _ValueTransfer } from '@metamask/core-backend';\nimport type { CaipChainId } from '@metamask/utils';\n\nexport type ActivityKind =\n | 'receive'\n | 'sell'\n | 'buy'\n | 'deposit'\n | 'swap'\n | 'claim'\n | 'claimMusdBonus'\n | 'send'\n | 'wrap'\n | 'unwrap'\n | 'approveSpendingCap'\n | 'revokeSpendingCap'\n | 'increaseSpendingCap'\n | 'contractInteraction'\n | 'contractDeployment'\n | 'bridge'\n | 'convert'\n | 'nftBuy'\n | 'nftMint'\n | 'nftSell'\n | 'smartAccountUpgrade'\n | 'lendingDeposit'\n | 'lendingWithdrawal'\n | 'predictionsAddFunds'\n | 'predictionsWithdrawFunds'\n | 'predictionClaimWinnings'\n | 'predictionCashedOut'\n | 'predictionPlaced'\n | 'perpsAddFunds'\n | 'perpsWithdraw'\n | 'perpsOpenLong'\n | 'perpsCloseLong'\n | 'perpsCloseLongLiquidated'\n | 'perpsCloseLongStopLoss'\n | 'perpsOpenShort'\n | 'perpsCloseShort'\n | 'perpsCloseShortLiquidated'\n | 'perpsCloseShortStopLoss'\n | 'perpsPaidFundingFees'\n | 'perpsReceivedFundingFees'\n | 'perpsCloseShortTakeProfit'\n | 'perpsCloseLongTakeProfit'\n | 'marketShort'\n | 'stopMarketCloseShort'\n | 'marketCloseShort'\n | 'assetActivation'\n | 'assetDeactivation';\n\nexport type Status = 'pending' | 'success' | 'failed' | 'cancelled';\n\nexport type AssetType = 'native' | 'erc20' | 'erc721' | 'erc1155';\n\nexport type TokenAmount = {\n amount?: string;\n decimals?: number;\n symbol?: string;\n assetId?: string;\n assetType?: AssetType;\n direction: 'in' | 'out';\n};\n\nexport type FiatAmount = {\n amount: string;\n currency?: string;\n};\n\nexport type Fee = {\n type: string;\n amount?: string;\n decimals?: number;\n symbol?: string;\n assetId?: string;\n assetType?: AssetType;\n};\n\ntype ActivityData<Type extends ActivityKind, Data> = {\n type: Type;\n chainId: CaipChainId;\n status: Status;\n timestamp: number;\n hash?: string;\n data: Data;\n};\n\nexport type ActivityItem =\n | ActivityData<\n 'approveSpendingCap' | 'revokeSpendingCap' | 'increaseSpendingCap',\n {\n from?: string;\n token?: TokenAmount;\n fees?: Fee[];\n }\n >\n | ActivityData<\n 'assetActivation' | 'assetDeactivation',\n {\n from?: string;\n token?: TokenAmount;\n fees?: Fee[];\n }\n >\n | ActivityData<\n 'send' | 'receive',\n {\n from: string;\n to: string;\n token?: TokenAmount;\n fees?: Fee[];\n }\n >\n | ActivityData<\n 'nftBuy' | 'nftMint' | 'nftSell',\n {\n from?: string;\n to?: string;\n token?: TokenAmount;\n paymentToken?: TokenAmount;\n }\n >\n | ActivityData<\n | 'swap'\n | 'bridge'\n | 'convert'\n | 'lendingDeposit'\n | 'lendingWithdrawal'\n | 'wrap'\n | 'unwrap',\n {\n from?: string;\n sourceToken?: TokenAmount;\n destinationToken?: TokenAmount;\n fees?: Fee[];\n }\n >\n | ActivityData<\n 'buy' | 'claim' | 'deposit' | 'claimMusdBonus',\n {\n from?: string;\n token?: TokenAmount;\n }\n >\n | ActivityData<\n 'perpsAddFunds' | 'perpsWithdraw',\n {\n from?: string;\n fiat?: FiatAmount;\n networkFee?: FiatAmount;\n token?: TokenAmount;\n }\n >\n | ActivityData<\n 'contractInteraction',\n {\n from: string;\n to: string;\n token?: TokenAmount;\n fees?: Fee[];\n methodId?: string;\n transactionCategory?: string;\n transactionProtocol?: string;\n }\n >;\n\n// Note: Update core-backend\nexport type ValueTransfer = _ValueTransfer & {\n contractAddress: string;\n symbol: string;\n name: string;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapRampsOrder = void 0;
|
|
4
|
-
const utils_1 = require("@metamask/utils");
|
|
5
|
-
const caip_js_1 = require("./helpers/caip.cjs");
|
|
6
|
-
/**
|
|
7
|
-
* Extracts the CAIP-2 chain id from a CAIP-19 asset id
|
|
8
|
-
* (`eip155:1/slip44:60` → `eip155:1`).
|
|
9
|
-
*
|
|
10
|
-
* @param assetId - CAIP-19 asset id.
|
|
11
|
-
* @returns The CAIP-2 chain id, or `undefined` when it can't be extracted.
|
|
12
|
-
*/
|
|
13
|
-
function caipChainIdFromAssetId(assetId) {
|
|
14
|
-
if (!assetId) {
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
|
-
const slash = assetId.indexOf('/');
|
|
18
|
-
const chainPart = slash === -1 ? assetId : assetId.slice(0, slash);
|
|
19
|
-
return (0, utils_1.isCaipChainId)(chainPart) ? chainPart : undefined;
|
|
20
|
-
}
|
|
21
|
-
function mapStatus(status) {
|
|
22
|
-
switch (status) {
|
|
23
|
-
case 'COMPLETED':
|
|
24
|
-
return 'success';
|
|
25
|
-
case 'FAILED':
|
|
26
|
-
return 'failed';
|
|
27
|
-
case 'CANCELLED':
|
|
28
|
-
return 'cancelled';
|
|
29
|
-
default:
|
|
30
|
-
return 'pending';
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
// `UNKNOWN`, `ID_EXPIRED`, and `PRECREATED` represent background checkout
|
|
34
|
-
// attempts (e.g. precreated orders that never matched a real order, or whose
|
|
35
|
-
// id expired before the provider assigned one) that the user never knowingly
|
|
36
|
-
// initiated as a distinct order and shouldn't see in their history.
|
|
37
|
-
const HIDDEN_STATUSES = new Set([
|
|
38
|
-
'UNKNOWN',
|
|
39
|
-
'ID_EXPIRED',
|
|
40
|
-
'PRECREATED',
|
|
41
|
-
]);
|
|
42
|
-
/**
|
|
43
|
-
* Resolves the CAIP-2 chain id for a ramps order.
|
|
44
|
-
*
|
|
45
|
-
* Tries each source in order and falls through when a value is present but
|
|
46
|
-
* unparseable (e.g. Coinbase's network name string `"ethereum"`). Generic
|
|
47
|
-
* providers often return a free-form network name while still attaching a
|
|
48
|
-
* real CAIP `cryptoCurrency.chainId` / `assetId`.
|
|
49
|
-
*
|
|
50
|
-
* Precedence: `network.chainId` (object) → `network` (string) →
|
|
51
|
-
* `cryptoCurrency.chainId` → chain segment of `cryptoCurrency.assetId`.
|
|
52
|
-
*
|
|
53
|
-
* @param order - The ramps order to resolve a chain id for.
|
|
54
|
-
* @returns The CAIP-2 chain id, or `undefined` when it can't be resolved.
|
|
55
|
-
*/
|
|
56
|
-
function resolveRampsOrderChainId(order) {
|
|
57
|
-
const { network } = order;
|
|
58
|
-
const networkChainId = typeof network === 'string' ? network : network.chainId;
|
|
59
|
-
return ((0, caip_js_1.formatChainIdToCaip)(networkChainId) ??
|
|
60
|
-
(order.cryptoCurrency?.chainId
|
|
61
|
-
? (0, caip_js_1.formatChainIdToCaip)(order.cryptoCurrency.chainId)
|
|
62
|
-
: undefined) ??
|
|
63
|
-
caipChainIdFromAssetId(order.cryptoCurrency?.assetId));
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Returns true when `txHash` looks like a real on-chain hash. Provider
|
|
67
|
-
* placeholders such as `""`, `"0x"`, and all-zero hashes must not be used as
|
|
68
|
-
* Activity row keys — they collide across orders whose hash isn't set yet.
|
|
69
|
-
*
|
|
70
|
-
* @param txHash - The order's raw `txHash` value.
|
|
71
|
-
* @returns `true` when the hash looks like a real on-chain hash.
|
|
72
|
-
*/
|
|
73
|
-
function isPlausibleRampTxHash(txHash) {
|
|
74
|
-
const normalized = txHash.trim().toLowerCase();
|
|
75
|
-
return normalized !== '' && !/^0x0*$/u.test(normalized);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Maps a ramps order into the shared activity item shape.
|
|
79
|
-
*
|
|
80
|
-
* @param order - The ramps order to map.
|
|
81
|
-
* @returns The normalized activity item, or `null` if the order's status
|
|
82
|
-
* should not be surfaced in the activity list.
|
|
83
|
-
*/
|
|
84
|
-
function mapRampsOrder(order) {
|
|
85
|
-
if (HIDDEN_STATUSES.has(order.status) || order.excludeFromPurchases) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
// The V2 API returns `orderType` uppercased (e.g. `'BUY'`); normalize since
|
|
89
|
-
// some call sites (e.g. locally-created stub orders) use lowercase. Transak
|
|
90
|
-
// deposits (`'DEPOSIT'`) are a buy variant, not a sell.
|
|
91
|
-
const normalizedOrderType = order.orderType.toUpperCase();
|
|
92
|
-
const isBuy = normalizedOrderType === 'BUY' || normalizedOrderType === 'DEPOSIT';
|
|
93
|
-
const direction = isBuy ? 'in' : 'out';
|
|
94
|
-
// `cryptoAmount`/`fiatAmount` are already human-formatted by the API, unlike
|
|
95
|
-
// `TokenAmount.decimals` elsewhere in this package, which signals a raw
|
|
96
|
-
// on-chain amount that still needs scaling. Omit `decimals` so clients don't
|
|
97
|
-
// wrongly re-scale an already-human amount.
|
|
98
|
-
const token = order.cryptoCurrency
|
|
99
|
-
? {
|
|
100
|
-
amount: String(order.cryptoAmount),
|
|
101
|
-
symbol: order.cryptoCurrency.symbol,
|
|
102
|
-
assetId: order.cryptoCurrency.assetId,
|
|
103
|
-
direction,
|
|
104
|
-
}
|
|
105
|
-
: undefined;
|
|
106
|
-
const fiat = {
|
|
107
|
-
amount: String(order.fiatAmount),
|
|
108
|
-
currency: order.fiatCurrency?.symbol,
|
|
109
|
-
};
|
|
110
|
-
const fees = [
|
|
111
|
-
{
|
|
112
|
-
type: 'total',
|
|
113
|
-
amount: String(order.totalFeesFiat),
|
|
114
|
-
symbol: order.fiatCurrency?.symbol,
|
|
115
|
-
},
|
|
116
|
-
];
|
|
117
|
-
const chainId = resolveRampsOrderChainId(order);
|
|
118
|
-
return {
|
|
119
|
-
type: isBuy ? 'rampBuy' : 'rampSell',
|
|
120
|
-
chainId,
|
|
121
|
-
status: mapStatus(order.status),
|
|
122
|
-
timestamp: order.createdAt,
|
|
123
|
-
hash: isPlausibleRampTxHash(order.txHash) ? order.txHash : undefined,
|
|
124
|
-
data: {
|
|
125
|
-
from: order.walletAddress,
|
|
126
|
-
fiat,
|
|
127
|
-
token,
|
|
128
|
-
fees,
|
|
129
|
-
provider: {
|
|
130
|
-
id: order.provider?.id,
|
|
131
|
-
name: order.provider?.name,
|
|
132
|
-
orderLink: order.providerOrderLink,
|
|
133
|
-
},
|
|
134
|
-
statusDescription: order.statusDescription,
|
|
135
|
-
paymentDetails: order.paymentDetails,
|
|
136
|
-
id: order.id ?? order.providerOrderId,
|
|
137
|
-
},
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
exports.mapRampsOrder = mapRampsOrder;
|
|
141
|
-
//# sourceMappingURL=ramps-order-mapper.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ramps-order-mapper.cjs","sourceRoot":"","sources":["../../src/mappers/ramps-order-mapper.ts"],"names":[],"mappings":";;;AACA,2CAAgD;AAUhD,gDAAwD;AAExD;;;;;;GAMG;AACH,SAAS,sBAAsB,CAC7B,OAA2B;IAE3B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACnC,MAAM,SAAS,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACnE,OAAO,IAAA,qBAAa,EAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1D,CAAC;AA6CD,SAAS,SAAS,CAAC,MAA4B;IAC7C,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,WAAW;YACd,OAAO,SAAS,CAAC;QACnB,KAAK,QAAQ;YACX,OAAO,QAAQ,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AK,CAAC,aAAa;YACzB,IAAI;YACJ,KAAK;YACL,IAAI;YACJ,QAAQ,EAAE;gBACR,EAAE,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE;gBACtB,IAAI,EAAE,KAAK,CAAC,QAAQ,EAAE,IAAI;gBAC1B,SAAS,EAAE,KAAK,CAAC,iBAAiB;aACnC;YACD,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;YAC1C,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,EAAE,EAAE,KAAK,CAAC,EAAE,IAAI,KAAK,CAAC,eAAe;SACtC;KACF,CAAC;AACJ,CAAC;AA9DD,sCA8DC","sourcesContent":["import type { CaipChainId } from '@metamask/utils';\nimport { isCaipChainId } from '@metamask/utils';\n\nimport type {\n ActivityItem,\n Fee,\n FiatAmount,\n RampOrderPaymentDetail,\n Status,\n TokenAmount,\n} from '../types.js';\nimport { formatChainIdToCaip } from './helpers/caip.js';\n\n/**\n * Extracts the CAIP-2 chain id from a CAIP-19 asset id\n * (`eip155:1/slip44:60` → `eip155:1`).\n *\n * @param assetId - CAIP-19 asset id.\n * @returns The CAIP-2 chain id, or `undefined` when it can't be extracted.\n */\nfunction caipChainIdFromAssetId(\n assetId: string | undefined,\n): CaipChainId | undefined {\n if (!assetId) {\n return undefined;\n }\n const slash = assetId.indexOf('/');\n const chainPart = slash === -1 ? assetId : assetId.slice(0, slash);\n return isCaipChainId(chainPart) ? chainPart : undefined;\n}\n\ntype RampsOrderStatusLike =\n | 'UNKNOWN'\n | 'PRECREATED'\n | 'CREATED'\n | 'PENDING'\n | 'FAILED'\n | 'COMPLETED'\n | 'CANCELLED'\n | 'ID_EXPIRED';\n\n/**\n * The subset of `RampsOrder` (from `@metamask/ramps-controller`) that this\n * mapper depends on. Redeclared locally rather than imported to keep\n * `client-utils` free of a dependency on `ramps-controller`.\n */\nexport type RampsOrderLike = {\n id?: string;\n provider?: { id?: string; name?: string };\n cryptoAmount: string | number;\n fiatAmount: number;\n cryptoCurrency?: {\n assetId?: string;\n chainId?: string;\n symbol: string;\n decimals?: number;\n };\n fiatCurrency?: { symbol: string };\n providerOrderId: string;\n providerOrderLink: string;\n createdAt: number;\n totalFeesFiat: number;\n txHash: string;\n walletAddress: string;\n status: RampsOrderStatusLike;\n // Declared as an object, but generic providers (e.g. Coinbase) actually send\n // a free-form network name string at runtime — see `resolveRampsOrderChainId`.\n network: { chainId: string } | string;\n statusDescription?: string;\n orderType: string;\n excludeFromPurchases?: boolean;\n paymentDetails?: RampOrderPaymentDetail[];\n};\n\nfunction mapStatus(status: RampsOrderStatusLike): Status {\n switch (status) {\n case 'COMPLETED':\n return 'success';\n case 'FAILED':\n return 'failed';\n case 'CANCELLED':\n return 'cancelled';\n default:\n return 'pending';\n }\n}\n\n// `UNKNOWN`, `ID_EXPIRED`, and `PRECREATED` represent background checkout\n// attempts (e.g. precreated orders that never matched a real order, or whose\n// id expired before the provider assigned one) that the user never knowingly\n// initiated as a distinct order and shouldn't see in their history.\nconst HIDDEN_STATUSES = new Set<RampsOrderStatusLike>([\n 'UNKNOWN',\n 'ID_EXPIRED',\n 'PRECREATED',\n]);\n\n/**\n * Resolves the CAIP-2 chain id for a ramps order.\n *\n * Tries each source in order and falls through when a value is present but\n * unparseable (e.g. Coinbase's network name string `\"ethereum\"`). Generic\n * providers often return a free-form network name while still attaching a\n * real CAIP `cryptoCurrency.chainId` / `assetId`.\n *\n * Precedence: `network.chainId` (object) → `network` (string) →\n * `cryptoCurrency.chainId` → chain segment of `cryptoCurrency.assetId`.\n *\n * @param order - The ramps order to resolve a chain id for.\n * @returns The CAIP-2 chain id, or `undefined` when it can't be resolved.\n */\nfunction resolveRampsOrderChainId(\n order: RampsOrderLike,\n): ReturnType<typeof formatChainIdToCaip> {\n const { network } = order;\n const networkChainId =\n typeof network === 'string' ? network : network.chainId;\n\n return (\n formatChainIdToCaip(networkChainId) ??\n (order.cryptoCurrency?.chainId\n ? formatChainIdToCaip(order.cryptoCurrency.chainId)\n : undefined) ??\n caipChainIdFromAssetId(order.cryptoCurrency?.assetId)\n );\n}\n\n/**\n * Returns true when `txHash` looks like a real on-chain hash. Provider\n * placeholders such as `\"\"`, `\"0x\"`, and all-zero hashes must not be used as\n * Activity row keys — they collide across orders whose hash isn't set yet.\n *\n * @param txHash - The order's raw `txHash` value.\n * @returns `true` when the hash looks like a real on-chain hash.\n */\nfunction isPlausibleRampTxHash(txHash: string): boolean {\n const normalized = txHash.trim().toLowerCase();\n return normalized !== '' && !/^0x0*$/u.test(normalized);\n}\n\n/**\n * Maps a ramps order into the shared activity item shape.\n *\n * @param order - The ramps order to map.\n * @returns The normalized activity item, or `null` if the order's status\n * should not be surfaced in the activity list.\n */\nexport function mapRampsOrder(order: RampsOrderLike): ActivityItem | null {\n if (HIDDEN_STATUSES.has(order.status) || order.excludeFromPurchases) {\n return null;\n }\n\n // The V2 API returns `orderType` uppercased (e.g. `'BUY'`); normalize since\n // some call sites (e.g. locally-created stub orders) use lowercase. Transak\n // deposits (`'DEPOSIT'`) are a buy variant, not a sell.\n const normalizedOrderType = order.orderType.toUpperCase();\n const isBuy =\n normalizedOrderType === 'BUY' || normalizedOrderType === 'DEPOSIT';\n const direction: TokenAmount['direction'] = isBuy ? 'in' : 'out';\n\n // `cryptoAmount`/`fiatAmount` are already human-formatted by the API, unlike\n // `TokenAmount.decimals` elsewhere in this package, which signals a raw\n // on-chain amount that still needs scaling. Omit `decimals` so clients don't\n // wrongly re-scale an already-human amount.\n const token: TokenAmount | undefined = order.cryptoCurrency\n ? {\n amount: String(order.cryptoAmount),\n symbol: order.cryptoCurrency.symbol,\n assetId: order.cryptoCurrency.assetId,\n direction,\n }\n : undefined;\n\n const fiat: FiatAmount = {\n amount: String(order.fiatAmount),\n currency: order.fiatCurrency?.symbol,\n };\n\n const fees: Fee[] = [\n {\n type: 'total',\n amount: String(order.totalFeesFiat),\n symbol: order.fiatCurrency?.symbol,\n },\n ];\n\n const chainId = resolveRampsOrderChainId(order);\n\n return {\n type: isBuy ? 'rampBuy' : 'rampSell',\n chainId,\n status: mapStatus(order.status),\n timestamp: order.createdAt,\n hash: isPlausibleRampTxHash(order.txHash) ? order.txHash : undefined,\n data: {\n from: order.walletAddress,\n fiat,\n token,\n fees,\n provider: {\n id: order.provider?.id,\n name: order.provider?.name,\n orderLink: order.providerOrderLink,\n },\n statusDescription: order.statusDescription,\n paymentDetails: order.paymentDetails,\n id: order.id ?? order.providerOrderId,\n },\n };\n}\n"]}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { ActivityItem, RampOrderPaymentDetail } from "../types.cjs";
|
|
2
|
-
type RampsOrderStatusLike = 'UNKNOWN' | 'PRECREATED' | 'CREATED' | 'PENDING' | 'FAILED' | 'COMPLETED' | 'CANCELLED' | 'ID_EXPIRED';
|
|
3
|
-
/**
|
|
4
|
-
* The subset of `RampsOrder` (from `@metamask/ramps-controller`) that this
|
|
5
|
-
* mapper depends on. Redeclared locally rather than imported to keep
|
|
6
|
-
* `client-utils` free of a dependency on `ramps-controller`.
|
|
7
|
-
*/
|
|
8
|
-
export type RampsOrderLike = {
|
|
9
|
-
id?: string;
|
|
10
|
-
provider?: {
|
|
11
|
-
id?: string;
|
|
12
|
-
name?: string;
|
|
13
|
-
};
|
|
14
|
-
cryptoAmount: string | number;
|
|
15
|
-
fiatAmount: number;
|
|
16
|
-
cryptoCurrency?: {
|
|
17
|
-
assetId?: string;
|
|
18
|
-
chainId?: string;
|
|
19
|
-
symbol: string;
|
|
20
|
-
decimals?: number;
|
|
21
|
-
};
|
|
22
|
-
fiatCurrency?: {
|
|
23
|
-
symbol: string;
|
|
24
|
-
};
|
|
25
|
-
providerOrderId: string;
|
|
26
|
-
providerOrderLink: string;
|
|
27
|
-
createdAt: number;
|
|
28
|
-
totalFeesFiat: number;
|
|
29
|
-
txHash: string;
|
|
30
|
-
walletAddress: string;
|
|
31
|
-
status: RampsOrderStatusLike;
|
|
32
|
-
network: {
|
|
33
|
-
chainId: string;
|
|
34
|
-
} | string;
|
|
35
|
-
statusDescription?: string;
|
|
36
|
-
orderType: string;
|
|
37
|
-
excludeFromPurchases?: boolean;
|
|
38
|
-
paymentDetails?: RampOrderPaymentDetail[];
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Maps a ramps order into the shared activity item shape.
|
|
42
|
-
*
|
|
43
|
-
* @param order - The ramps order to map.
|
|
44
|
-
* @returns The normalized activity item, or `null` if the order's status
|
|
45
|
-
* should not be surfaced in the activity list.
|
|
46
|
-
*/
|
|
47
|
-
export declare function mapRampsOrder(order: RampsOrderLike): ActivityItem | null;
|
|
48
|
-
export {};
|
|
49
|
-
//# sourceMappingURL=ramps-order-mapper.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ramps-order-mapper.d.cts","sourceRoot":"","sources":["../../src/mappers/ramps-order-mapper.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,YAAY,EAGZ,sBAAsB,EAGvB,qBAAoB;AAqBrB,KAAK,oBAAoB,GACrB,SAAS,GACT,YAAY,GACZ,SAAS,GACT,SAAS,GACT,QAAQ,GACR,WAAW,GACX,WAAW,GACX,YAAY,CAAC;AAEjB;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1C,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,YAAY,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,oBAAoB,CAAC;IAG7B,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC;IACtC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,cAAc,CAAC,EAAE,sBAAsB,EAAE,CAAC;CAC3C,CAAC;AAoEF;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,cAAc,GAAG,YAAY,GAAG,IAAI,CA8DxE"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { ActivityItem, RampOrderPaymentDetail } from "../types.mjs";
|
|
2
|
-
type RampsOrderStatusLike = 'UNKNOWN' | 'PRECREATED' | 'CREATED' | 'PENDING' | 'FAILED' | 'COMPLETED' | 'CANCELLED' | 'ID_EXPIRED';
|
|
3
|
-
/**
|
|
4
|
-
* The subset of `RampsOrder` (from `@metamask/ramps-controller`) that this
|
|
5
|
-
* mapper depends on. Redeclared locally rather than imported to keep
|
|
6
|
-
* `client-utils` free of a dependency on `ramps-controller`.
|
|
7
|
-
*/
|
|
8
|
-
export type RampsOrderLike = {
|
|
9
|
-
id?: string;
|
|
10
|
-
provider?: {
|
|
11
|
-
id?: string;
|
|
12
|
-
name?: string;
|
|
13
|
-
};
|
|
14
|
-
cryptoAmount: string | number;
|
|
15
|
-
fiatAmount: number;
|
|
16
|
-
cryptoCurrency?: {
|
|
17
|
-
assetId?: string;
|
|
18
|
-
chainId?: string;
|
|
19
|
-
symbol: string;
|
|
20
|
-
decimals?: number;
|
|
21
|
-
};
|
|
22
|
-
fiatCurrency?: {
|
|
23
|
-
symbol: string;
|
|
24
|
-
};
|
|
25
|
-
providerOrderId: string;
|
|
26
|
-
providerOrderLink: string;
|
|
27
|
-
createdAt: number;
|
|
28
|
-
totalFeesFiat: number;
|
|
29
|
-
txHash: string;
|
|
30
|
-
walletAddress: string;
|
|
31
|
-
status: RampsOrderStatusLike;
|
|
32
|
-
network: {
|
|
33
|
-
chainId: string;
|
|
34
|
-
} | string;
|
|
35
|
-
statusDescription?: string;
|
|
36
|
-
orderType: string;
|
|
37
|
-
excludeFromPurchases?: boolean;
|
|
38
|
-
paymentDetails?: RampOrderPaymentDetail[];
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Maps a ramps order into the shared activity item shape.
|
|
42
|
-
*
|
|
43
|
-
* @param order - The ramps order to map.
|
|
44
|
-
* @returns The normalized activity item, or `null` if the order's status
|
|
45
|
-
* should not be surfaced in the activity list.
|
|
46
|
-
*/
|
|
47
|
-
export declare function mapRampsOrder(order: RampsOrderLike): ActivityItem | null;
|
|
48
|
-
export {};
|
|
49
|
-
//# sourceMappingURL=ramps-order-mapper.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ramps-order-mapper.d.mts","sourceRoot":"","sources":["../../src/mappers/ramps-order-mapper.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,YAAY,EAGZ,sBAAsB,EAGvB,qBAAoB;AAqBrB,KAAK,oBAAoB,GACrB,SAAS,GACT,YAAY,GACZ,SAAS,GACT,SAAS,GACT,QAAQ,GACR,WAAW,GACX,WAAW,GACX,YAAY,CAAC;AAEjB;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1C,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,YAAY,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,oBAAoB,CAAC;IAG7B,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC;IACtC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,cAAc,CAAC,EAAE,sBAAsB,EAAE,CAAC;CAC3C,CAAC;AAoEF;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,cAAc,GAAG,YAAY,GAAG,IAAI,CA8DxE"}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { isCaipChainId } from "@metamask/utils";
|
|
2
|
-
import { formatChainIdToCaip } from "./helpers/caip.mjs";
|
|
3
|
-
/**
|
|
4
|
-
* Extracts the CAIP-2 chain id from a CAIP-19 asset id
|
|
5
|
-
* (`eip155:1/slip44:60` → `eip155:1`).
|
|
6
|
-
*
|
|
7
|
-
* @param assetId - CAIP-19 asset id.
|
|
8
|
-
* @returns The CAIP-2 chain id, or `undefined` when it can't be extracted.
|
|
9
|
-
*/
|
|
10
|
-
function caipChainIdFromAssetId(assetId) {
|
|
11
|
-
if (!assetId) {
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
|
14
|
-
const slash = assetId.indexOf('/');
|
|
15
|
-
const chainPart = slash === -1 ? assetId : assetId.slice(0, slash);
|
|
16
|
-
return isCaipChainId(chainPart) ? chainPart : undefined;
|
|
17
|
-
}
|
|
18
|
-
function mapStatus(status) {
|
|
19
|
-
switch (status) {
|
|
20
|
-
case 'COMPLETED':
|
|
21
|
-
return 'success';
|
|
22
|
-
case 'FAILED':
|
|
23
|
-
return 'failed';
|
|
24
|
-
case 'CANCELLED':
|
|
25
|
-
return 'cancelled';
|
|
26
|
-
default:
|
|
27
|
-
return 'pending';
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
// `UNKNOWN`, `ID_EXPIRED`, and `PRECREATED` represent background checkout
|
|
31
|
-
// attempts (e.g. precreated orders that never matched a real order, or whose
|
|
32
|
-
// id expired before the provider assigned one) that the user never knowingly
|
|
33
|
-
// initiated as a distinct order and shouldn't see in their history.
|
|
34
|
-
const HIDDEN_STATUSES = new Set([
|
|
35
|
-
'UNKNOWN',
|
|
36
|
-
'ID_EXPIRED',
|
|
37
|
-
'PRECREATED',
|
|
38
|
-
]);
|
|
39
|
-
/**
|
|
40
|
-
* Resolves the CAIP-2 chain id for a ramps order.
|
|
41
|
-
*
|
|
42
|
-
* Tries each source in order and falls through when a value is present but
|
|
43
|
-
* unparseable (e.g. Coinbase's network name string `"ethereum"`). Generic
|
|
44
|
-
* providers often return a free-form network name while still attaching a
|
|
45
|
-
* real CAIP `cryptoCurrency.chainId` / `assetId`.
|
|
46
|
-
*
|
|
47
|
-
* Precedence: `network.chainId` (object) → `network` (string) →
|
|
48
|
-
* `cryptoCurrency.chainId` → chain segment of `cryptoCurrency.assetId`.
|
|
49
|
-
*
|
|
50
|
-
* @param order - The ramps order to resolve a chain id for.
|
|
51
|
-
* @returns The CAIP-2 chain id, or `undefined` when it can't be resolved.
|
|
52
|
-
*/
|
|
53
|
-
function resolveRampsOrderChainId(order) {
|
|
54
|
-
const { network } = order;
|
|
55
|
-
const networkChainId = typeof network === 'string' ? network : network.chainId;
|
|
56
|
-
return (formatChainIdToCaip(networkChainId) ??
|
|
57
|
-
(order.cryptoCurrency?.chainId
|
|
58
|
-
? formatChainIdToCaip(order.cryptoCurrency.chainId)
|
|
59
|
-
: undefined) ??
|
|
60
|
-
caipChainIdFromAssetId(order.cryptoCurrency?.assetId));
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Returns true when `txHash` looks like a real on-chain hash. Provider
|
|
64
|
-
* placeholders such as `""`, `"0x"`, and all-zero hashes must not be used as
|
|
65
|
-
* Activity row keys — they collide across orders whose hash isn't set yet.
|
|
66
|
-
*
|
|
67
|
-
* @param txHash - The order's raw `txHash` value.
|
|
68
|
-
* @returns `true` when the hash looks like a real on-chain hash.
|
|
69
|
-
*/
|
|
70
|
-
function isPlausibleRampTxHash(txHash) {
|
|
71
|
-
const normalized = txHash.trim().toLowerCase();
|
|
72
|
-
return normalized !== '' && !/^0x0*$/u.test(normalized);
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Maps a ramps order into the shared activity item shape.
|
|
76
|
-
*
|
|
77
|
-
* @param order - The ramps order to map.
|
|
78
|
-
* @returns The normalized activity item, or `null` if the order's status
|
|
79
|
-
* should not be surfaced in the activity list.
|
|
80
|
-
*/
|
|
81
|
-
export function mapRampsOrder(order) {
|
|
82
|
-
if (HIDDEN_STATUSES.has(order.status) || order.excludeFromPurchases) {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
// The V2 API returns `orderType` uppercased (e.g. `'BUY'`); normalize since
|
|
86
|
-
// some call sites (e.g. locally-created stub orders) use lowercase. Transak
|
|
87
|
-
// deposits (`'DEPOSIT'`) are a buy variant, not a sell.
|
|
88
|
-
const normalizedOrderType = order.orderType.toUpperCase();
|
|
89
|
-
const isBuy = normalizedOrderType === 'BUY' || normalizedOrderType === 'DEPOSIT';
|
|
90
|
-
const direction = isBuy ? 'in' : 'out';
|
|
91
|
-
// `cryptoAmount`/`fiatAmount` are already human-formatted by the API, unlike
|
|
92
|
-
// `TokenAmount.decimals` elsewhere in this package, which signals a raw
|
|
93
|
-
// on-chain amount that still needs scaling. Omit `decimals` so clients don't
|
|
94
|
-
// wrongly re-scale an already-human amount.
|
|
95
|
-
const token = order.cryptoCurrency
|
|
96
|
-
? {
|
|
97
|
-
amount: String(order.cryptoAmount),
|
|
98
|
-
symbol: order.cryptoCurrency.symbol,
|
|
99
|
-
assetId: order.cryptoCurrency.assetId,
|
|
100
|
-
direction,
|
|
101
|
-
}
|
|
102
|
-
: undefined;
|
|
103
|
-
const fiat = {
|
|
104
|
-
amount: String(order.fiatAmount),
|
|
105
|
-
currency: order.fiatCurrency?.symbol,
|
|
106
|
-
};
|
|
107
|
-
const fees = [
|
|
108
|
-
{
|
|
109
|
-
type: 'total',
|
|
110
|
-
amount: String(order.totalFeesFiat),
|
|
111
|
-
symbol: order.fiatCurrency?.symbol,
|
|
112
|
-
},
|
|
113
|
-
];
|
|
114
|
-
const chainId = resolveRampsOrderChainId(order);
|
|
115
|
-
return {
|
|
116
|
-
type: isBuy ? 'rampBuy' : 'rampSell',
|
|
117
|
-
chainId,
|
|
118
|
-
status: mapStatus(order.status),
|
|
119
|
-
timestamp: order.createdAt,
|
|
120
|
-
hash: isPlausibleRampTxHash(order.txHash) ? order.txHash : undefined,
|
|
121
|
-
data: {
|
|
122
|
-
from: order.walletAddress,
|
|
123
|
-
fiat,
|
|
124
|
-
token,
|
|
125
|
-
fees,
|
|
126
|
-
provider: {
|
|
127
|
-
id: order.provider?.id,
|
|
128
|
-
name: order.provider?.name,
|
|
129
|
-
orderLink: order.providerOrderLink,
|
|
130
|
-
},
|
|
131
|
-
statusDescription: order.statusDescription,
|
|
132
|
-
paymentDetails: order.paymentDetails,
|
|
133
|
-
id: order.id ?? order.providerOrderId,
|
|
134
|
-
},
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
//# sourceMappingURL=ramps-order-mapper.mjs.map
|
|
@@ -1 +0,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YACrC,SAAS;SACV;QACH,CAAC,CAAC,SAAS,CAAC;IAEd,MAAM,IAAI,GAAe;QACvB,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;QAChC,QAAQ,EAAE,KAAK,CAAC,YAAY,EAAE,MAAM;KACrC,CAAC;IAEF,MAAM,IAAI,GAAU;QAClB;YACE,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC;YACnC,MAAM,EAAE,KAAK,CAAC,YAAY,EAAE,MAAM;SACnC;KACF,CAAC;IAEF,MAAM,OAAO,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAC;IAEhD,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU;QACpC,OAAO;QACP,MAAM,EAAE,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC;QAC/B,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,IAAI,EAAE,qBAAqB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;QACpE,IAAI,EAAE;YACJ,IAAI,EAAE,KAAK,CAAC,aAAa;YACzB,IAAI;YACJ,KAAK;YACL,IAAI;YACJ,QAAQ,EAAE;gBACR,EAAE,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE;gBACtB,IAAI,EAAE,KAAK,CAAC,QAAQ,EAAE,IAAI;gBAC1B,SAAS,EAAE,KAAK,CAAC,iBAAiB;aACnC;YACD,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;YAC1C,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,EAAE,EAAE,KAAK,CAAC,EAAE,IAAI,KAAK,CAAC,eAAe;SACtC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { CaipChainId } from '@metamask/utils';\nimport { isCaipChainId } from '@metamask/utils';\n\nimport type {\n ActivityItem,\n Fee,\n FiatAmount,\n RampOrderPaymentDetail,\n Status,\n TokenAmount,\n} from '../types.js';\nimport { formatChainIdToCaip } from './helpers/caip.js';\n\n/**\n * Extracts the CAIP-2 chain id from a CAIP-19 asset id\n * (`eip155:1/slip44:60` → `eip155:1`).\n *\n * @param assetId - CAIP-19 asset id.\n * @returns The CAIP-2 chain id, or `undefined` when it can't be extracted.\n */\nfunction caipChainIdFromAssetId(\n assetId: string | undefined,\n): CaipChainId | undefined {\n if (!assetId) {\n return undefined;\n }\n const slash = assetId.indexOf('/');\n const chainPart = slash === -1 ? assetId : assetId.slice(0, slash);\n return isCaipChainId(chainPart) ? chainPart : undefined;\n}\n\ntype RampsOrderStatusLike =\n | 'UNKNOWN'\n | 'PRECREATED'\n | 'CREATED'\n | 'PENDING'\n | 'FAILED'\n | 'COMPLETED'\n | 'CANCELLED'\n | 'ID_EXPIRED';\n\n/**\n * The subset of `RampsOrder` (from `@metamask/ramps-controller`) that this\n * mapper depends on. Redeclared locally rather than imported to keep\n * `client-utils` free of a dependency on `ramps-controller`.\n */\nexport type RampsOrderLike = {\n id?: string;\n provider?: { id?: string; name?: string };\n cryptoAmount: string | number;\n fiatAmount: number;\n cryptoCurrency?: {\n assetId?: string;\n chainId?: string;\n symbol: string;\n decimals?: number;\n };\n fiatCurrency?: { symbol: string };\n providerOrderId: string;\n providerOrderLink: string;\n createdAt: number;\n totalFeesFiat: number;\n txHash: string;\n walletAddress: string;\n status: RampsOrderStatusLike;\n // Declared as an object, but generic providers (e.g. Coinbase) actually send\n // a free-form network name string at runtime — see `resolveRampsOrderChainId`.\n network: { chainId: string } | string;\n statusDescription?: string;\n orderType: string;\n excludeFromPurchases?: boolean;\n paymentDetails?: RampOrderPaymentDetail[];\n};\n\nfunction mapStatus(status: RampsOrderStatusLike): Status {\n switch (status) {\n case 'COMPLETED':\n return 'success';\n case 'FAILED':\n return 'failed';\n case 'CANCELLED':\n return 'cancelled';\n default:\n return 'pending';\n }\n}\n\n// `UNKNOWN`, `ID_EXPIRED`, and `PRECREATED` represent background checkout\n// attempts (e.g. precreated orders that never matched a real order, or whose\n// id expired before the provider assigned one) that the user never knowingly\n// initiated as a distinct order and shouldn't see in their history.\nconst HIDDEN_STATUSES = new Set<RampsOrderStatusLike>([\n 'UNKNOWN',\n 'ID_EXPIRED',\n 'PRECREATED',\n]);\n\n/**\n * Resolves the CAIP-2 chain id for a ramps order.\n *\n * Tries each source in order and falls through when a value is present but\n * unparseable (e.g. Coinbase's network name string `\"ethereum\"`). Generic\n * providers often return a free-form network name while still attaching a\n * real CAIP `cryptoCurrency.chainId` / `assetId`.\n *\n * Precedence: `network.chainId` (object) → `network` (string) →\n * `cryptoCurrency.chainId` → chain segment of `cryptoCurrency.assetId`.\n *\n * @param order - The ramps order to resolve a chain id for.\n * @returns The CAIP-2 chain id, or `undefined` when it can't be resolved.\n */\nfunction resolveRampsOrderChainId(\n order: RampsOrderLike,\n): ReturnType<typeof formatChainIdToCaip> {\n const { network } = order;\n const networkChainId =\n typeof network === 'string' ? network : network.chainId;\n\n return (\n formatChainIdToCaip(networkChainId) ??\n (order.cryptoCurrency?.chainId\n ? formatChainIdToCaip(order.cryptoCurrency.chainId)\n : undefined) ??\n caipChainIdFromAssetId(order.cryptoCurrency?.assetId)\n );\n}\n\n/**\n * Returns true when `txHash` looks like a real on-chain hash. Provider\n * placeholders such as `\"\"`, `\"0x\"`, and all-zero hashes must not be used as\n * Activity row keys — they collide across orders whose hash isn't set yet.\n *\n * @param txHash - The order's raw `txHash` value.\n * @returns `true` when the hash looks like a real on-chain hash.\n */\nfunction isPlausibleRampTxHash(txHash: string): boolean {\n const normalized = txHash.trim().toLowerCase();\n return normalized !== '' && !/^0x0*$/u.test(normalized);\n}\n\n/**\n * Maps a ramps order into the shared activity item shape.\n *\n * @param order - The ramps order to map.\n * @returns The normalized activity item, or `null` if the order's status\n * should not be surfaced in the activity list.\n */\nexport function mapRampsOrder(order: RampsOrderLike): ActivityItem | null {\n if (HIDDEN_STATUSES.has(order.status) || order.excludeFromPurchases) {\n return null;\n }\n\n // The V2 API returns `orderType` uppercased (e.g. `'BUY'`); normalize since\n // some call sites (e.g. locally-created stub orders) use lowercase. Transak\n // deposits (`'DEPOSIT'`) are a buy variant, not a sell.\n const normalizedOrderType = order.orderType.toUpperCase();\n const isBuy =\n normalizedOrderType === 'BUY' || normalizedOrderType === 'DEPOSIT';\n const direction: TokenAmount['direction'] = isBuy ? 'in' : 'out';\n\n // `cryptoAmount`/`fiatAmount` are already human-formatted by the API, unlike\n // `TokenAmount.decimals` elsewhere in this package, which signals a raw\n // on-chain amount that still needs scaling. Omit `decimals` so clients don't\n // wrongly re-scale an already-human amount.\n const token: TokenAmount | undefined = order.cryptoCurrency\n ? {\n amount: String(order.cryptoAmount),\n symbol: order.cryptoCurrency.symbol,\n assetId: order.cryptoCurrency.assetId,\n direction,\n }\n : undefined;\n\n const fiat: FiatAmount = {\n amount: String(order.fiatAmount),\n currency: order.fiatCurrency?.symbol,\n };\n\n const fees: Fee[] = [\n {\n type: 'total',\n amount: String(order.totalFeesFiat),\n symbol: order.fiatCurrency?.symbol,\n },\n ];\n\n const chainId = resolveRampsOrderChainId(order);\n\n return {\n type: isBuy ? 'rampBuy' : 'rampSell',\n chainId,\n status: mapStatus(order.status),\n timestamp: order.createdAt,\n hash: isPlausibleRampTxHash(order.txHash) ? order.txHash : undefined,\n data: {\n from: order.walletAddress,\n fiat,\n token,\n fees,\n provider: {\n id: order.provider?.id,\n name: order.provider?.name,\n orderLink: order.providerOrderLink,\n },\n statusDescription: order.statusDescription,\n paymentDetails: order.paymentDetails,\n id: order.id ?? order.providerOrderId,\n },\n };\n}\n"]}
|