2023-11-21 14:35:43 -08:00
|
|
|
import { Connection } from '@solana/web3.js'
|
|
|
|
import { sleep } from 'utils'
|
|
|
|
|
2023-07-20 18:40:37 -07:00
|
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
|
|
export function getNetworkInfo() {
|
|
|
|
const connection =
|
|
|
|
(navigator as any).connection ||
|
|
|
|
(navigator as any).mozConnection ||
|
|
|
|
(navigator as any).webkitConnection
|
|
|
|
if (connection) {
|
|
|
|
return connection.effectiveType
|
|
|
|
}
|
|
|
|
return 'unknown'
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function isNetworkSlow() {
|
|
|
|
return ['slow-2g', '2g', '3g'].includes(getNetworkInfo()) ? true : false
|
|
|
|
}
|
2023-11-21 14:35:43 -08:00
|
|
|
|
|
|
|
export async function waitForSlot(connection: Connection, slot: number) {
|
|
|
|
let lastSlot = 0
|
|
|
|
while (slot > lastSlot) {
|
|
|
|
lastSlot = await connection.getSlot()
|
|
|
|
await sleep(250)
|
|
|
|
}
|
|
|
|
}
|