From 0923b49c15748eb7580d62e8b4816fb4eb037969 Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Sat, 12 Nov 2022 17:01:46 -0700 Subject: [PATCH 1/4] Unsub from gas sub --- docs/src/lib/components/gas/Gas.svelte | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/src/lib/components/gas/Gas.svelte b/docs/src/lib/components/gas/Gas.svelte index fb93ef8e1..e5f9a230b 100644 --- a/docs/src/lib/components/gas/Gas.svelte +++ b/docs/src/lib/components/gas/Gas.svelte @@ -2,7 +2,7 @@ import anime from 'animejs' import GasCard from './GasCard.svelte' import gasModule from '@web3-onboard/gas' - import { onMount } from 'svelte' + import { onDestroy, onMount } from 'svelte' import { ethers } from 'ethers' import type { GasPrice, RPCGasPrice, GasData } from './types' @@ -19,6 +19,7 @@ }) } let ethMainnetGasBlockPrices + let gasUnsub let rpcGasData: RPCGasPrice onMount(() => { ethMainnetGasBlockPrices = gasModule.stream({ @@ -26,7 +27,7 @@ apiKey: 'da1b962d-314d-4903-bfe1-426821d14a35', endpoint: 'blockPrices' }) - ethMainnetGasBlockPrices.subscribe(() => { + gasUnsub = ethMainnetGasBlockPrices.subscribe(() => { async function getEtherGasFromRPC() { const INFURA_ID = '8b60d52405694345a99bcb82e722e0af' const infuraRPC = `https://mainnet.infura.io/v3/${INFURA_ID}` @@ -62,6 +63,9 @@ estimatedTransactionCount: null, seconds: null } + onDestroy(() => { + gasUnsub.unsubscribe() + })
From b84f2e714f372e028a54176fe9fc06fbb8c6b9bb Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Sat, 12 Nov 2022 17:02:27 -0700 Subject: [PATCH 2/4] rename --- docs/src/lib/components/gas/Gas.svelte | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/src/lib/components/gas/Gas.svelte b/docs/src/lib/components/gas/Gas.svelte index e5f9a230b..ce406b8a9 100644 --- a/docs/src/lib/components/gas/Gas.svelte +++ b/docs/src/lib/components/gas/Gas.svelte @@ -19,7 +19,7 @@ }) } let ethMainnetGasBlockPrices - let gasUnsub + let gasSub let rpcGasData: RPCGasPrice onMount(() => { ethMainnetGasBlockPrices = gasModule.stream({ @@ -27,7 +27,7 @@ apiKey: 'da1b962d-314d-4903-bfe1-426821d14a35', endpoint: 'blockPrices' }) - gasUnsub = ethMainnetGasBlockPrices.subscribe(() => { + gasSub = ethMainnetGasBlockPrices.subscribe(() => { async function getEtherGasFromRPC() { const INFURA_ID = '8b60d52405694345a99bcb82e722e0af' const infuraRPC = `https://mainnet.infura.io/v3/${INFURA_ID}` @@ -64,7 +64,7 @@ seconds: null } onDestroy(() => { - gasUnsub.unsubscribe() + gasSub.unsubscribe() }) From b03d84ccf95824653f03affcf50f6545ac7bb2c3 Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Sat, 12 Nov 2022 17:07:51 -0700 Subject: [PATCH 3/4] Null check --- docs/src/lib/components/gas/Gas.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/lib/components/gas/Gas.svelte b/docs/src/lib/components/gas/Gas.svelte index ce406b8a9..772aa6f16 100644 --- a/docs/src/lib/components/gas/Gas.svelte +++ b/docs/src/lib/components/gas/Gas.svelte @@ -64,7 +64,7 @@ seconds: null } onDestroy(() => { - gasSub.unsubscribe() + gasSub && gasSub.unsubscribe() }) From 4fbcc14e580c3b38a6c09b8d7b85efd0e29a1dee Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Sat, 12 Nov 2022 17:09:34 -0700 Subject: [PATCH 4/4] prettier --- docs/src/lib/components/gas/Gas.svelte | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/src/lib/components/gas/Gas.svelte b/docs/src/lib/components/gas/Gas.svelte index 772aa6f16..0497d8951 100644 --- a/docs/src/lib/components/gas/Gas.svelte +++ b/docs/src/lib/components/gas/Gas.svelte @@ -63,6 +63,7 @@ estimatedTransactionCount: null, seconds: null } + onDestroy(() => { gasSub && gasSub.unsubscribe() })