Skip to content

Commit

Permalink
Using anonnymus connection on the flyover instance
Browse files Browse the repository at this point in the history
		I've defined the provider parameter on the flyover instance depending
		on the option, for pegin it will use an annonymus wallet and for pegout
		the rlogin provider connected.
  • Loading branch information
ronaldsg20 committed Nov 21, 2024
1 parent a7db315 commit fe16c57
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
14 changes: 1 addition & 13 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<script lang="ts">
import {
computed, onBeforeMount, onMounted, ref,
computed, onBeforeMount, ref,
} from 'vue';
import Top from '@/common/components/layouts/Top.vue';
import FooterRsk from '@/common/components/layouts/Footer.vue';
Expand All @@ -39,7 +39,6 @@ export default {
let hotjarScriptTag: HTMLScriptElement;
const getFeatures = useAction('web3Session', constants.SESSION_ADD_FEATURES);
const getBtcPrice = useAction('pegInTx', constants.PEGIN_TX_ADD_BITCOIN_PRICE);
const initFlyover = useAction('flyoverPegin', constants.FLYOVER_PEGIN_INIT);
const showTermsAndConditions = ref(false);
const contentSecurityPolicy = computed((): string => {
const envVariables = EnvironmentAccessorService.getEnvironmentVariables();
Expand Down Expand Up @@ -100,17 +99,6 @@ export default {
getBtcPrice();
});
onMounted(() => {
console.log('App mounted trying to init flyover');
initFlyover()
.then(() => {
console.log('flyover init success');
})
.catch((error) => {
console.error('flyover init error', error);
});
});
appendHotjar();
appendClarity();
appendCSP();
Expand Down
16 changes: 11 additions & 5 deletions src/common/services/FlyoverService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BlockchainConnection, BlockchainReadOnlyConnection, Network } from '@rsksmart/bridges-core-sdk';
import { BlockchainConnection, Network } from '@rsksmart/bridges-core-sdk';
import {
AcceptedPegoutQuote, Flyover,
LiquidityProvider, PegoutQuote, Quote,
Expand All @@ -10,6 +10,7 @@ import {
LiquidityProvider2WP, PeginQuote, QuotePegOut2WP,
SatoshiBig, WeiBig,
} from '@/common/types';
import { Wallet, providers } from 'ethers';
import { EnvironmentAccessorService } from './enviroment-accessor.service';
import { isValidSiteKey, ServiceError } from '../utils';

Expand Down Expand Up @@ -51,14 +52,19 @@ export default class FlyoverService {
}
}

initialize(): Promise<void> {
initialize(web3Provider?: providers.ExternalProvider): Promise<void> {
return new Promise<void>((resolve, reject) => {
BlockchainReadOnlyConnection.createUsingRpc(this.providerUrl)
const connectionPromise = web3Provider
? BlockchainConnection.createUsingStandard(web3Provider)
: BlockchainConnection.createUsingPassphrase(
Wallet.createRandom().mnemonic.phrase,
this.providerUrl,
);
connectionPromise
.then((connection) => {
console.log(connection);
this.flyover = new Flyover({
network: this.flyoverNetwork,
rskConnection: connection as unknown as BlockchainConnection,
rskConnection: connection as BlockchainConnection,
captchaTokenResolver: this.tokenResolver.bind(this),
disableChecksum: true,
});
Expand Down
4 changes: 3 additions & 1 deletion src/pegout/components/PegoutForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ import router from '@/common/router';
import ApiService from '@/common/services/ApiService';
import { FlyoverService } from '@/common/services';
import FullTxErrorDialog from '@/common/components/exchange/FullTxErrorDialog.vue';
import { providers } from 'ethers';
import PegoutOption from './PegoutOption.vue';
export default defineComponent({
Expand Down Expand Up @@ -186,6 +187,7 @@ export default defineComponent({
const clearFlyoverState = useAction('flyoverPegout', constants.FLYOVER_PEGOUT_CLEAR_STATE);
const clearPegoutTx = useAction('pegOutTx', constants.PEGOUT_TX_CLEAR);
const getPegoutQuotes = useAction('flyoverPegout', constants.FLYOVER_PEGOUT_GET_QUOTES);
const ethersProvider = useStateAttribute<providers.Web3Provider>('web3Session', 'ethersProvider');
const quotes = useStateAttribute<Record<number, QuotePegOut2WP[]>>('flyoverPegout', 'quotes');
const quoteDifferences = useStateAttribute<Array<ObjectDifference>>('flyoverPegout', 'differences');
const selectedQuote = useGetter<QuotePegOut2WP>('flyoverPegout', constants.FLYOVER_PEGOUT_GET_SELECTED_QUOTE);
Expand Down Expand Up @@ -368,7 +370,7 @@ export default defineComponent({
function clearState() {
clearFlyoverState();
clearPegoutTx();
initFlyoverTx();
initFlyoverTx(ethersProvider.value);
initPegoutTx();
selectedOption.value = '';
showStep.value = false;
Expand Down
6 changes: 4 additions & 2 deletions src/pegout/views/PegOut.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import {
} from 'vue';
import * as constants from '@/common/store/constants';
import PegoutForm from '@/pegout/components/PegoutForm.vue';
import { useAction, useGetter } from '@/common/store/helper';
import { useAction, useGetter, useStateAttribute } from '@/common/store/helper';
import { Feature, FeatureNames } from '@/common/types';
import { providers } from 'ethers';
export default defineComponent({
name: 'PegOut',
Expand All @@ -31,13 +32,14 @@ export default defineComponent({
const init = useAction('pegOutTx', constants.PEGOUT_TX_INIT);
const initFlyover = useAction('flyoverPegout', constants.FLYOVER_PEGOUT_INIT);
const flyoverFeature = useGetter<(name: FeatureNames) => Feature>('web3Session', constants.SESSION_GET_FEATURE);
const ethersProvider = useStateAttribute<providers.Web3Provider>('web3Session', 'ethersProvider');
const flyoverEnabled = ref(false);
const loadingProviders = ref(true);
onBeforeMount(() => {
const feature = flyoverFeature.value(FeatureNames.FLYOVER_PEG_OUT);
if (feature?.value === constants.ENABLED) {
initFlyover()
initFlyover(ethersProvider.value)
.then(() => {
flyoverEnabled.value = true;
loadingProviders.value = false;
Expand Down

0 comments on commit fe16c57

Please sign in to comment.