-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into av/feat/qr-code-modal
- Loading branch information
Showing
10 changed files
with
193 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/frontend/src/icp/components/fee/EthereumFeeContext.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<script lang="ts"> | ||
import type { NetworkId } from '$lib/types/network'; | ||
import { isTokenCkErc20Ledger, isTokenCkEthLedger } from '$icp/utils/ic-send.utils'; | ||
import { token, tokenId } from '$lib/derived/token.derived'; | ||
import type { IcToken } from '$icp/types/ic'; | ||
import { isNetworkIdEthereum } from '$lib/utils/network.utils'; | ||
import { eip1559TransactionPriceStore } from '$icp/stores/cketh.store'; | ||
import { icrcTokens } from '$icp/derived/icrc.derived'; | ||
import { nonNullish } from '@dfinity/utils'; | ||
import { CKERC20_TO_ERC20_MAX_TRANSACTION_FEE } from '$icp/constants/cketh.constants'; | ||
import { loadEip1559TransactionPrice } from '$icp/services/cketh.services'; | ||
import { getContext, onDestroy } from 'svelte'; | ||
import { | ||
ETHEREUM_FEE_CONTEXT_KEY, | ||
type EthereumFeeContext | ||
} from '$icp/stores/ethereum-fee.store'; | ||
export let networkId: NetworkId | undefined = undefined; | ||
let ckETH = false; | ||
$: ckETH = isTokenCkEthLedger($token as IcToken); | ||
let ckEr20 = false; | ||
$: ckEr20 = isTokenCkErc20Ledger($token as IcToken); | ||
let ethNetwork = false; | ||
$: ethNetwork = isNetworkIdEthereum(networkId); | ||
let maxTransactionFeeEth: bigint | undefined = undefined; | ||
$: maxTransactionFeeEth = $eip1559TransactionPriceStore?.[$tokenId]?.data.max_transaction_fee; | ||
let tokenCkEth: IcToken | undefined; | ||
$: tokenCkEth = $icrcTokens.find(isTokenCkEthLedger); | ||
let maxTransactionFeePlusEthLedgerApprove: bigint | undefined = undefined; | ||
$: maxTransactionFeePlusEthLedgerApprove = nonNullish(maxTransactionFeeEth) | ||
? maxTransactionFeeEth + CKERC20_TO_ERC20_MAX_TRANSACTION_FEE + (tokenCkEth?.fee ?? 0n) | ||
: undefined; | ||
let maxTransactionFee: bigint | undefined = undefined; | ||
$: maxTransactionFee = | ||
nonNullish(maxTransactionFeePlusEthLedgerApprove) && ckEr20 | ||
? maxTransactionFeePlusEthLedgerApprove + CKERC20_TO_ERC20_MAX_TRANSACTION_FEE | ||
: maxTransactionFeePlusEthLedgerApprove; | ||
const { store } = getContext<EthereumFeeContext>(ETHEREUM_FEE_CONTEXT_KEY); | ||
$: store.setFee({ maxTransactionFee }); | ||
const updateContext = () => { | ||
if ((!ckETH && !ckEr20) || !ethNetwork) { | ||
store.setFee(null); | ||
return; | ||
} | ||
store.setFee({ maxTransactionFee }); | ||
}; | ||
$: maxTransactionFee, updateContext(); | ||
const loadFee = async () => { | ||
clearTimer(); | ||
if ((!ckETH && !ckEr20) || !ethNetwork) { | ||
updateContext(); | ||
return; | ||
} | ||
const load = async () => await loadEip1559TransactionPrice($token as IcToken); | ||
await load(); | ||
timer = setInterval(load, 30000); | ||
}; | ||
$: networkId, (async () => await loadFee())(); | ||
let timer: NodeJS.Timeout | undefined; | ||
const clearTimer = () => clearInterval(timer); | ||
onDestroy(clearTimer); | ||
</script> | ||
|
||
<slot /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.