Skip to content

Commit

Permalink
migrate examples to not use top-level JSON values
Browse files Browse the repository at this point in the history
  • Loading branch information
itegulov committed Dec 2, 2022
1 parent 7aeede7 commit a53a588
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 5 additions & 3 deletions examples/src/standard-nft/test-approval-receiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
PromiseOrValue,
assert,
call,
bytes,
serialize,
} from "near-sdk-js";
import { AccountId } from "near-sdk-js";
import { NonFungibleTokenApprovalReceiver } from "near-contract-standards/lib/non_fungible_token/approval/approval_receiver";
Expand All @@ -15,7 +17,7 @@ const PROMISE_CALL = 20_000_000_000_000n;
const GAS_FOR_NFT_ON_APPROVE = BASE_GAS + PROMISE_CALL;

interface ValueReturnInterface {
ok_go(msg: string): PromiseOrValue<string>;
ok_go({ msg }: { msg: string }): PromiseOrValue<string>;
}

@NearBindgen({ requireInit: true })
Expand Down Expand Up @@ -56,7 +58,7 @@ export class ApprovalReceiver
const account_id = near.currentAccountId();
return NearPromise.new(account_id).functionCall(
"ok_go",
JSON.stringify(msg),
bytes(serialize({ msg })),
0n,
prepaid_gas - GAS_FOR_NFT_ON_APPROVE
);
Expand All @@ -65,7 +67,7 @@ export class ApprovalReceiver
}

@call({})
ok_go(msg: string): PromiseOrValue<string> {
ok_go({ msg }: { msg: string }): PromiseOrValue<string> {
near.log(`in ok_go, msg=${msg}`);
return msg;
}
Expand Down
10 changes: 6 additions & 4 deletions examples/src/standard-nft/test-token-receiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
NearBindgen,
NearPromise,
PromiseOrValue,
bytes,
serialize,
} from "near-sdk-js";
import { AccountId } from "near-sdk-js";

Expand All @@ -15,7 +17,7 @@ const PROMISE_CALL = 10_000_000_000_000n;
const GAS_FOR_NFT_ON_TRANSFER = BASE_GAS + PROMISE_CALL;

interface ValueReturnInterface {
ok_go(return_it: boolean): PromiseOrValue<boolean>;
ok_go({ return_it }: { return_it: boolean }): PromiseOrValue<boolean>;
}

@NearBindgen({ requireInit: true })
Expand Down Expand Up @@ -64,7 +66,7 @@ export class TokenReceiver
const account_id = near.currentAccountId();
return NearPromise.new(account_id).functionCall(
"ok_go",
JSON.stringify(true),
bytes(serialize({ return_it: true })),
0n,
prepaid_gas - GAS_FOR_NFT_ON_TRANSFER
);
Expand All @@ -76,7 +78,7 @@ export class TokenReceiver
const account_id = near.currentAccountId();
return NearPromise.new(account_id).functionCall(
"ok_go",
JSON.stringify(false),
bytes(serialize({ return_it: false })),
0n,
prepaid_gas - GAS_FOR_NFT_ON_TRANSFER
);
Expand All @@ -87,7 +89,7 @@ export class TokenReceiver
}

@call({})
ok_go(return_it: boolean): PromiseOrValue<boolean> {
ok_go({ return_it }: { return_it: boolean }): PromiseOrValue<boolean> {
near.log(`in ok_go, return_it=${return_it}`);
return return_it;
}
Expand Down

0 comments on commit a53a588

Please sign in to comment.