Skip to content

Commit

Permalink
Merge pull request #5450 from leather-wallet/fix/sip10-memo
Browse files Browse the repository at this point in the history
hotfix: sip10 memo and rune balances
  • Loading branch information
fbwoolf authored May 24, 2024
2 parents 271875f + 9a8d965 commit a6528a6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
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

0 comments on commit a6528a6

Please sign in to comment.