Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Sam/logbox #5748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
samholmes wants to merge 2 commits into develop
base: develop
Choose a base branch
Loading
from sam/logbox
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eslint.config.mjs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default [
'src/actions/WalletActions.tsx',
'src/actions/WalletListActions.tsx',
'src/actions/WalletListMenuActions.tsx',
'src/app.ts',

'src/components/App.tsx',
'src/components/buttons/ButtonsView.tsx',
'src/components/buttons/EdgeSwitch.tsx',
Expand Down
81 changes: 45 additions & 36 deletions src/app.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if (ENV.SENTRY_ORGANIZATION_SLUG.includes('SENTRY_ORGANIZATION')) {
}

// Uncomment the next line to remove popup warning/error boxes.
// LogBox.ignoreAllLogs()
if (!ENV.DEBUG_LOGBOX) LogBox.ignoreAllLogs()
LogBox.ignoreLogs([
'Require cycle:',
'Attempted to end a Span which has already ended.'
Expand Down Expand Up @@ -109,7 +109,7 @@ console.log('***********************')
console.log('App directory: ' + RNFS.DocumentDirectoryPath)
console.log('***********************')

// @ts-expect-error
// @ts-expect-error - this needs an explanation
Copy link
Contributor

@swansontec swansontec Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it does need an explanation.

This is needed for our logging integration. When we replace console.log with our own custom logging, we use global.clog to keep forwarding logs to the normal place.

This is dumb. Instead, our logging infrastructure should use named variable like export const realLog = console.log, and then call realLog() in the logging system. That avoids polluting the global scope, and makes it clear where this is being used (TypeScript becomes aware of what's going on).

global.clog = console.log

if (!__DEV__) {
Expand All @@ -119,7 +119,7 @@ if (!__DEV__) {
console.error = log
}

if (ENV.LOG_SERVER) {
if (ENV.LOG_SERVER != null) {
console.log = function () {
logToServer(arguments)
}
Expand All @@ -138,12 +138,16 @@ if (PERF_LOGGING_ONLY) {
}

if (ENABLE_PERF_LOGGING) {
// @ts-expect-error
if (!global.nativePerformanceNow && window?.performance) {
// @ts-expect-error
global.nativePerformanceNow = () => window.performance.now()
const nativePerformanceNow = (): number => {
// @ts-expect-error - this is a hack to get around the fact that window is not typed
return window.performance.now()
Comment on lines +141 to +143
Copy link
Contributor

@swansontec swansontec Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take all this performance stuff, and move it to its own file. Do not attach it to the global scope, but instead export const pnow = and so forth for each performance function. If we want to do performance analysis in the future, we can just import { pstart, pend, ... } from '../../perf.ts' or whatever you call the new file, rather than grabbing it from the global scope.

Copy link
Member

@paullinator paullinator Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why this is in global scope was for the convenience in putting it in any repo like login-ui. Admittedly since most of our code is in the webview, this doesn't help much although it would be nice to have some equivalent in there as well.

}
const makeDate = () => {
// @ts-expect-error - all performance utilities on the global object are not statically typed.
if (global.nativePerformanceNow == null && window?.performance != null) {
// @ts-expect-error - all performance utilities on the global object are not statically typed.
global.nativePerformanceNow = nativePerformanceNow
}
const makeDate = (): string => {
const d = new Date(Date.now())
const h = ('0' + d.getHours().toString()).slice(-2)
const m = ('0' + d.getMinutes().toString()).slice(-2)
Expand All @@ -152,45 +156,44 @@ if (ENABLE_PERF_LOGGING) {
return `${h}:${m}:${s}.${ms}`
}

// @ts-expect-error
// @ts-expect-error - all performance utilities on the global object are not statically typed.
global.pnow = function (label: string) {
const d = makeDate()
clog(`${d} PTIMER PNOW: ${label}`)
}

// @ts-expect-error
// @ts-expect-error - all performance utilities on the global object are not statically typed.
global.pstart = function (label: string) {
const d = makeDate()
if (!perfTotals[label]) {
if (perfTotals[label] == null) {
perfTotals[label] = 0
perfCounters[label] = 0
}
if (typeof perfTimers[label] === 'undefined') {
// @ts-expect-error
perfTimers[label] = global.nativePerformanceNow()
perfTimers[label] = nativePerformanceNow()
} else {
clog(`${d}: PTIMER Error: PTimer already started: ${label}`)
}
}

// @ts-expect-error
// @ts-expect-error - all performance utilities on the global object are not statically typed.
global.pend = function (label: string) {
const d = makeDate()
if (typeof perfTimers[label] === 'number') {
// @ts-expect-error
const elapsed = global.nativePerformanceNow() - perfTimers[label]
const elapsed = nativePerformanceNow() - perfTimers[label]
perfTotals[label] += elapsed
perfCounters[label]++
clog(
`${d}: PTIMER ${label}:${elapsed}ms total:${perfTotals[label]}ms count:${perfCounters[label]}`
)
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete perfTimers[label]
} else {
clog(`${d}: PTIMER Error: PTimer not started: ${label}`)
}
}

// @ts-expect-error
// @ts-expect-error - all performance utilities on the global object are not statically typed.
global.pcount = function (label: string) {
const d = makeDate()
if (typeof perfCounters[label] === 'undefined') {
Expand All @@ -203,33 +206,34 @@ if (ENABLE_PERF_LOGGING) {
}
}
} else {
// @ts-expect-error
// @ts-expect-error - all performance utilities on the global object are not statically typed.
global.pnow = function (label: string) {}
// @ts-expect-error
// @ts-expect-error - all performance utilities on the global object are not statically typed.
global.pstart = function (label: string) {}
// @ts-expect-error
// @ts-expect-error - all performance utilities on the global object are not statically typed.
global.pend = function (label: string) {}
// @ts-expect-error
// @ts-expect-error - all performance utilities on the global object are not statically typed.
global.pcount = function (label: string) {}
}

const realFetch = fetch
// @ts-expect-error
// @ts-expect-error - There isn't really a clean way to wrap the fetch function to add Sentry logging
// eslint-disable-next-line no-global-assign
fetch = async (...args: any) => {
// @ts-expect-error
return await realFetch(...args).catch(e => {
Sentry.addBreadcrumb({
event_id: e.name,
message: e.message,
data: args[0]
})
fetch = async (...args: [RequestInfo, RequestInit]) => {
return await realFetch(...args).catch((e: unknown) => {
if (e instanceof Error) {
Sentry.addBreadcrumb({
event_id: e.name,
message: e.message,
data: args[0] as any
})
}
throw e
})
}

if (ENV.DEBUG_THEME) {
const themeFunc = async () => {
const themeFunc = async (): Promise<void> => {
try {
const oldTheme = getTheme()
const { host, port } = asServerDetails(ENV.THEME_SERVER)
Expand All @@ -250,7 +254,7 @@ if (ENV.DEBUG_THEME) {
method: 'GET'
}
let themeJson = ''
setInterval(async () => {
const intervalCallback = async (): Promise<void> => {
try {
const response = await realFetch(url, getOptions)
const overrideTheme = await response.json()
Expand All @@ -264,17 +268,22 @@ if (ENV.DEBUG_THEME) {
} catch (e: any) {
console.log(`Failed get theme`, e.message)
}
}
setInterval(() => {
intervalCallback().catch((err: unknown) => {
console.error(err)
})
Comment on lines +272 to +275
Copy link
Contributor

@swansontec swansontec Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: This should really be makePeriodicTask, since that avoids overlapping work in cases where the async function takes more that 3s.

}, 3000)
} catch (e: any) {
console.log(`Failed to access theme server`)
}
}
themeFunc().catch(err => {
themeFunc().catch((err: unknown) => {
console.error(err)
})
}

initDeviceSettings().catch(err => {
initDeviceSettings().catch((err: unknown) => {
console.log(err)
})

Expand All @@ -284,10 +293,10 @@ NetInfo.addEventListener(state => {
const currentConnectionState = state.isConnected ?? false
if (!previousConnectionState && currentConnectionState) {
console.log('Network connected, refreshing info and coinrank...')
initInfoServer().catch(err => {
initInfoServer().catch((err: unknown) => {
console.log(err)
})
initCoinrankList().catch(err => {
initCoinrankList().catch((err: unknown) => {
console.log(err)
})
}
Expand Down
1 change: 1 addition & 0 deletions src/envConfig.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ export const asEnvConfig = asObject({
DEBUG_PLUGINS: asOptional(asBoolean, false),
DEBUG_ACCOUNTBASED: asOptional(asBoolean, false),
DEBUG_EXCHANGES: asOptional(asBoolean, false),
DEBUG_LOGBOX: asOptional(asBoolean, true),
DEBUG_VERBOSE_ERRORS: asOptional(asBoolean, false),
DEBUG_THEME: asOptional(asBoolean, false),
MUTE_CONSOLE_OUTPUT: asOptional(
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /