Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
397419f5
Unverified
Commit
397419f5
authored
Oct 25, 2022
by
tom goriunov
Committed by
GitHub
Oct 25, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #276 from blockscout/refine-config
refine app config
parents
ede913d3
932f011a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
50 deletions
+50
-50
config.ts
configs/app/config.ts
+48
-30
featuredNetworks.ts
lib/networks/featuredNetworks.ts
+1
-10
networkExplorers.ts
lib/networks/networkExplorers.ts
+1
-10
No files found.
configs/app/config.ts
View file @
397419f5
/* eslint-disable no-restricted-properties */
/* eslint-disable no-restricted-properties */
import
type
{
FeaturedNetwork
,
NetworkExplorer
}
from
'
types/networks
'
;
const
getEnvValue
=
(
env
:
string
|
undefined
)
=>
env
?.
replaceAll
(
'
\'
'
,
'
"
'
);
const
parseEnvJson
=
<
DataType
>
(
env
:
string
|
undefined
):
DataType
|
null
=>
{
try
{
return
JSON
.
parse
(
env
||
'
null
'
);
}
catch
(
error
)
{
return
null
;
}
};
const
env
=
process
.
env
.
VERCEL_ENV
||
process
.
env
.
NODE_ENV
;
const
env
=
process
.
env
.
VERCEL_ENV
||
process
.
env
.
NODE_ENV
;
const
isDev
=
env
===
'
development
'
;
const
isDev
=
env
===
'
development
'
;
const
appPort
=
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_APP_PORT
);
const
appSchema
=
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_APP_PROTOCOL
);
const
appHost
=
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_APP_HOST
);
const
baseUrl
=
[
const
baseUrl
=
[
process
.
env
.
NEXT_PUBLIC_APP_PROTOCOL
?.
replaceAll
(
'
\'
'
,
'
"
'
)
||
'
https
'
,
appSchema
||
'
https
'
,
'
://
'
,
'
://
'
,
process
.
env
.
NEXT_PUBLIC_VERCEL_URL
||
process
.
env
.
NEXT_PUBLIC_APP_HOST
,
process
.
env
.
NEXT_PUBLIC_VERCEL_URL
||
appHost
,
process
.
env
.
NEXT_PUBLIC_APP_PORT
?.
replaceAll
(
'
\'
'
,
'
"
'
)
?
'
:
'
+
process
.
env
.
NEXT_PUBLIC_APP_PORT
:
''
,
appPort
&&
'
:
'
+
appPort
,
].
join
(
''
);
].
filter
(
Boolean
).
join
(
''
);
const
networkType
=
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_NETWORK_TYPE
);
const
networkSubType
=
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_NETWORK_SUBTYPE
);
const
DEFAULT_CURRENCY_DECIMALS
=
18
;
const
DEFAULT_CURRENCY_DECIMALS
=
18
;
...
@@ -14,40 +32,40 @@ const config = Object.freeze({
...
@@ -14,40 +32,40 @@ const config = Object.freeze({
env
,
env
,
isDev
,
isDev
,
network
:
{
network
:
{
type
:
process
.
env
.
NEXT_PUBLIC_NETWORK_TYPE
,
type
:
networkType
,
subtype
:
process
.
env
.
NEXT_PUBLIC_NETWORK_SUBTYPE
,
subtype
:
networkSubType
,
logo
:
process
.
env
.
NEXT_PUBLIC_NETWORK_LOGO
,
logo
:
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_NETWORK_LOGO
)
,
name
:
process
.
env
.
NEXT_PUBLIC_NETWORK_NAME
,
name
:
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_NETWORK_NAME
)
,
id
:
process
.
env
.
NEXT_PUBLIC_NETWORK_ID
,
id
:
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_NETWORK_ID
)
,
shortName
:
process
.
env
.
NEXT_PUBLIC_NETWORK_SHORT_NAME
,
shortName
:
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_NETWORK_SHORT_NAME
)
,
currency
:
{
currency
:
{
name
:
process
.
env
.
NEXT_PUBLIC_NETWORK_CURRENCY_NAME
,
name
:
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_NETWORK_CURRENCY_NAME
)
,
symbol
:
process
.
env
.
NEXT_PUBLIC_NETWORK_CURRENCY_SYMBOL
,
symbol
:
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_NETWORK_CURRENCY_SYMBOL
)
,
decimals
:
Number
(
process
.
env
.
NEXT_PUBLIC_NETWORK_CURRENCY_DECIMALS
)
||
DEFAULT_CURRENCY_DECIMALS
,
decimals
:
Number
(
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_NETWORK_CURRENCY_DECIMALS
)
)
||
DEFAULT_CURRENCY_DECIMALS
,
},
},
assetsPathname
:
process
.
env
.
NEXT_PUBLIC_NETWORK_ASSETS_PATHNAME
,
assetsPathname
:
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_NETWORK_ASSETS_PATHNAME
)
,
nativeTokenAddress
:
process
.
env
.
NEXT_PUBLIC_NETWORK_TOKEN_ADDRESS
,
nativeTokenAddress
:
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_NETWORK_TOKEN_ADDRESS
)
,
basePath
:
'
/
'
+
[
process
.
env
.
NEXT_PUBLIC_NETWORK_TYPE
,
process
.
env
.
NEXT_PUBLIC_NETWORK_SUBTYPE
].
filter
(
Boolean
).
join
(
'
/
'
),
basePath
:
'
/
'
+
[
networkType
,
networkSubType
].
filter
(
Boolean
).
join
(
'
/
'
),
explorers
:
p
rocess
.
env
.
NEXT_PUBLIC_NETWORK_EXPLORERS
?.
replaceAll
(
'
\'
'
,
'
"
'
)
,
explorers
:
p
arseEnvJson
<
Array
<
NetworkExplorer
>>
(
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_NETWORK_EXPLORERS
))
||
[]
,
verificationType
:
process
.
env
.
NEXT_PUBLIC_NETWORK_VERIFICATION_TYPE
||
'
mining
'
,
verificationType
:
process
.
env
.
NEXT_PUBLIC_NETWORK_VERIFICATION_TYPE
||
'
mining
'
,
},
},
footerLinks
:
{
footerLinks
:
{
github
:
process
.
env
.
NEXT_PUBLIC_FOOTER_GITHUB_LINK
,
github
:
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_FOOTER_GITHUB_LINK
)
,
twitter
:
process
.
env
.
NEXT_PUBLIC_FOOTER_TWITTER_LINK
,
twitter
:
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_FOOTER_TWITTER_LINK
)
,
telegram
:
process
.
env
.
NEXT_PUBLIC_FOOTER_TELEGRAM_LINK
,
telegram
:
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_FOOTER_TELEGRAM_LINK
)
,
staking
:
process
.
env
.
NEXT_PUBLIC_FOOTER_STAKING_LINK
,
staking
:
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_FOOTER_STAKING_LINK
)
,
},
},
featuredNetworks
:
p
rocess
.
env
.
NEXT_PUBLIC_FEATURED_NETWORKS
?.
replaceAll
(
'
\'
'
,
'
"
'
)
,
featuredNetworks
:
p
arseEnvJson
<
Array
<
FeaturedNetwork
>>
(
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_FEATURED_NETWORKS
))
||
[]
,
blockScoutVersion
:
process
.
env
.
NEXT_PUBLIC_BLOCKSCOUT_VERSION
,
blockScoutVersion
:
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_BLOCKSCOUT_VERSION
)
,
isAccountSupported
:
process
.
env
.
NEXT_PUBLIC_IS_ACCOUNT_SUPPORTED
?.
replaceAll
(
'
\'
'
,
'
"
'
)
===
'
true
'
,
isAccountSupported
:
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_IS_ACCOUNT_SUPPORTED
)
===
'
true
'
,
marketplaceSubmitForm
:
process
.
env
.
NEXT_PUBLIC_MARKETPLACE_SUBMIT_FORM
,
marketplaceSubmitForm
:
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_MARKETPLACE_SUBMIT_FORM
)
,
protocol
:
process
.
env
.
NEXT_PUBLIC_APP_PROTOCOL
,
protocol
:
appSchema
,
host
:
process
.
env
.
NEXT_PUBLIC_APP_HOST
,
host
:
appHost
,
port
:
process
.
env
.
NEXT_PUBLIC_APP_PORT
,
port
:
appPort
,
baseUrl
,
baseUrl
,
api
:
{
api
:
{
endpoint
:
process
.
env
.
NEXT_PUBLIC_API_ENDPOINT
||
'
https://blockscout.com
'
,
endpoint
:
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_API_ENDPOINT
)
||
'
https://blockscout.com
'
,
basePath
:
process
.
env
.
NEXT_PUBLIC_API_BASE_PATH
||
''
,
basePath
:
getEnvValue
(
process
.
env
.
NEXT_PUBLIC_API_BASE_PATH
)
||
''
,
},
},
});
});
...
...
lib/networks/featuredNetworks.ts
View file @
397419f5
...
@@ -90,17 +90,8 @@ const ICONS: Record<string, React.FunctionComponent<React.SVGAttributes<SVGEleme
...
@@ -90,17 +90,8 @@ const ICONS: Record<string, React.FunctionComponent<React.SVGAttributes<SVGEleme
// },
// },
// ]).replaceAll('"', '\'');
// ]).replaceAll('"', '\'');
function
parseNetworkConfig
()
{
try
{
return
JSON
.
parse
(
appConfig
.
featuredNetworks
||
'
[]
'
);
}
catch
(
error
)
{
return
[];
}
}
const
featuredNetworks
:
Array
<
FeaturedNetwork
>
=
(()
=>
{
const
featuredNetworks
:
Array
<
FeaturedNetwork
>
=
(()
=>
{
const
networksFromConfig
:
Array
<
FeaturedNetwork
>
=
parseNetworkConfig
();
return
appConfig
.
featuredNetworks
.
map
((
network
)
=>
({
return
networksFromConfig
.
map
((
network
)
=>
({
...
network
,
...
network
,
icon
:
network
.
icon
||
ICONS
[
network
.
basePath
],
icon
:
network
.
icon
||
ICONS
[
network
.
basePath
],
}));
}));
...
...
lib/networks/networkExplorers.ts
View file @
397419f5
...
@@ -16,20 +16,11 @@ import appConfig from 'configs/app/config';
...
@@ -16,20 +16,11 @@ import appConfig from 'configs/app/config';
// },
// },
// ]).replaceAll('"', '\'');
// ]).replaceAll('"', '\'');
function
parseNetworkExplorers
()
{
try
{
return
JSON
.
parse
(
appConfig
.
network
.
explorers
||
'
[]
'
);
}
catch
(
error
)
{
return
[];
}
}
const
stripTrailingSlash
=
(
str
:
string
)
=>
str
.
at
(
-
1
)
===
'
/
'
?
str
.
slice
(
0
,
-
1
)
:
str
;
const
stripTrailingSlash
=
(
str
:
string
)
=>
str
.
at
(
-
1
)
===
'
/
'
?
str
.
slice
(
0
,
-
1
)
:
str
;
const
addLeadingSlash
=
(
str
:
string
)
=>
str
.
at
(
0
)
===
'
/
'
?
str
:
'
/
'
+
str
;
const
addLeadingSlash
=
(
str
:
string
)
=>
str
.
at
(
0
)
===
'
/
'
?
str
:
'
/
'
+
str
;
const
networkExplorers
:
Array
<
NetworkExplorer
>
=
(()
=>
{
const
networkExplorers
:
Array
<
NetworkExplorer
>
=
(()
=>
{
const
explorers
:
Array
<
NetworkExplorer
>
=
parseNetworkExplorers
();
return
appConfig
.
network
.
explorers
.
map
((
explorer
)
=>
({
return
explorers
.
map
((
explorer
)
=>
({
...
explorer
,
...
explorer
,
baseUrl
:
stripTrailingSlash
(
explorer
.
baseUrl
),
baseUrl
:
stripTrailingSlash
(
explorer
.
baseUrl
),
paths
:
_mapValues
(
explorer
.
paths
,
_compose
(
stripTrailingSlash
,
addLeadingSlash
)),
paths
:
_mapValues
(
explorer
.
paths
,
_compose
(
stripTrailingSlash
,
addLeadingSlash
)),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment