Skip to content
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

hotfix: sip10 memo and rune balances #5450

Merged
merged 3 commits into from
May 24, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import BigNumber from 'bignumber.js';

import { CryptoCurrencies } from '@shared/models/currencies.model';
import { createMoney } from '@shared/models/money.model';
import { isDefined } from '@shared/utils';

import {
baseCurrencyAmountInQuote,
Expand Down Expand Up @@ -72,13 +73,20 @@ export function useStacksTransactionSummary(token: CryptoCurrencies) {
};
}

function getSip10MemoDisplayText(payload: ContractCallPayload): string {
const noMemoText = 'No memo';
if (!isDefined(payload.functionArgs[3])) {
return noMemoText;
}
const isSome = payload.functionArgs[3].type === ClarityType.OptionalSome;
return isSome ? bytesToUtf8(serializeCV(payload.functionArgs[3])) : noMemoText;
}

function formSip10TxSummary(tx: StacksTransaction, symbol: string, decimals = 6) {
const payload = tx.payload as ContractCallPayload;
const fee = tx.auth.spendingCondition.fee;
const txValue = Number((payload.functionArgs[0] as IntCV).value);
const isSome = payload.functionArgs[3].type === ClarityType.OptionalSome;
const memo = bytesToUtf8(serializeCV(payload.functionArgs[3]));
const memoDisplayText = isSome ? memo : 'No memo';
const memoDisplayText = getSip10MemoDisplayText(payload);

const sendingValue = formatMoney(
convertToMoneyTypeWithDefaultOfZero(symbol, txValue, decimals)
Expand Down
9 changes: 5 additions & 4 deletions src/app/query/bitcoin/runes/runes-ticker-info.query.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { useQueries } from '@tanstack/react-query';

import { useConfigRunesEnabled } from '@app/query/common/remote-config/remote-config.query';
import { isDefined } from '@shared/utils';

import { useBitcoinClient } from '@app/store/common/api-clients.hooks';
import { useCurrentNetwork } from '@app/store/networks/networks.selectors';

import type { RuneBalance, RuneTickerInfo } from '../bitcoin-client';
import { useRunesEnabled } from './runes.hooks';
import { createRuneCryptoAssetDetails } from './runes.utils';

const queryOptions = { staleTime: 5 * 60 * 1000 };

export function useGetRunesTickerInfoQuery(runesBalances: RuneBalance[]) {
const client = useBitcoinClient();
const network = useCurrentNetwork();
const runesEnabled = useConfigRunesEnabled();
const runesEnabled = useRunesEnabled();

return useQueries({
queries: runesBalances.map(runeBalance => {
return {
enabled:
!runeBalance && (network.chain.bitcoin.bitcoinNetwork === 'testnet' || runesEnabled),
enabled: isDefined(runeBalance) && runesEnabled,
queryKey: ['runes-ticker-info', runeBalance.rune_name],
queryFn: () =>
client.bestinSlotApi.getRunesTickerInfo(
Expand Down
5 changes: 1 addition & 4 deletions src/app/store/transactions/token-transfer.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ export function useGenerateFtTokenTransferUnsignedTx(info: Sip10CryptoAssetInfo)
standardPrincipalCVFromAddress(recipient),
];

if (info.hasMemo) {
functionArgs.push(memo);
}
functionArgs.push(memo);

const options = {
txData: {
Expand Down Expand Up @@ -149,7 +147,6 @@ export function useGenerateFtTokenTransferUnsignedTx(info: Sip10CryptoAssetInfo)
[
account,
info.decimals,
info.hasMemo,
network,
nextNonce?.nonce,
contractName,
Expand Down
Loading