Skip to content

Commit 293fe09

Browse files
committed
Multiple Wallets Support
1 parent 4a8cc0e commit 293fe09

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1790
-470
lines changed

dev/angular.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
"js-sha3",
5050
"bech32",
5151
"aes-js",
52-
"scrypt-js"
52+
"scrypt-js",
53+
"metakeep"
5354
]
5455
},
5556
"configurations": {
@@ -127,5 +128,8 @@
127128
}
128129
}
129130
}
131+
},
132+
"cli": {
133+
"analytics": false
130134
}
131135
}

dev/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "dev",
33
"version": "1.0.0",
44
"scripts": {
5+
"version": "ng version",
56
"start": "ng serve",
67
"build": "ng build --configuration production --output-path dist --base-href ./",
78
"clear": "rm -rf dist node_modules .angular;"

dev/src/app/components/nav-bar/nav-bar.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
<a class="c-navbar__button" routerLink="/" routerLinkActive="active-link" [routerLinkActiveOptions]="{ exact: true }">{{ 'PAGES.HOME.NAME' | translate }}</a>
2424
<a class="c-navbar__button" routerLink="/accounts" routerLinkActive="active-link">{{ 'PAGES.ACCOUNTS.NAME' | translate }}</a>
25+
<a class="c-navbar__button" routerLink="/resources" *ngIf="isAntelope" routerLinkActive="active-link">{{ 'PAGES.RESOURCES.NAME' | translate }}</a>
2526
<a class="c-navbar__button" *ngIf="isLogged" routerLink="/wallet" routerLinkActive="active-link">{{ 'PAGES.WALLET.NAME' | translate }}</a>
2627
</div>
2728

dev/src/app/components/nav-bar/nav-bar.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { SideContainerService } from '@app/components/base-components/side-conta
1414
import { DropDownComponent } from '../base-components/drop-down/drop-down.component';
1515
import { TranslateService } from '@ngx-translate/core';
1616
import { SharedModule } from '@app/shared/shared.module';
17+
import { Web3OctopusService } from '@app/services/web3-octopus.service';
1718

1819
@Component({
1920
selector: 'app-nav-bar',
@@ -48,8 +49,13 @@ export class NavBarComponent implements OnInit, OnDestroy {
4849
private sideContainerService: SideContainerService,
4950
private translate: TranslateService,
5051
private sessionService: SessionService,
52+
private w3o: Web3OctopusService,
5153
) {}
5254

55+
get isAntelope(): boolean {
56+
return this.w3o.octopus.networks.current.type === 'antelope';
57+
}
58+
5359
ngOnInit() {
5460
// Detect theme preference
5561
this.store.select(user.selectors.isDarkTheme)

dev/src/app/pages/accounts/accounts.component.html

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,22 @@
1515
</ng-template>
1616

1717
<div class="p-accounts__login">
18-
<select class="p-accounts__network-select" [(ngModel)]="selectedNetwork" (change)="changeNetwork(selectedNetwork)">
18+
<select class="p-accounts__network-select" [(ngModel)]="networkName" (change)="changeNetwork(networkName)">
1919
<option *ngFor="let net of networks" [ngValue]="net.name">{{ net.settings.displayName }}</option>
2020
</select>
2121
<button class="p-accounts__login-btn" (click)="login()">{{ 'TYPES.BUTTON.LOGIN' | translate }}</button>
2222
</div>
23+
24+
<!--div
25+
class="p-accounts__google-one-tap"
26+
[class.p-accounts__google-one-tap--show]="networkType === 'ethereum'"
27+
>
28+
<div
29+
id="google_btn"
30+
[attr.data-client_id]="googleCtrl.clientId"
31+
class="p-accounts__google-one-tap-btn"
32+
>
33+
<div id="google_btn_content" class="p-accounts__google-one-tap-btn-loading">loading...</div>
34+
</div>
35+
</div-->
2336
</div>

dev/src/app/pages/accounts/accounts.component.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,12 @@
6464
&__login-btn {
6565
@include button-0;
6666
}
67+
68+
&__google-one-tap {
69+
display: none;
70+
margin-top: 20px;
71+
&--show {
72+
display: block;
73+
}
74+
}
6775
}

dev/src/app/pages/accounts/accounts.component.ts

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { RedirectService } from '@app/services/redirect.service';
66
import { SharedModule } from '@app/shared/shared.module';
77
import { W3oContextFactory, W3oNetwork, W3oSession } from '@vapaee/w3o-core';
88
import { LucideAngularModule, X } from 'lucide-angular';
9+
import { EthereumWalletMetakeep, googleCtrl, MetakeepWallets } from '@vapaee/w3o-ethereum';
10+
import { Subscription } from 'rxjs';
911

1012
const logger = new W3oContextFactory('AccountsComponent');
1113

@@ -23,17 +25,70 @@ const logger = new W3oContextFactory('AccountsComponent');
2325
export class AccountsComponent implements OnInit, OnDestroy {
2426
readonly XIcon = X;
2527
networks = this.w3o.octopus.networks.list;
26-
selectedNetwork = this.w3o.octopus.networks.current.name;
28+
networkName = this.w3o.octopus.networks.current.name;
29+
networkType = this.w3o.octopus.networks.current.type;
30+
31+
// Google Obe Tap Button
32+
googleCtrl = googleCtrl;
33+
googleSubscription: Subscription;
34+
googleLoading: boolean = false;
2735

2836
constructor(
2937
public sessionService: SessionService,
3038
private w3o: Web3OctopusService,
3139
private redirect: RedirectService,
3240
) {
41+
const context = logger.method('constructor', { sessionService, w3o, redirect });
3342
w3o.octopus.networks.current$.subscribe((network: W3oNetwork) => {
34-
console.log('Current network changed:', network);
35-
this.selectedNetwork = network.name;
43+
context.log('Current network changed:', network);
44+
this.networkName = network.name;
45+
this.networkType = network.type;
3646
});
47+
48+
/*
49+
if (!googleCtrl.logged) {
50+
this.googleSubscription = googleCtrl.onSuccessfulLogin.subscribe({
51+
next: (data) => {
52+
if (data) {
53+
this.googleLoading = true;
54+
const ethereumSupport = w3o.octopus.auth.getChainSupport('ethereum');
55+
const metakeepWallet = ethereumSupport.getWalletByName('metakeep', context) as EthereumWalletMetakeep;
56+
if (!metakeepWallet) {
57+
throw new Error('Metakeep wallet not found');
58+
} else {
59+
metakeepWallet.setEmail(data.email);
60+
ethereumSupport.setCurentWallet(metakeepWallet, context);
61+
this.login();
62+
}
63+
}
64+
},
65+
});
66+
67+
// we check the div is present before trying to render the google button
68+
const googleBtnLoop = setInterval(() => {
69+
// loop until div#google_btn is rendered
70+
const googleBtn = document.getElementById('google_btn');
71+
if (googleBtn !== null) {
72+
// we found it, so we stop the first loop
73+
clearInterval(googleBtnLoop);
74+
75+
// Now we call the button render function
76+
googleCtrl.renderButton('google_btn');
77+
78+
// Now we start a second loop waiting for the div#google_btn_content to be replaced by the actual google btn
79+
const googleBtnRenderSecondLoop = setInterval(() => {
80+
const googleBtnContent = document.getElementById('google_btn_content');
81+
if (googleBtnContent === null) {
82+
clearInterval(googleBtnRenderSecondLoop);
83+
} else {
84+
// if after a whole second it didn't render we call it again
85+
googleCtrl.renderButton('google_btn');
86+
}
87+
}, 1000);
88+
}
89+
}, 100);
90+
}
91+
*/
3792
}
3893

3994
ngOnInit() {

dev/src/app/services/session-kit.service.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,6 @@ export class SessionService {
6262
}
6363
}
6464

65-
// Restore session method
66-
async restoreSession() {
67-
const context = logger.method('restoreSession');
68-
try {
69-
this.w3o.octopus.auth.autoLogin(context);
70-
} catch (error) {
71-
console.error('Error restoring session:', error);
72-
throw error;
73-
}
74-
75-
}
76-
7765
validateAccount(address: string): Observable<boolean> {
7866
const sender = this.current?.address;
7967
const context = logger.method('validateAccount', { sender });

dev/src/app/services/web3-octopus.service.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ import {
1818
AntelopeTokensService, // extends W3oService
1919
AntelopeResourcesService,
2020
AntelopeChainSupport,
21+
AntelopeWalletAnchor,
2122
TelosZeroNetwork,
2223
TelosZeroTestnetNetwork,
2324
} from '@vapaee/w3o-antelope';
2425
// import the classes to support Ethereum networks
2526
import {
2627
EthereumChainSupport,
28+
EthereumWalletMetamask,
2729
EthereumTokensService,
2830
TelosEVMNetwork,
31+
// EthereumWalletMetakeep,
32+
googleCtrl,
2933
} from '@vapaee/w3o-ethereum';
3034

3135
import { VortDEXw3oServices } from '@app/types';
@@ -48,6 +52,7 @@ export class Web3OctopusService implements OnDestroy {
4852
constructor() {
4953
const context = logger.method('constructor');
5054
try {
55+
googleCtrl.setClientId('639241197544-pdd2fjldd0jeo0obmracoes7414eotpm.apps.googleusercontent.com');
5156
const octopus = new Web3Octopus<VortDEXw3oServices>(context);
5257
this.octopus = octopus;
5358
window.w3o = octopus; // assign the instance to the window object so it can be accessed from anywhere
@@ -56,7 +61,9 @@ export class Web3OctopusService implements OnDestroy {
5661
// Network type
5762
type: 'antelope',
5863
// chain support implementation
59-
chain: new AntelopeChainSupport(context),
64+
chain: new AntelopeChainSupport(context, [
65+
new AntelopeWalletAnchor(context)
66+
]),
6067
// list of supported Antelope networks
6168
networks: [
6269
new TelosZeroNetwork({}, context),
@@ -68,7 +75,15 @@ export class Web3OctopusService implements OnDestroy {
6875
// ---- Register Telos EVM support ----
6976
const telosEvmSupportSettings: W3oNetworkSupportSettings = {
7077
type: 'ethereum',
71-
chain: new EthereumChainSupport(context),
78+
chain: new EthereumChainSupport(context, [
79+
// Metamask wallet
80+
new EthereumWalletMetamask(context),
81+
// Metakeep wallet
82+
// new EthereumWalletMetakeep({
83+
// appName: 'Web3 Octopus Wallet',
84+
// appId: 'd190c88f-1bb5-4e16-bc48-96dbf33b77e0',
85+
// } as MetakeepOptions, context)
86+
]),
7287
networks: [
7388
new TelosEVMNetwork({}, context),
7489
]
@@ -85,7 +100,7 @@ export class Web3OctopusService implements OnDestroy {
85100
octopus.registerServices(services);
86101
octopus.init(
87102
{
88-
appName: 'VortDEX',
103+
appName: 'We3 Octopus',
89104
multiSession: false,
90105
autoLogin: true,
91106
},

dev/src/app/store/user/user.effects.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,6 @@ export class UserEffects {
1414
private localStorageService = inject(LocalStorageService);
1515
private sessionService = inject(SessionService);
1616

17-
initPreferences$ = createEffect(
18-
() =>
19-
this.actions$.pipe(
20-
ofType('@ngrx/effects/init'),
21-
tap(() => {
22-
this.sessionService.restoreSession();
23-
})
24-
),
25-
{ dispatch: false }
26-
);
27-
2817
savePreferences$ = createEffect(
2918
() =>
3019
this.actions$.pipe(

0 commit comments

Comments
 (0)