Skip to content

Commit d9fffd1

Browse files
authored
Add gas unsubscribe on destroy (#1360)
1 parent d46bd4d commit d9fffd1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

docs/src/lib/components/gas/Gas.svelte

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import anime from 'animejs'
33
import GasCard from './GasCard.svelte'
44
import gasModule from '@web3-onboard/gas'
5-
import { onMount } from 'svelte'
5+
import { onDestroy, onMount } from 'svelte'
66
import { ethers } from 'ethers'
77
import type { GasPrice, RPCGasPrice, GasData } from './types'
88
@@ -19,14 +19,15 @@
1919
})
2020
}
2121
let ethMainnetGasBlockPrices
22+
let gasSub
2223
let rpcGasData: RPCGasPrice
2324
onMount(() => {
2425
ethMainnetGasBlockPrices = gasModule.stream({
2526
chains: ['0x1'],
2627
apiKey: 'da1b962d-314d-4903-bfe1-426821d14a35',
2728
endpoint: 'blockPrices'
2829
})
29-
ethMainnetGasBlockPrices.subscribe(() => {
30+
gasSub = ethMainnetGasBlockPrices.subscribe(() => {
3031
async function getEtherGasFromRPC() {
3132
const INFURA_ID = '8b60d52405694345a99bcb82e722e0af'
3233
const infuraRPC = `https://mainnet.infura.io/v3/${INFURA_ID}`
@@ -62,6 +63,10 @@
6263
estimatedTransactionCount: null,
6364
seconds: null
6465
}
66+
67+
onDestroy(() => {
68+
gasSub && gasSub.unsubscribe()
69+
})
6570
</script>
6671

6772
<div class="Gas px-6 p-4">

0 commit comments

Comments
 (0)