Skip to content
This repository was archived by the owner on Oct 27, 2023. It is now read-only.

Commit 7f10396

Browse files
authored
hotfix: logging, apm, ga (#866)
2 parents fbb817c + d30666d commit 7f10396

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1526
-360
lines changed

.env.example

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,25 @@ NEXT_PUBLIC_PROPOSAL_ACCEPTED=
105105
NEXT_PUBLIC_PROPOSAL_REJECTED=
106106

107107
# Google Analytics Measurement ID
108-
NEXT_PUBLIC_GA_MEASUREMENT_ID=
108+
NEXT_PUBLIC_GA_MEASUREMENT_ID=
109+
110+
# API log level: 0 none, 1 error, 2 warn, 3 info, 4 trace, 5 log, 6 debug
111+
LOG_LEVEL=6
112+
113+
# Elastic APM integration secret token
114+
ELASTIC_APM_SECRET_TOKEN=
115+
116+
# Elastic APM integration server url
117+
ELASTIC_APM_SERVER_URL=
118+
119+
# Elastic APM integration service name
120+
ELASTIC_APM_SERVICE_NAME=
121+
122+
# true|false - Enable Elastic APM integration
123+
ELASTIC_APM_ACTIVE=
124+
125+
# Elastic APM _local_ log level
126+
ELASTIC_APM_LOG_LEVEL=
127+
128+
# true|false - should we index Logger.trace() into elastic
129+
ELASTIC_INDEX_STACK_TRACE=

components/bounties/list-active-networks.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export default function ListActiveNetworks() {
4545
<h4 className="mt-1">{t("most-active-networks")}</h4>
4646
<Link href={"/networks"}>
4747
<a
48-
target="_blank"
4948
className="text-decoration-none text-primary mt-2"
5049
rel="noreferrer"
5150
>

components/connect-wallet-button.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ import {changeShowWeb3} from "../contexts/reducers/update-show-prop";
1919
export default function ConnectWalletButton({children = null, asModal = false, forceLogin = false,}) {
2020
const { t } = useTranslation(["common", "connect-wallet-button"]);
2121

22-
const {dispatch, state: { loading, connectedChain },} = useAppState();
22+
const {dispatch, state} = useAppState();
2323
const [showModal, setShowModal] = useState(false);
2424

25-
const {state} = useAppState();
26-
2725
const { connectWallet } = useAuthentication();
2826

2927
async function handleLogin() {
@@ -35,11 +33,12 @@ export default function ConnectWalletButton({children = null, asModal = false, f
3533
if (!state.Service?.active)
3634
return;
3735

38-
if (+state.connectedChain?.id === +state.Settings?.requiredChain?.id) {
36+
if (
37+
(+state.connectedChain?.id || +window?.ethereum?.chainId) ===
38+
+state.Settings?.requiredChain?.id
39+
) {
3940
connectWallet();
4041
} else {
41-
console.log('no connected chain?', connectedChain, state.Settings?.requiredChain);
42-
4342
dispatch(changeChain.update({...state.connectedChain, id: state.Settings?.requiredChain?.id}));
4443
setShowModal(false);
4544
}
@@ -64,7 +63,7 @@ export default function ConnectWalletButton({children = null, asModal = false, f
6463

6564

6665
if (asModal) {
67-
if (loading?.isLoading) return <></>;
66+
if (state?.loading?.isLoading) return <></>;
6867

6968
return (
7069
<Modal

components/main-nav.tsx

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {ReactElement, ReactNode, useEffect, useState} from "react";
33
import {Defaults} from "@taikai/dappkit";
44
import {useRouter} from "next/router";
55

6+
import ExternalLinkIcon from "assets/icons/external-link-icon";
67
import HelpIcon from "assets/icons/help-icon";
78
import LogoPlaceholder from "assets/icons/logo-placeholder";
89
import PlusIcon from "assets/icons/plus-icon";
@@ -45,7 +46,7 @@ export default function MainNav() {
4546
const { searchNetworks } = useApi();
4647
const { getURLWithNetwork } = useNetworkTheme();
4748

48-
const noNeedNetworkInstance = ["/networks", "/new-network", "/bounty-hall", "/leaderboard"].includes(pathname);
49+
const noNeedNetworkInstance = ["/networks", "/new-network", "/explore", "/leaderboard"].includes(pathname);
4950
const fullLogoUrl = state.Service?.network?.active?.fullLogo;
5051

5152
useEffect(() => {
@@ -74,7 +75,21 @@ export default function MainNav() {
7475
if(!window.ethereum) return dispatch(changeShowWeb3(true))
7576
return dispatch(changeShowCreateBounty(true))
7677

77-
}
78+
}
79+
80+
function LinkExplore() {
81+
return (
82+
<InternalLink
83+
className="mt-1"
84+
href={"/explore"}
85+
blank={!noNeedNetworkInstance}
86+
label={<Translation label={"main-nav.explorer"} />}
87+
nav
88+
uppercase
89+
icon={!noNeedNetworkInstance ? <ExternalLinkIcon className="mb-1" width={12} height={12} />:null}
90+
/>
91+
);
92+
}
7893

7994
function LinkNetworks() {
8095
return(
@@ -101,7 +116,9 @@ export default function MainNav() {
101116
function LinkBounties() {
102117
return (
103118
<InternalLink
104-
href={"/bounty-hall"}
119+
href={getURLWithNetwork("/bounties", {
120+
network: state.Service?.network?.active?.name,
121+
})}
105122
label={<Translation label={"main-nav.nav-avatar.bounties"} />}
106123
nav
107124
uppercase
@@ -110,41 +127,17 @@ export default function MainNav() {
110127
}
111128

112129
const brandLogo = !noNeedNetworkInstance ? (
113-
<InternalLink
114-
href={getURLWithNetwork("/", {
115-
network: state.Service?.network?.active?.name,
116-
})}
117-
icon={
118-
fullLogoUrl ? (
119-
<img
120-
src={`${state.Settings?.urls?.ipfs}/${fullLogoUrl}`}
121-
width={104}
122-
height={40}
123-
/>
124-
) : (
125-
<LogoPlaceholder />
126-
)
127-
}
128-
className="brand"
129-
nav
130-
active
131-
brand
132-
/>
133-
): (
134-
<InternalLink
135-
href={'/'}
136-
icon={
137-
<img
138-
src={`/images/Bepro_Logo_Light.svg`}
139-
width={104}
140-
height={40}
141-
/>
142-
}
143-
className="brand"
144-
nav
145-
active
146-
brand
130+
fullLogoUrl ? (
131+
<img
132+
src={`${state.Settings?.urls?.ipfs}/${fullLogoUrl}`}
133+
width={104}
134+
height={40}
147135
/>
136+
) : (
137+
<LogoPlaceholder />
138+
)
139+
) : (
140+
<img src={`/images/Bepro_Logo_Light.svg`} width={104} height={40} />
148141
);
149142

150143
return (
@@ -163,7 +156,6 @@ export default function MainNav() {
163156
<li>
164157
<LinkBounties />
165158
</li>
166-
167159
<li>
168160
<InternalLink
169161
href={getURLWithNetwork("/curators", {
@@ -180,18 +172,21 @@ export default function MainNav() {
180172
<li>
181173
<LinkLeaderBoard />
182174
</li>
175+
<li>
176+
<LinkExplore />
177+
</li>
183178
</ul>
184179
)) || (
185180
<ul className="nav-links">
186-
<li>
187-
<LinkBounties />
188-
</li>
189181
<li>
190182
<LinkNetworks/>
191183
</li>
192184
<li>
193185
<LinkLeaderBoard />
194186
</li>
187+
<li>
188+
<LinkExplore />
189+
</li>
195190
</ul>
196191
)}
197192
</div>

components/transaction-modal.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {toastInfo} from "contexts/reducers/change-toaster";
1919
import {CopyValue} from "helpers/copy-value";
2020
import {formatStringToCurrency} from "helpers/formatNumber";
2121
import {truncateAddress} from "helpers/truncate-address";
22+
import { isValidUrl } from "helpers/validateUrl";
2223

2324
import {BlockTransaction, Transaction} from "interfaces/transaction";
2425

@@ -99,7 +100,9 @@ export default function TransactionModal({
99100
}
100101

101102
function getEtherScanHref(tx: string) {
102-
return `${state.Settings?.urls?.blockScan}/${tx}`;
103+
const url = state.Settings?.urls?.blockScan
104+
const validUrl = isValidUrl(url) ? url : `https://${url}`
105+
return `${validUrl}/${tx}`;
103106
}
104107

105108
return (

components/web3-dialog.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ export default function WebThreeDialog() {
3131

3232
useEffect(() => {
3333
if (![
34+
"/explore",
35+
"/leaderboard",
36+
"/networks",
3437
getURLWithNetwork("/").pathname,
3538
getURLWithNetwork("/bounties").pathname,
3639
getURLWithNetwork("/curators").pathname,
37-
getURLWithNetwork("/oracle").pathname,
38-
getURLWithNetwork("/oracle/new-bounties").pathname,
39-
getURLWithNetwork("/oracle/ready-to-merge").pathname,
4040
"/[network]/bounty",
4141
"/[network]",
4242
].includes(router.pathname))

elastic-apm-node.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require(`dotenv`).config();
2+
3+
module.exports = {
4+
serverUrl: process.env.ELASTIC_APM_SERVER_URL, // E.g. https://my-deployment-name.apm.us-west2.gcp.elastic-cloud.com
5+
secretToken: process.env.ELASTIC_APM_SECRET_TOKEN,
6+
serviceName: process.env.ELASTIC_APM_SERVICE_NAME,
7+
active: process.env.ELASTIC_APM_ACTIVE === "true",
8+
logLevel: process.env.ELASTIC_APM_LOG_LEVEL
9+
}

helpers/error-messages.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const UNAUTHORIZED = `Unauthorized`;
2+
export const INVALID_JWT_TOKEN = `Invalid JWT Token`;

helpers/validateUrl.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function isValidUrl(string) {
2+
try {
3+
new URL(string);
4+
return true;
5+
} catch (err) {
6+
return false;
7+
}
8+
}

middleware/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import {LogAccess} from "./log-access";
12
import withCors from "./withCors";
23
import WithJwt from "./withJwt";
34

45
const withProtected = (handler) => withCors(WithJwt(handler))
5-
export {withCors, WithJwt, withProtected}
6+
const RouteMiddleware = (handler) => LogAccess(withCors(WithJwt(handler)));
7+
8+
export {withCors, WithJwt, withProtected, RouteMiddleware};

0 commit comments

Comments
 (0)