Skip to content

Commit

Permalink
Merge pull request #832 from aeternity/feature/fungible-token-feature…
Browse files Browse the repository at this point in the history
…flagged

fungible token featureflagged via existence of v2 contract
  • Loading branch information
mradkov authored Oct 13, 2020
2 parents 296a5da + 2c24a2a commit 29f914b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 43 deletions.
18 changes: 0 additions & 18 deletions package-lock.json

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

29 changes: 20 additions & 9 deletions src/components/AeInputAmount.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@input="$emit('input', $event.target.value)"
>
<div
v-if="!notTokenTipable"
v-if="tokenTipable"
class="input-group-append"
>
<Dropdown
Expand All @@ -32,8 +32,13 @@
class="input-group-text append__ae text-ellipsis"
:title="value"
>
<!--eslint-disable-next-line vue-i18n/no-raw-text-->
<span class="ae">AE</span>&nbsp;
<!-- eslint-disable vue-i18n/no-raw-text -->
<span
v-if="!tokenTipable"
class="ae"
>
AE
</span>&nbsp;
<FiatValue
display-symbol
:amount="value.toString()"
Expand All @@ -45,6 +50,7 @@

<script>
import { mapState } from 'vuex';
import { hasV2ContractAddress } from '@/utils/aeternity';
import FiatValue from './FiatValue.vue';
import Dropdown from './Dropdown.vue';
Expand All @@ -63,12 +69,17 @@ export default {
data: () => ({
selectedToken: 'native',
}),
computed: mapState({
selectTokenOptions: ({ tokenBalances, tokenInfo }) => [
{ text: 'AE', value: 'native' },
...tokenBalances.map(({ token }) => ({ text: tokenInfo[token].symbol, value: token })),
],
}),
computed: {
...mapState({
selectTokenOptions: ({ tokenBalances, tokenInfo }) => [
{ text: 'AE', value: 'native' },
...tokenBalances.map(({ token }) => ({ text: tokenInfo[token].symbol, value: token })),
],
}),
tokenTipable() {
return !this.notTokenTipable && hasV2ContractAddress();
},
},
methods: {
selectToken(selected) {
this.selectedToken = selected;
Expand Down
22 changes: 14 additions & 8 deletions src/components/layout/RightSectionWallet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,23 @@
/>
</div>

<AeAmount
v-for="tokenBalance in tokenBalances"
:key="tokenBalance.token"
class="not-bootstrap-row"
:amount="tokenBalance.balance"
:token="tokenBalance.token"
/>
<div v-if="hasV2ContractAddress()">
<AeAmount
v-for="tokenBalance in tokenBalances"
:key="tokenBalance.token"
class="not-bootstrap-row"
:amount="tokenBalance.balance"
:token="tokenBalance.token"
/>
</div>
</template>
</div>
</template>

<script>
import { mapState, mapMutations, mapGetters } from 'vuex';
import BigNumber from 'bignumber.js';
import { hasV2ContractAddress } from '@/utils/aeternity';
import AeAmount from '../AeAmount.vue';
import Dropdown from '../Dropdown.vue';
import RightSectionTitle from './RightSectionTitle.vue';
Expand All @@ -70,7 +73,10 @@ export default {
},
}),
},
methods: mapMutations(['updateCurrency']),
methods: {
...mapMutations(['updateCurrency']),
hasV2ContractAddress() { return hasV2ContractAddress(); },
},
};
</script>

Expand Down
10 changes: 6 additions & 4 deletions src/config/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export const BACKEND_URL = typeof Cypress !== 'undefined' ? 'https://testnet.superhero.aeternity.art' : 'https://test-tipping.aeternity.art';
export const MIDDLEWARE_URL = 'https://testnet.aeternity.io/';
export const BACKEND_URL = typeof Cypress !== 'undefined'
? 'https://testnet.superhero.aeternity.art'
: 'https://test-tipping.aeternity.art';

export const EXPLORER_URL = 'https://testnet.aeternal.io/';
export const COMPILER_URL = 'https://latest.compiler.aepps.com';
export const NODE_URL = 'https://testnet.aeternity.io';
Expand All @@ -9,5 +11,5 @@ export const CONTRACT_V1_ADDRESS = window.Cypress
: 'ct_2Cvbf3NYZ5DLoaNYAU71t67DdXLHeSXhodkSNifhgd7Xsw28Xd';

export const CONTRACT_V2_ADDRESS = window.Cypress
? 'ct_2GRP3xp7KWrKtZSnYfdcLnreRWrntWf5aTsxtLqpBHp71EFc3i'
: 'ct_2ZEoCKcqXkbz2uahRrsWeaPooZs9SdCv6pmC4kc55rD4MhqYSu';
? null
: null;
14 changes: 10 additions & 4 deletions src/utils/aeternity.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@ import FUNGIBLE_TOKEN_CONTRACT from 'aeternity-fungible-token/FungibleTokenFullI
import { BigNumber } from 'bignumber.js';
import { EventBus } from './eventBus';
import store from '../store';
import { IS_MOBILE_DEVICE } from './util';

let contractV1;
let contractV2;

export let client; // eslint-disable-line import/no-mutable-exports

export const hasV2ContractAddress = () => CONTRACT_V2_ADDRESS !== null;

const initTippingContractIfNeeded = async () => {
if (!client) throw new Error('Init sdk first');
if (!contractV1) {
contractV1 = await client
.getContractInstance(TIPPING_V1_INTERFACE, { contractAddress: CONTRACT_V1_ADDRESS });
}
if (!contractV2) {
if (!contractV2 && hasV2ContractAddress()) {
contractV2 = await client
.getContractInstance(TIPPING_V2_INTERFACE, { contractAddress: CONTRACT_V2_ADDRESS });
}
Expand Down Expand Up @@ -79,11 +82,12 @@ export const scanForWallets = async () => {
connectionInfo: { id: 'spy' },
});
const detector = await Detector({ connection: scannerConnection });
// const webWalletTimeout = setTimeout(() => store.commit('useIframeWallet'), 2000);
const webWalletTimeout = setTimeout(() => !IS_MOBILE_DEVICE && store.commit('useIframeWallet'), 2000);

return new Promise((resolve) => {
detector.scan(async ({ newWallet }) => {
if (!newWallet) return;
// clearInterval(webWalletTimeout);
clearInterval(webWalletTimeout);
detector.stopScan();
await client.connectToWallet(await newWallet.getConnection());
await client.subscribeAddress('subscribe', 'current');
Expand Down Expand Up @@ -129,7 +133,9 @@ export const tip = async (url, title, amount, tokenAddress = null) => {
return contractV2.methods.tip_token(url, title, tokenAddress, amount);
}

return contractV2.methods.tip(url, title, { amount });
return hasV2ContractAddress()
? contractV2.methods.tip(url, title, { amount })
: contractV1.methods.tip(url, title, { amount });
};

export const retip = async (contractAddress, id, amount, tokenAddress = null) => {
Expand Down

1 comment on commit 29f914b

@mradkov
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.