Skip to content
This repository has been archived by the owner on Mar 26, 2023. It is now read-only.

Commit

Permalink
use the new lazy loading approach in samples
Browse files Browse the repository at this point in the history
  • Loading branch information
joshstevens19 committed May 24, 2021
1 parent c9a553a commit 2f9344d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 30 deletions.
Binary file added funfair-tech-wallet-sdk-3.4.0.tgz
Binary file not shown.
33 changes: 23 additions & 10 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
"@funfair-tech/wallet-sdk": "^3.0.3",
"@funfair-tech/wallet-sdk": "file:funfair-tech-wallet-sdk-3.4.0.tgz",
"@funfair-tech/wallet-vue": "^1.1.0",
"core-js": "^3.6.5",
"rxjs": "^6.6.3",
Expand Down
4 changes: 0 additions & 4 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<link rel="icon" href="<%= BASE_URL %>favicon.ico" />
<title><%= htmlWebpackPlugin.options.title %></title>
<script
src="https://wallet.funfair.io/assets/sdk/fun-wallet-sdk.js?appId=0x1b084986077d1aedfa1d92318fdcc7d1621fbc92deb390269b94226fd79c0ce6"
type="text/JavaScript"
></script>
</head>
<body>
<noscript>
Expand Down
26 changes: 22 additions & 4 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<template>
<div id="app">
<WalletLeader :registerEventListeners="this.registerEventListeners" />
<div class="App">
<div class="App-container">
<img class="App-logo" src="./assets/logo.svg" />
Expand All @@ -22,7 +21,7 @@
</template>

<script>
import { WalletLeader, WalletFollower } from '@funfair-tech/wallet-vue';
import { WalletFollower } from '@funfair-tech/wallet-vue';
import { login, logout } from './services/wallet-service';
import { registerEventListeners } from './services/wallet-service';
import LoggedInActions from './components/Logged-In-Actions.vue';
Expand All @@ -31,11 +30,11 @@ import {
isAuthenticated$,
restoreAuthenticationTaskCompleted$,
} from './services/store';
import { FunWalletEmbed } from '@funfair-tech/wallet-sdk';
export default {
name: 'App',
components: {
WalletLeader,
LoggedInActions,
LoggedOutActions,
WalletFollower,
Expand All @@ -54,8 +53,27 @@ export default {
logout();
},
},
created: function() {
created: async function() {
const _this = this;
// you call this method when you want to load the wallet
// this can be on a button click or page load up to how
// your dApp needs it to act
// it returns the fun wallet sdk but this
// is always exposed in `window.funwallet.sdk`
await FunWalletEmbed.load({
appId:
'0x4bacd419787e5caec0058282067089891e88d48afd03741ddb452555eb7bcf3d',
// make sure its in a arrow expression
// functions so it can get context to `this`
// when executing your wallet event listener method
eventListenerCallback: () => {
this.registerEventListeners();
},
environment: 'LOCAL',
});
isAuthenticated$.subscribe((value) => {
_this.$data.isLoggedIn = value;
});
Expand Down
28 changes: 17 additions & 11 deletions src/services/wallet-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ import Web3 from 'web3';
import { isAuthenticated$, restoreAuthenticationTaskCompleted$ } from './store';

export function registerEventListeners() {
window.funwallet.sdk.on(
MessageListeners.authenticationCompleted,
(result) => {
if (result.origin === 'https://wallet.funfair.io') {
isAuthenticated$.next(true);
}
}
);

window.funwallet.sdk.on(
MessageListeners.restoreAuthenticationCompleted,
(result) => {
if (result.origin === 'https://wallet.funfair.io') {
restoreAuthenticationTaskCompleted$.next(true);

// if the user has been restored authentication then your all good
// to go again
if (result.data.isAuthenticated) {
// result.data.result holds `AuthenticationCompletedResponeData` in for you.
isAuthenticated$.next(true);
}
}
}
);
Expand Down Expand Up @@ -68,8 +66,16 @@ export function registerEventListeners() {
// register all the other events your interested in here...
}

export function login() {
window.funwallet.sdk.openWalletAuthenticationPopUp();
export async function login() {
try {
const result = await window.funwallet.sdk.auth.login();
console.log('Authentication result', result);

isAuthenticated$.next(true);
} catch (error) {
console.error('User did not sign in');
return;
}
}

export function logout() {
Expand Down

0 comments on commit 2f9344d

Please sign in to comment.