Skip to content

Commit

Permalink
apiUrl refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghel committed Feb 19, 2024
1 parent 0f97ab2 commit 563f27e
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,7 @@ export const robot = (app: Probot) => {
const allOwners: string[] = [];
const allOwnersToCheck = [mainOwner, ...extraOwners];

let apiUrl = 'https://next-api.multiversx.com';
if (network === 'devnet') {
apiUrl = 'https://devnet-api.multiversx.com';
} else if (network === 'testnet') {
apiUrl = 'https://testnet-api.multiversx.com';
}
const apiUrl = getApiUrl();

for (const owner of allOwnersToCheck) {
if (new Address(owner).isContractAddress()) {
Expand All @@ -88,12 +83,7 @@ export const robot = (app: Probot) => {
}
const account = identity;

let apiUrl = 'https://next-api.multiversx.com';
if (network === 'devnet') {
apiUrl = 'https://devnet-api.multiversx.com';
} else if (network === 'testnet') {
apiUrl = 'https://testnet-api.multiversx.com';
}
const apiUrl = getApiUrl();

const ownerResult = await axios.get(`${apiUrl}/accounts/${account}?extract=ownerAddress`);
const accountOwner = ownerResult.data;
Expand All @@ -113,13 +103,7 @@ export const robot = (app: Probot) => {
}
const token = identity;

let apiUrl = 'https://next-api.multiversx.com';
if (network === 'devnet') {
apiUrl = 'https://devnet-api.multiversx.com';
} else if (network === 'testnet') {
apiUrl = 'https://testnet-api.multiversx.com';
}

const apiUrl = getApiUrl();

const tokenOwner = await getTokenOwnerFromApi(token, apiUrl);
if (new Address(tokenOwner).isContractAddress()) {
Expand All @@ -139,6 +123,19 @@ export const robot = (app: Probot) => {
return '';
}

function getApiUrl() {
switch (network) {
case 'mainnet':
return 'https://next-api.multiversx.com';
case 'devnet':
return 'https://devnet-api.multiversx.com';
case 'testnet':
return 'https://testnet-api.multiversx.com';
}

throw new Error(`Invalid network: ${network}`);
}

function getDistinctNetworks(fileNames: string[]) {
const networks = fileNames.map(fileName => getNetwork(fileName)).filter(x => x !== undefined);

Expand Down

0 comments on commit 563f27e

Please sign in to comment.