Skip to content

Commit

Permalink
chore(bitgo): bitgo proposal to have 2 envs (#851)
Browse files Browse the repository at this point in the history
* chore: mmi-configuration and bitgo-custodyKeyring

* feat(test update): updates test
  • Loading branch information
zone-live authored Oct 22, 2024
1 parent 29e33c4 commit 8a00358
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
8 changes: 6 additions & 2 deletions packages/custodyKeyring/src/MmiConfiguration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const v2custodian = {
tokens: "All ERC-20 tokens",
chains: ["Ethereum"],
tags: null,
apiVersion: 2,
apiVersion: "1",
custodianPublishesTransaction: false,
environments: [
{
Expand All @@ -57,9 +57,11 @@ const v2custodian = {
websocketApiUrl: "wss://websocket.dev.metamask-institutional.io/v1/ws",
apiBaseUrl: "https://saturn-custody.dev.metamask-institutional.io/eth",
iconUrl: "https://saturn-custody-ui.dev.metamask-institutional.io/saturn.svg",
apiVersion: 2,
apiVersion: "1",
custodianPublishesTransaction: false,
isNoteToTraderSupported: true,
isManualTokenInputSupported: false,
isQRCodeSupported: false
},
],
};
Expand Down Expand Up @@ -160,6 +162,8 @@ describe("MmiConfigurationController", () => {
production: v2custodian.production,
refreshTokenUrl: v2custodian.refreshTokenUrl,
isNoteToTraderSupported: v2custodian.environments[0].isNoteToTraderSupported,
isManualTokenInputSupported: v2custodian.environments[0].isManualTokenInputSupported,
isQRCodeSupported: v2custodian.environments[0].isQRCodeSupported,
websocketApiUrl: "wss://websocket.dev.metamask-institutional.io/v1/ws",
version: 2,
},
Expand Down
35 changes: 21 additions & 14 deletions packages/custodyKeyring/src/MmiConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ export class MmiConfigurationController {
const initState = opts.initState?.mmiConfiguration
? opts.initState
: {
mmiConfiguration: {
portfolio: {
enabled: false,
url: "",
cookieSetUrls: [],
mmiConfiguration: {
portfolio: {
enabled: false,
url: "",
cookieSetUrls: [],
},
features: {
websocketApi: false,
},
custodians: [], // NB: Custodians will always be empty when we start
},
features: {
websocketApi: false,
},
custodians: [], // NB: Custodians will always be empty when we start
},
};
};

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

Expand Down Expand Up @@ -99,6 +99,13 @@ export class MmiConfigurationController {
// Loop through the custodians from the API
configuredCustodians.forEach(custodian => {
custodian.environments.forEach(environment => {
if (environment.name.includes("bitgo")) {
environment.type = "Bitgo";
environment.version = 1;
environment.apiVersion = undefined;
environment.websocketApiUrl = undefined;
}

// 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
Expand All @@ -110,7 +117,7 @@ export class MmiConfigurationController {
if (!legacyCustodian) {
console.warn(`Missing legacy custodian ${environment.name}`);
} else {
if(environment.apiBaseUrl) {
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;
Expand All @@ -120,7 +127,7 @@ export class MmiConfigurationController {
}

custodians.push({
type: environment.apiVersion === "3" ? "ECA3" : "JSONRPC",
type: environment.apiVersion === "3" ? "ECA3" : environment.apiVersion === "1" ? "JSONRPC" : environment.type,
iconUrl: custodian.iconUrl,
name: custodian.name,
onboardingUrl: custodian.onboardingUrl,
Expand All @@ -136,7 +143,7 @@ export class MmiConfigurationController {
isQRCodeSupported: environment.isQRCodeSupported,
isManualTokenInputSupported: environment.isManualTokenInputSupported,
custodianPublishesTransaction: environment.custodianPublishesTransaction,
version: 2,
version: !environment.apiVersion ? 1 : 2,
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export class BitgoCustodyKeyring extends CustodyKeyring {
};

sdkFactory = (authDetails: AuthDetails, envName: string): MMISDK => {
const custodian = this.getCustodianFromEnvName("bitgo");
const custodianEnvName = envName !== "bitgo" ? "bitgo-test" : "bitgo";
const custodian = this.getCustodianFromEnvName(custodianEnvName);

return mmiSDKFactory(BitgoCustodianApi, authDetails, this.authType, custodian.apiUrl);
};
Expand Down
2 changes: 2 additions & 0 deletions packages/custodyKeyring/src/interfaces/IJsonRpcCustodian.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
interface IEnvironment {
type: string;
version: number;
refreshTokenUrl: string;
name: string;
displayName: string;
Expand Down

0 comments on commit 8a00358

Please sign in to comment.