Skip to content

Commit

Permalink
fix: Use nft_buy instead of nft_mint, and double price to cover storage
Browse files Browse the repository at this point in the history
  • Loading branch information
johnedvard committed Sep 10, 2022
1 parent d966006 commit a6c8832
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/gameEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export const RESTART_LEVEL = 'r';
export const START_NEXT_LEVEL = 'snl';
export const ARCADIAN_HEAD_SELECTED = 'ahs';
export const NEAR_TOKENS_ADDED = 'n';
export const NFT_MINT = 'nm';
export const NFT_BUY = 'nb';
export const MONETIZATION_PROGRESS = 'mp';
export const PLAYER_DIED = 'pd';
9 changes: 5 additions & 4 deletions src/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
LEVEL_COMPLETE,
MONETIZATION_PROGRESS,
NEAR_TOKENS_ADDED,
NFT_MINT,
NFT_BUY,
RESTART_LEVEL,
START_LEVEL,
START_NEXT_LEVEL,
Expand Down Expand Up @@ -82,7 +82,8 @@ const initNearLevels = ({
levelEl.setAttribute('disabled', !ownsNft);
}
levelEl.setAttribute('token-series-id', collection.token_series_id);
levelEl.setAttribute('price', collection.price);
// TODO (johnedvard) figure out how to use actual prize and pay for storage instead of hardcoding 1N (actual price is 0.5N)
levelEl.setAttribute('price', '1000000000000000000000000');
levelEl.textContent = collection.metadata.title;
levelEl.appendChild(imgEl);
const mintForPriceEl = document.createElement('span');
Expand Down Expand Up @@ -184,7 +185,7 @@ const onContainerClick = (e) => {
const btn = e.target.closest('button');
if (btn && btn.getAttribute('near')) {
onNearLevelClick(btn);
} else if (btn.classList.contains('level-item')) {
} else if (btn && btn.classList.contains('level-item')) {
showOverlay();
emit(START_LEVEL, { levelId: +btn.textContent });
}
Expand All @@ -195,7 +196,7 @@ const onNearLevelClick = (btn) => {
showLoading();
const token_series_id = btn.getAttribute('token-series-id');
const priceInYoctoNear = btn.getAttribute('price');
emit(NFT_MINT, { token_series_id, priceInYoctoNear });
emit(NFT_BUY, { token_series_id, priceInYoctoNear });
} else {
showOverlay();
emit(START_LEVEL, {
Expand Down
12 changes: 6 additions & 6 deletions src/near/nearConnection.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { on } from '../kontra';
import { NFT_MINT } from '../gameEvents';
import { NFT_BUY } from '../gameEvents';
import getConfig from './config';

export const HANG_BY_A_THREAD_SERIES_TESTNET = '2036';
Expand Down Expand Up @@ -47,7 +47,7 @@ export class NearConnection {
// View methods are read only. They don't modify the state, but usually return some value.
viewMethods: ['nft_tokens_for_owner', 'nft_tokens_by_series'],
// Change methods can modify the state. But you don't receive the returned value when called.
changeMethods: ['nft_mint'],
changeMethods: ['nft_buy'],
}
);
this.resolveContract();
Expand All @@ -73,8 +73,8 @@ export class NearConnection {
nft_tokens_by_series(token_series_id) {
return this.contract.nft_tokens_by_series({ token_series_id });
}
nft_mint({ token_series_id, priceInYoctoNear }) {
return this.contract.nft_mint(
nft_buy({ token_series_id, priceInYoctoNear }) {
return this.contract.nft_buy(
{
owner_id: this.accountId,
receiver_id: this.accountId,
Expand All @@ -94,8 +94,8 @@ export class NearConnection {
});
}
listenForGameEvents() {
on(NFT_MINT, ({ token_series_id, priceInYoctoNear }) =>
this.nft_mint({ token_series_id, priceInYoctoNear })
on(NFT_BUY, ({ token_series_id, priceInYoctoNear }) =>
this.nft_buy({ token_series_id, priceInYoctoNear })
);
}
}

0 comments on commit a6c8832

Please sign in to comment.