Skip to content

Commit

Permalink
added domain provider exception logic (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
kailash-bitpack committed May 11, 2023
1 parent 6e0385b commit b7870d8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/lib/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ export class DappStoreRegistry {
const newUrls: string[] = []
try {
const allNewDappIds = dapps.map((dapp) => {
const dappId = getDappId(dapp.appUrl, dapps, newUrls);
const dappId = getDappId(dapp.appUrl, [], newUrls);
newUrls.push(dappId);
return dappId;
});
Expand Down
18 changes: 16 additions & 2 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,21 @@ export const getDappId = (appUrl: string | undefined, dapps: DAppSchema[], newUr

if (urlSuffix[urlSuffix.length-1] === '-') urlSuffix = urlSuffix.split('').splice(0, urlSuffix.length-1).join('');

const domainProviders = ['vercel', 'twitter', 'instagram', 'bitly', 'netlify'];
const [first, start, ...others] = parts[0].split('.').reverse();
// only for domain providers
if (domainProviders.includes(start)) {
let dappId = `${others}.app`.toLocaleLowerCase();
if (others.length > 0) {
if(typeof others !== 'string') dappId = `${others.join('-')}.app`.toLocaleLowerCase();
if(!checkIfExists(dappId, dapps, newUrls)) return dappId;
}
dappId = `${dappId.split('.app')[0]}`;
dappId = `${dappId.length > 0 ? dappId+'-'+urlSuffix: urlSuffix}.app`.toLocaleLowerCase();
if(!checkIfExists(dappId, dapps, newUrls)) return dappId;
// return dappId;
throw new Error(`dapp Id already exists, dappId: ${dappId}`);
}

// check if {domain}.app is available
let dappId = `${start}.app`.toLocaleLowerCase();
Expand All @@ -575,6 +589,6 @@ export const getDappId = (appUrl: string | undefined, dapps: DAppSchema[], newUr
dappId = `${start}${urlSuffix.length > 0 ? '-'+urlSuffix: ''}.app`.toLocaleLowerCase();
if(!checkIfExists(dappId, dapps, newUrls)) return dappId;
debug(`dappId already Exists:::, dappId: ${dappId}, first: ${first}, others:${others}`);
return dappId;
// throw new Error(`dapp Id already exists, dappId: ${dappId}`);
// return dappId;
throw new Error(`dapp Id already exists, dappId: ${dappId}`);
}
6 changes: 3 additions & 3 deletions src/registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -7203,7 +7203,7 @@
"chains": [
1
],
"dappId": "vercel.app",
"dappId": "roleformetaverse.app",
"downloadBaseUrls": [
{
"url": "https://roleformetaverse.vercel.app/#/",
Expand Down Expand Up @@ -27674,7 +27674,7 @@
"chains": [
1
],
"dappId": "netlify.app",
"dappId": "degenskellies.app",
"downloadBaseUrls": [
{
"url": "https://degenskellies.netlify.app/",
Expand Down Expand Up @@ -27738,7 +27738,7 @@
"chains": [
1
],
"dappId": "twitter.app",
"dappId": "central_frog.app",
"downloadBaseUrls": [
{
"url": "https://twitter.com/central_frog",
Expand Down

0 comments on commit b7870d8

Please sign in to comment.