Skip to content

Commit

Permalink
fix: applies feedback & upgrades dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
kenodressel committed May 8, 2024
1 parent fd2204a commit 0514889
Show file tree
Hide file tree
Showing 7 changed files with 293 additions and 424 deletions.
490 changes: 223 additions & 267 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"normalize.css": "^8.0.1",
"serve-static": "^1.14.1",
"smart-app-banner": "^2.0.0",
"sophia-bonding-curve": "git+https://[email protected]/aeternity/BondingCurve#1.0.0-alpha.2",
"sophia-bonding-curve": "git+https://[email protected]/aeternity/BondingCurve#1.0.0-alpha.3",
"soundcloud-widget": "^0.2.1",
"tipping-contract": "git+https://[email protected]/aeternity/tipping-contract#v5.0.0-alpha2",
"vue": "^2.6.14",
Expand All @@ -61,7 +61,7 @@
"vue-timeago": "^5.1.3",
"vuex": "^3.6.2",
"vuex-router-sync": "^5.0.0",
"wordbazaar-contracts": "git+https://[email protected]/aeternity/wordbazaar-contracts#v0.0.4-alpha3"
"wordbazaar-contracts": "git+https://[email protected]/aeternity/wordbazaar-contracts#v0.0.4-alpha4"
},
"repository": {
"type": "git",
Expand Down
1 change: 0 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ export default {
let { address } = this.$route.query;
if (!address) {
address = await this.$store.dispatch('aeternity/scanForWallets');
console.log('found wallet');
this.useSdkWallet();
this.setAddress(address);
this.$store.dispatch('updateCookiesConsent');
Expand Down
5 changes: 1 addition & 4 deletions src/components/UserInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,7 @@ export default {
}),
(async () => {
await this.$watchUntilTruly(() => this.sdk);
this.balance = await this.sdk.getBalance(this.address).catch((error) => {
if (error.status !== 404) throw error;
return 0;
});
this.balance = await this.sdk.getBalance(this.address);
})(),
]);
this.loading = false;
Expand Down
5 changes: 1 addition & 4 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ export default () => new Vuex.Store({
dispatch('updatePinnedItems'),
dispatch('updateUserProfile'),
(async () => {
const balance = await sdk.getBalance(address).catch((error) => {
if (error.status !== 404) throw error;
return 0;
});
const balance = await sdk.getBalance(address);
commit('updateBalance', balance);
})(),
dispatch('updateTokensBalanceAndPrice'),
Expand Down
183 changes: 66 additions & 117 deletions src/store/modules/aeternity.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@ import TIPPING_V2_ACI from 'tipping-contract/generated/Tipping_v2.aci.json';
import TIPPING_V3_ACI from 'tipping-contract/generated/Tipping_v3.aci.json';
import tippingContractUtil from 'tipping-contract/util/tippingContractUtil';
import FUNGIBLE_TOKEN_ACI from 'aeternity-fungible-token/generated/FungibleTokenFull.aci.json';
import FUNGIBLE_TOKEN_CONTRACT from 'aeternity-fungible-token/FungibleTokenFull.aes';
import WORD_REGISTRY_ACI from 'wordbazaar-contracts/generated/WordRegistry.aci.json';
import TOKEN_VOTING_ACI from 'wordbazaar-contracts/generated/TokenVoting.aci.json';
import TOKEN_SALE_ACI from 'wordbazaar-contracts/generated/TokenSale.aci.json';
import TOKEN_SALE_CONTRACT from 'wordbazaar-contracts/generated/TokenSale.aes';
import TOKEN_VOTING_CONTRACT from 'wordbazaar-contracts/generated/TokenVoting.aes';
import BONDING_CURVE from 'sophia-bonding-curve/generated/BondCurveLinear.aes';

import { BigNumber } from 'bignumber.js';
import { shiftDecimalPlaces } from '../../utils';

export default {
namespaced: true,
state: {
sdk: null,
useSdkWallet: false,
useIframeWallet: false,
wordRegistryContract: null,
fungibleTokenContracts: {},
tokenVotingContracts: {},
tokenSaleContracts: {},
},
mutations: {
setSdk(state, { instance }) {
Expand All @@ -38,18 +42,6 @@ export default {
enableIframeWallet(state) {
state.useIframeWallet = true;
},
setFungibleTokenContract(state, contractAddress, instance) {
state.fungibleTokenContracts[contractAddress] = instance;
},
setTokenVotingContract(state, contractAddress, instance) {
state.tokenVotingContracts[contractAddress] = instance;
},
setTokenSaleContract(state, contractAddress, instance) {
state.tokenSaleContracts[contractAddress] = instance;
},
setWordRegistryContract(state, instance) {
state.wordRegistryContract = instance;
},
},
actions: {
async initTippingContract({
Expand Down Expand Up @@ -81,7 +73,7 @@ export default {
new MemoryAccount(Cypress.env('privateKey')),
],
});
instance.subscribeAddress = async () => ({ address: { current: { [Cypress.env('publicKey')]: 'subscribed' } } });
instance.addresses = () => ([Cypress.env('publicKey')]);
commit('setSdk', { instance });
} else {
const instance = new AeSdkAepp({
Expand Down Expand Up @@ -111,12 +103,10 @@ export default {

async function handleNewWallet({ newWallet }) {
try {
if (!newWallet) return null;
clearInterval(webWalletTimeout);
await sdk.connectToWallet(await newWallet.getConnection());
const ret = await sdk.subscribeAddress('subscribe', 'current');
const { address: { current } } = ret;
const address = Object.keys(current)[0];
await sdk.subscribeAddress('subscribe', 'current');
const address = sdk.addresses()[0];
if (!address) return null;
if (stopScan) stopScan();
commit('setAddress', address, { root: true });
Expand All @@ -126,11 +116,10 @@ export default {
return rejected(e);
}
}

console.log('Scanning for wallets...');

const scannerConnection = new BrowserWindowMessageConnection({
connectionInfo: { id: 'spy' },
});
const scannerConnection = new BrowserWindowMessageConnection();
stopScan = walletDetector(scannerConnection, handleNewWallet);

return new Promise((_resolve, _rejected) => {
Expand All @@ -141,81 +130,50 @@ export default {
async getHeight({ state: { sdk } }) {
return sdk.getHeight();
},
async initFungibleTokenContractIfNeeded(
{ commit, state: { sdk, fungibleTokenContracts } },
async initFungibleTokenContract(
{ commit, state: { sdk } },
contractAddress,
) {
if (!fungibleTokenContracts[contractAddress]) {
const contract = await sdk
.initializeContract({
aci: FUNGIBLE_TOKEN_ACI,
address: contractAddress,
});
commit('setFungibleTokenContract', contractAddress, contract);
return contract;
}

return fungibleTokenContracts[contractAddress];
return sdk
.initializeContract({
aci: FUNGIBLE_TOKEN_ACI,
address: contractAddress,
});
},
async initWordRegistryContractIfNeeded({ commit, state: { sdk, wordRegistryContract } }) {
// FIXME implement wordbazaar contracts
throw new Error('Wordbazaar contracts are not implemented yet');
// if (!wordRegistryContract) {
// const contract = await sdk.initializeContract({
// aci: WORD_REGISTRY_CONTRACT,
// address: process.env.VUE_APP_WORD_REGISTRY_ADDRESS,
// });
// commit('setWordRegistryContract', contract);
// return contract;
// }
//
// return wordRegistryContract;
async initWordRegistryContract({ commit, state: { sdk } }) {
return sdk.initializeContract({
aci: WORD_REGISTRY_ACI,
address: process.env.VUE_APP_WORD_REGISTRY_ADDRESS,
});
},
async initTokenVotingContractIfNeeded(
{ commit, state: { sdk, tokenVotingContracts } },
async initTokenVotingContract(
{ commit, state: { sdk } },
contractAddress,
) {
// FIXME implement wordbazaar contracts
throw new Error('Wordbazaar contracts are not implemented yet');
// if (!tokenVotingContracts[contractAddress]) {
// const contract = await sdk.initializeContract({
// aci: TOKEN_VOTING_CONTRACT,
// address: contractAddress,
// });
// commit('setTokenVotingContract', contractAddress, contract);
// return contract;
// }
//
// return tokenVotingContracts[contractAddress];
return sdk.initializeContract({
aci: TOKEN_VOTING_ACI,
address: contractAddress,
});
},
async initTokenSaleContractIfNeeded(
{ commit, state: { sdk, tokenSaleContracts } },
async initTokenSaleContract(
{ commit, state: { sdk } },
contractAddress,
) {
// FIXME implement wordbazaar contracts
throw new Error('Wordbazaar contracts are not implemented yet');
// if (!tokenSaleContracts[contractAddress]) {
// const contract = await sdk.initializeContract({
// aci: TOKEN_SALE_CONTRACT,
// address: contractAddress,
// });
// commit('setTokenSaleContract', contractAddress, contract);
// return contract;
// }
// return tokenSaleContracts[contractAddress];
return sdk.initializeContract({
aci: TOKEN_SALE_ACI,
address: contractAddress,
});
},
async deployBondingCurve({ state: { sdk } }, decimals) {
// FIXME implement wordbazaar contracts
throw new Error('Wordbazaar contracts are not implemented yet'); // alters bonding curve contract to change the dependency default 1 alpha to 18
// as we use 18 decimals and thus need to adjust the curve to match that
// const BONDING_CURVE_DECIMALS = BONDING_CURVE.replace(
// 'function alpha() : Frac.frac = Frac.make_frac(1, 1)',
// `function alpha() : Frac.frac = Frac.make_frac(1, ${shiftDecimalPlaces(1, decimals)})`,
// );
// const contract = await sdk.getContractInstance(BONDING_CURVE_DECIMALS);
// await contract.init();
//
// return contract.deployInfo.address;
const BONDING_CURVE_DECIMALS = BONDING_CURVE.replace(
'function alpha() : Frac.frac = Frac.make_frac(1, 1)',
`function alpha() : Frac.frac = Frac.make_frac(1, ${shiftDecimalPlaces(1, decimals)})`,
);
const contract = await sdk.initializeContract({ sourceCode: BONDING_CURVE_DECIMALS });
await contract.init();

return contract.$options.address;
},
async deployTokenSaleContract(
{ commit, state: { sdk } },
Expand All @@ -226,19 +184,16 @@ export default {
description,
},
) {
// FIXME implement wordbazaar contracts
throw new Error('Wordbazaar contracts are not implemented yet');
// alters token sale contract to change the dependency default 1 decimals to 18
// as we want that as default for use with wordbazaar
// const TOKEN_SALE_CONTRACT_DECIMALS = TOKEN_SALE_CONTRACT.replace(
// 'let decimals = 1',
// `let decimals = ${shiftDecimalPlaces(1, decimals)}`,
// );
//
// const contract = await sdk.getContractInstance(TOKEN_SALE_CONTRACT_DECIMALS);
// await contract.init(timeout, bondingCurveAddress, description);
// commit('setTokenSaleContract', contract.deployInfo.address, contract);
// return contract.deployInfo.address;
const TOKEN_SALE_CONTRACT_DECIMALS = TOKEN_SALE_CONTRACT.replace(
'let decimals = 1',
`let decimals = ${shiftDecimalPlaces(1, decimals)}`,
);

const contract = await sdk.initializeContract({ sourceCode: TOKEN_SALE_CONTRACT_DECIMALS });
await contract.init(timeout, bondingCurveAddress, description);
return contract.$options.address;
},
async deployFungibleTokenContract(
{ commit, state: { sdk } },
Expand All @@ -249,13 +204,10 @@ export default {
tokenSaleAddress,
},
) {
// FIXME implement wordbazaar contracts
throw new Error('Wordbazaar contracts are not implemented yet');
// const contract = await sdk.getContractInstance(FUNGIBLE_TOKEN_CONTRACT);
// await contract
// .init(name, decimals, symbol, tokenSaleAddress, process.env.VUE_APP_WORD_REGISTRY_ADDRESS);
// commit('setFungibleTokenContract', contract.deployInfo.address, contract);
// return contract.deployInfo.address;
const contract = await sdk.initializeContract({ sourceCode: FUNGIBLE_TOKEN_CONTRACT });
await contract
.init(name, decimals, symbol, tokenSaleAddress, process.env.VUE_APP_WORD_REGISTRY_ADDRESS);
return contract.$options.address;
},
async deployTokenVotingContract(
{ commit, state: { sdk } },
Expand All @@ -265,15 +217,12 @@ export default {
token,
},
) {
// FIXME implement wordbazaar contracts
throw new Error('Wordbazaar contracts are not implemented yet');
// const contract = await sdk.getContractInstance(TOKEN_VOTING_CONTRACT);
// await contract.init(metadata, closeHeight, token);
// commit('setTokenVotingContract', contract.deployInfo.address, contract);
// return contract.deployInfo.address;
const contract = await sdk.initializeContract({ sourceCode: TOKEN_VOTING_CONTRACT });
await contract.init(metadata, closeHeight, token);
return contract.$options.address;
},
async wordRegistryAddToken({ dispatch }, addTokenAddress) {
const contract = await dispatch('initWordRegistryContractIfNeeded');
const contract = await dispatch('initWordRegistryContract');

const { decodedResult } = await contract.add_token(addTokenAddress);
return decodedResult;
Expand All @@ -287,7 +236,7 @@ export default {
options = {},
},
) {
const contract = await dispatch('initTokenSaleContractIfNeeded', contractAddress);
const contract = await dispatch('initTokenSaleContract', contractAddress);

const { decodedResult } = await contract[method](...args, options);
return decodedResult;
Expand All @@ -301,19 +250,19 @@ export default {
options = {},
},
) {
const contract = await dispatch('initTokenVotingContractIfNeeded', contractAddress);
const contract = await dispatch('initTokenVotingContract', contractAddress);

const { decodedResult } = await contract[method](...args, options);
return decodedResult;
},
async tokenBalance({ dispatch }, { contractAddress, address }) {
const contract = await dispatch('initFungibleTokenContractIfNeeded', contractAddress);
const contract = await dispatch('initFungibleTokenContract', contractAddress);

const { decodedResult } = await contract.balance(address);
return new BigNumber(decodedResult || 0).toFixed();
},
async tokenTotalSupply({ dispatch }, contractAddress) {
const contract = await dispatch('initFungibleTokenContractIfNeeded', contractAddress);
const contract = await dispatch('initFungibleTokenContract', contractAddress);

const { decodedResult } = await contract.total_supply();
return new BigNumber(decodedResult || 0).toFixed();
Expand All @@ -322,7 +271,7 @@ export default {
{ dispatch, state: { sdk } },
{ contractAddress, amount, forAccount = null },
) {
const contract = await dispatch('initFungibleTokenContractIfNeeded', contractAddress);
const contract = await dispatch('initFungibleTokenContract', contractAddress);

const { decodedResult } = await contract.allowance({
from_account: sdk.address,
Expand Down
29 changes: 0 additions & 29 deletions vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,35 +111,6 @@ module.exports = {
.loader('svgo-loader')
.end();

/*
{
test: /@swagger-api\/apidom-.*\.[mc]?js$/,
include: /node_modules/,
loader: 'babel-loader',
options: {
plugins: [
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-logical-assignment-operators',
],
...defaultJsOptions,
},
},
*/
config.module
.rule('babel-loader-for-apidom')
.test(/@swagger-api\/apidom-.*\.[mc]?js$/)
.include
.add(/node_modules/)
.end()
.use('babel-loader')
.loader('babel-loader')
.options({
plugins: [
'@babel/plugin-transform-class-properties',
'@babel/plugin-transform-logical-assignment-operators',
],
});

return config;
},
};

0 comments on commit 0514889

Please sign in to comment.