Skip to content

Commit

Permalink
Support more Getgems methods
Browse files Browse the repository at this point in the history
  • Loading branch information
voloshinskii committed May 21, 2024
1 parent a310f6f commit 6f35a5d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
2 changes: 2 additions & 0 deletions packages/@core-js/src/service/contractService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export enum OpCodes {
JETTON_TRANSFER = 0xf8a7ea5,
NFT_TRANSFER = 0x5fcc3d14,
STONFI_SWAP = 0x25938561,
PUT_ON_SALE = 0x00000001,
REMOVE_FROM_SALE = 0x00000003,
}

export enum WalletVersion {
Expand Down
27 changes: 21 additions & 6 deletions packages/@core-js/src/service/transactionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export interface TransferParams {
messages: MessageRelaxed[];
}

export const ALLOWED_BATTERY_DOMAINS = ['getgems.io'];

export function tonAddress(address: AnyAddress) {
if (typeof address === 'string') {
return Address.parse(address);
Expand Down Expand Up @@ -111,24 +113,37 @@ export class TransactionService {
supportedTransactions: Record<BatterySupportedTransaction, boolean>,
) {
const slice = payload.beginParse();
if (slice.remainingBits < 32) {
return true;
}
const opCode = slice.loadUint(32);

switch (opCode) {
case OpCodes.PUT_ON_SALE:
return supportedTransactions[BatterySupportedTransaction.NFTSale];
case OpCodes.REMOVE_FROM_SALE:
return supportedTransactions[BatterySupportedTransaction.NFTSale];
case OpCodes.STONFI_SWAP:
return supportedTransactions[BatterySupportedTransaction.Swap];
case OpCodes.NFT_TRANSFER:
if (slice.remainingRefs) {
return TransactionService.shouldRelayPayload(
slice.loadRef(),
supportedTransactions,
const refsArr = new Array(slice.remainingRefs);
while (slice.remainingRefs) {
refsArr.push(slice.loadRef());
}
return refsArr.every((ref) =>
TransactionService.shouldRelayPayload(ref, supportedTransactions),
);
}
return supportedTransactions[BatterySupportedTransaction.NFT];
case OpCodes.JETTON_TRANSFER:
if (slice.remainingRefs) {
return TransactionService.shouldRelayPayload(
slice.loadRef(),
supportedTransactions,
const refsArr = new Array(slice.remainingRefs);
while (slice.remainingRefs) {
refsArr.push(slice.loadRef());
}
return refsArr.every((ref) =>
TransactionService.shouldRelayPayload(ref, supportedTransactions),
);
}
return supportedTransactions[BatterySupportedTransaction.Jetton];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,18 @@ export const openSignRawModal = async (
await TonConnectRemoteBridge.closeOtherTransactions();
}

let shouldRelayTransaction: boolean = false;
try {
shouldRelayTransaction = options.experimentalWithBattery
? TransactionService.shouldRelayPayloads(
params.messages
.map((message) => message.payload)
.filter((message) => !!message) as string[],
tk.wallet.battery.state.data.supportedTransactions,
)
: false;
} catch {}

let consequences: MessageConsequences | null = null;
let isBattery = false;
try {
Expand All @@ -393,15 +405,6 @@ export const openSignRawModal = async (
seqno: await getWalletSeqno(wallet),
});

const shouldRelayTransaction = options.experimentalWithBattery
? TransactionService.shouldRelayPayloads(
params.messages
.map((message) => message.payload)
.filter((message) => !!message) as string[],
tk.wallet.battery.state.data.supportedTransactions,
)
: false;

const totalAmount = calculateMessageTransferAmount(params.messages);
const { emulateResult, battery } = await emulateBoc(
boc,
Expand Down
7 changes: 6 additions & 1 deletion packages/mobile/src/tonconnect/TonConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { tk } from '$wallet';
import { TonConnectRemoteBridge } from './TonConnectRemoteBridge';
import { WithWalletIdentifier } from '$wallet/WalletTypes';
import { getDomainFromURL } from '$utils';
import { ALLOWED_BATTERY_DOMAINS } from '@tonkeeper/core';

class TonConnectService {
checkProtocolVersionCapability(protocolVersion: number) {
Expand Down Expand Up @@ -310,6 +311,10 @@ class TonConnectService {
);
}

const isBatteryEnabled = ALLOWED_BATTERY_DOMAINS.includes(
getDomainFromURL(senderUrl),
);

const { valid_until, messages } = params;

if (valid_until < getTimeSec()) {
Expand All @@ -332,7 +337,7 @@ class TonConnectService {
const openModalResult = await openSignRawModal(
txParams,
{
experimentalWithBattery: true,
experimentalWithBattery: isBatteryEnabled,
expires_sec: valid_until,
response_options: {
broadcast: false,
Expand Down

0 comments on commit 6f35a5d

Please sign in to comment.