Skip to content

Commit

Permalink
Contract V3 added
Browse files Browse the repository at this point in the history
  • Loading branch information
AtanasKrondev committed Dec 15, 2020
1 parent 275df39 commit 295a3ac
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 42 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ VUE_APP_EXPLORER_URL=https://mainnet.aeternal.io
VUE_APP_COMPILER_URL=https://latest.compiler.aepps.com
VUE_APP_CONTRACT_V1_ADDRESS=ct_2AfnEfCSZCTEkxL5Yoi4Yfq6fF7YapHRaFKDJK3THMXMBspp5z
VUE_APP_CONTRACT_V2_ADDRESS=
VUE_APP_CONTRACT_V3_ADDRESS=ct_2Hyt9ZxzXra5NAzhePkRsDPDWppoatVD7CtHnUoHVbuehwR8Nb
VUE_APP_IMGUR_API_CLIENT_ID=eafea0a779e4039
VUE_APP_GIPHY_API_KEY=P16yBDlSeEfcrJfp1rwnamtEZmQHxHNM
3 changes: 2 additions & 1 deletion .env.e2e
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
VUE_APP_BACKEND_URL=https://test-tipping.aeternity.art
VUE_APP_BACKEND_URL=https://testnet.superhero.aeternity.art
VUE_APP_NODE_URL=https://testnet.aeternity.io
VUE_APP_EXPLORER_URL=https://testnet.aeternal.io
VUE_APP_CONTRACT_V1_ADDRESS=ct_2GRP3xp7KWrKtZSnYfdcLnreRWrntWf5aTsxtLqpBHp71EFc3i
VUE_APP_CONTRACT_V2_ADDRESS=
VUE_APP_CONTRACT_V3_ADDRESS=ct_WscpdLQf6ZZxoVqrsEwUwmuAEdzEkJii5W5TzG84rVgHeK6BW
34 changes: 4 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 25 additions & 11 deletions src/utils/aeternity.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* globals Cypress */
import {
MemoryAccount, Node, Universal, RpcAepp,
MemoryAccount, Node, Universal, RpcAepp, Crypto,
} from '@aeternity/aepp-sdk/es';
import Detector from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/wallet-detector';
import BrowserWindowMessageConnection from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-window-message';
import TIPPING_V1_INTERFACE from 'tipping-contract/Tipping_v1_Interface.aes';
import TIPPING_V2_INTERFACE from 'tipping-contract/Tipping_v2_Interface.aes';
import TIPPING_V3_INTERFACE from 'tipping-contract/Tipping_v3_Interface.aes';
import tippingContractUtil from 'tipping-contract/util/tippingContractUtil';
import FUNGIBLE_TOKEN_CONTRACT from 'aeternity-fungible-token/FungibleTokenFullInterface.aes';
import { BigNumber } from 'bignumber.js';
import store from '../store';
Expand All @@ -14,19 +16,20 @@ import { IS_MOBILE_DEVICE } from './index';
let sdk;
let contractV1;
let contractV2;
let contractV3;
let isTippingContractsInitialised;

const initTippingContractIfNeeded = async () => {
if (!sdk) throw new Error('Init sdk first');
if (!contractV1) {
contractV1 = await sdk.getContractInstance(TIPPING_V1_INTERFACE, {
contractAddress: process.env.VUE_APP_CONTRACT_V1_ADDRESS,
});
}
if (!contractV2 && process.env.VUE_APP_CONTRACT_V2_ADDRESS) {
contractV2 = await sdk.getContractInstance(TIPPING_V2_INTERFACE, {
contractAddress: process.env.VUE_APP_CONTRACT_V2_ADDRESS,
});
}
if (isTippingContractsInitialised) return;
[contractV1, contractV2, contractV3] = await Promise.all([
[TIPPING_V1_INTERFACE, process.env.VUE_APP_CONTRACT_V1_ADDRESS],
[TIPPING_V2_INTERFACE, process.env.VUE_APP_CONTRACT_V2_ADDRESS],
[TIPPING_V3_INTERFACE, process.env.VUE_APP_CONTRACT_V3_ADDRESS],
].map(([tippingInterface, contractAddress]) => (contractAddress
? sdk.getContractInstance(tippingInterface, { contractAddress })
: null)));
isTippingContractsInitialised = true;
};

/**
Expand Down Expand Up @@ -143,3 +146,14 @@ export const retip = async (contractAddress, id, amount, tokenAddress = null) =>

return null;
};

export const postWithoutTip = async (title, media) => {
await initTippingContractIfNeeded();
return contractV3.methods.post_without_tip(title, media);
};

export const postWithoutTipSignature = async (title, media) => {
const message = tippingContractUtil.postWithoutTippingString(title, media);
const hash = Crypto.hash(message);
return sdk.signMessage(hash, { returnHex: true });
};

0 comments on commit 295a3ac

Please sign in to comment.