Skip to content

Commit

Permalink
fix: mmi xxx bitgo api url (#790)
Browse files Browse the repository at this point in the history
* chore(custody-keyring): get the bitgo api url from configuration api

* fix(custody-keyrings): use config api isManualTokenInputSupported

* chore(custodykeyring): improving logic

* chore(custody-keyring): improve code

* chore(github): remove support for node 16

* fix(tests): fix tests

* chore(property value): this default value should be false, since it only exists in dev config

* refactor(mmi_configuration): checks for the api url first before assigning it

* chore(configuration): updates config

* fix(remove file): removes file

---------

Co-authored-by: Shane Terence Odlum <[email protected]>
Co-authored-by: Antonio Regadas <[email protected]>
  • Loading branch information
3 people authored Aug 28, 2024
1 parent 3efcf66 commit 2e869d1
Show file tree
Hide file tree
Showing 6 changed files with 1,079 additions and 1,565 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x, 20.x, 22.x]
node-version: [18.x, 20.x, 22.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
1 change: 0 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"npmClient": "yarn",
"useWorkspaces": true,
"useNx": true,
"version": "independent",
"command": {
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
"jest-coverage-badges": "^1.1.2",
"jest-junit": "^15.0.0",
"jest-sonar-reporter": "^2.0.0",
"lerna": "^6.6.1",
"lerna": "^8.1.7",
"lint-staged": "^13.1.2",
"nx": "^19.4.0",
"nx": "^19.5.4",
"prettier": "^2.8.7",
"rimraf": "^4.4.1",
"ts-jest": "^29.0.5",
Expand All @@ -73,5 +73,6 @@
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
},
"packageManager": "[email protected]"
}
43 changes: 28 additions & 15 deletions packages/custodyKeyring/src/MmiConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { ICustodianEnvironment } from "./interfaces/ICustodianEnvironment";
import { IMmiConfigurationControllerOptions } from "./interfaces/IMmiConfigurationControllerOptions";
import { MMIConfiguration } from "./types/MMIConfiguration";

// If a custodian is `curv`, `qredo` `bitgo` or `cactus` it is legacy custodian
const legacyCustodianNames = ["curv", "qredo", "bitgo", "cactus"];

/**
* Background controller responsible for maintaining
* a cache of MMI Portfolio related data in local storage
Expand All @@ -29,18 +32,18 @@ export class MmiConfigurationController {
const initState = opts.initState?.mmiConfiguration
? opts.initState
: {
mmiConfiguration: {
portfolio: {
enabled: false,
url: "",
cookieSetUrls: [],
},
features: {
websocketApi: false,
},
custodians: [], // NB: Custodians will always be empty when we start
mmiConfiguration: {
portfolio: {
enabled: false,
url: "",
cookieSetUrls: [],
},
features: {
websocketApi: false,
},
};
custodians: [], // NB: Custodians will always be empty when we start
},
};

this.configurationClient = new ConfigurationClient(opts.mmiConfigurationServiceUrl);

Expand All @@ -64,6 +67,7 @@ export class MmiConfigurationController {
const { mmiConfiguration } = this.store.getState(); // Stored configuration
const configuredCustodians = configuration.custodians;

// Steo 1: populate the custodian array with the LEGACY custodians
// Mutate custodians by adding information from the hardcoded types
const custodians: ICustodianEnvironment[] = [
...Object.values(CUSTODIAN_TYPES)
Expand All @@ -89,21 +93,30 @@ export class MmiConfigurationController {
})),
];

// Step 2: populate the custodians array with the configured custodians, which already INCLUDES the legacy custodians
// We also mutate the legacy custodian, adding the API url when it exists on the configured custodians side (Bitgo dev/test env)

// Loop through the custodians from the API
configuredCustodians.forEach(custodian => {
custodian.environments.forEach(environment => {
if (!environment.apiBaseUrl) {
// Version 1 custodians should still support note to trader
// This used to check if there is no apiUrl, but now it checks by name
if (legacyCustodianNames.includes(environment.name)) {
// This logic checks if something is a legacy custodian

// Find the legacy custodians in the list of custodians we are building
const legacyCustodian = custodians.find(
legacyCustodian => legacyCustodian.name.toLowerCase() === environment.name,
);
if (!legacyCustodian) {
console.warn(`Missing legacy custodian ${environment.name}`);
} else {
legacyCustodian.isNoteToTraderSupported = environment.isNoteToTraderSupported;
if(environment.apiBaseUrl) {
// Updates a legacy custodian with an API url from the configured custodian,
// it's useful for bitgo that has a different API url from dev to prod
legacyCustodian.apiUrl = environment.apiBaseUrl;
}
}
return; // Use return instead of continue
return; // Exit this routine to avoid double adding the legacy custodian
}

custodians.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export class BitgoCustodyKeyring extends CustodyKeyring {
};

sdkFactory = (authDetails: AuthDetails, envName: string): MMISDK => {
return mmiSDKFactory(BitgoCustodianApi, authDetails, this.authType, this.custodianType.apiUrl);
const custodian = this.getCustodianFromEnvName("bitgo");

return mmiSDKFactory(BitgoCustodianApi, authDetails, this.authType, custodian.apiUrl);
};

txDeepLink = async (_custodianDetails, _txId) => {
Expand Down
Loading

0 comments on commit 2e869d1

Please sign in to comment.