-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from proyecto26/feat/3-add-page-to-display-the-…
…balance-of-the-wallet add page to display balance of the wallet
- Loading branch information
Showing
29 changed files
with
1,187 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,6 @@ Thumbs.db | |
|
||
.nx/cache | ||
.angular | ||
|
||
# Environment Variables | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
NG_APP_SHYFT_API_KEY=fill-this-in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
apps/webapp/src/app/containers/layout/layout-container.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
<section class="min-h-screen flex flex-col"> | ||
<projectx-header [title]="title"> | ||
<projectx-header [title]="title" [links]="headerLinks"> | ||
<div right> | ||
<hd-wallet-multi-button></hd-wallet-multi-button> | ||
</div> | ||
</projectx-header> | ||
<main class="flex flex-grow"> | ||
<ng-content></ng-content> | ||
</main> | ||
<projectx-footer [navigation]="navigationLinks" /> | ||
<projectx-footer [navigation]="footerLinks" /> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<webapp-layout-container> | ||
<section class="mx-auto w-full max-w-7xl px-4 py-16 sm:px-6 lg:px-8 lg:pb-24"> | ||
<div class="max-w-xl"> | ||
<h1 class="text-2xl font-bold tracking-tight text-gray-900 sm:text-3xl">Account</h1> | ||
<p class="mt-1 text-sm text-gray-500"> | ||
Check the status of your account | ||
</p> | ||
</div> | ||
|
||
<section aria-labelledby="recent-heading" class="mt-16"> | ||
<h2 id="recent-heading" class="sr-only"> | ||
Wallet Status | ||
</h2> | ||
|
||
<div class="space-y-20"> | ||
<div *ngIf="(account$ | async) as account"> | ||
<div | ||
class="rounded-lg bg-gray-50 px-4 py-6 sm:flex sm:items-center sm:justify-between sm:space-x-6 sm:px-6 lg:space-x-8"> | ||
<dl | ||
class="flex-auto space-y-6 divide-y divide-gray-200 text-sm text-gray-600 sm:grid sm:grid-cols-3 sm:gap-x-6 sm:space-y-0 sm:divide-y-0 lg:w-1/2 lg:flex-none lg:gap-x-8"> | ||
<div class="flex justify-between sm:block"> | ||
<dd class="sm:mt-1"> | ||
<img [src]="account.info?.image" alt="account.info?.name || token" | ||
class="h-16 w-16 rounded object-cover object-center" /> | ||
</dd> | ||
</div> | ||
<div class="flex justify-between pt-6 sm:block sm:pt-0"> | ||
<dt class="font-medium text-gray-900">Balance</dt> | ||
<dd class="sm:mt-1"> | ||
{{ account.balance }} | ||
</dd> | ||
</div> | ||
<div class="flex justify-between pt-6 font-medium text-gray-900 sm:block sm:pt-0"> | ||
<dt>Is Frozen</dt> | ||
<dd class="sm:mt-1"> | ||
{{ account.isFrozen ? 'Yes' : 'No' }} | ||
</dd> | ||
</div> | ||
</dl> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
</section> | ||
</webapp-layout-container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { AccountPage } from './account.page'; | ||
|
||
describe('AccountPage', () => { | ||
let component: AccountPage; | ||
let fixture: ComponentFixture<AccountPage>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [AccountPage], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(AccountPage); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Component, inject } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
|
||
import { LayoutContainerComponent } from '../../containers/layout/layout-container.component'; | ||
import { WalletStore } from '../../store'; | ||
|
||
@Component({ | ||
selector: 'webapp-account', | ||
standalone: true, | ||
imports: [CommonModule, LayoutContainerComponent], | ||
templateUrl: './account.page.html', | ||
styleUrl: './account.page.css', | ||
providers: [WalletStore], | ||
}) | ||
export class AccountPage { | ||
|
||
readonly walletStore = inject(WalletStore); | ||
readonly account$ = this.walletStore.account() | ||
} |
Empty file.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
apps/webapp/src/app/pages/home.page.ts → apps/webapp/src/app/pages/home/home.page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './wallet'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './store' | ||
export * from './model' | ||
export * from './service' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export type TokenBalanceResponse = { | ||
success: boolean; | ||
message: string; | ||
result: { | ||
address: string; | ||
balance: number; | ||
associated_account: string; | ||
info: { | ||
name: string; | ||
symbol: string; | ||
image: string; | ||
decimals: number; | ||
}; | ||
isFrozen: false; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Injectable, inject } from '@angular/core'; | ||
import { map, of } from 'rxjs'; | ||
|
||
import { environment } from '../../../environments/environment'; | ||
import { TokenBalanceResponse } from './model'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class ShyftApiService { | ||
private readonly http = inject(HttpClient); | ||
|
||
getAccount(publicKey?: string) { | ||
if (!publicKey) { | ||
return of(null); | ||
} | ||
|
||
const url = new URL( | ||
'/sol/v1/wallet/token_balance', | ||
environment.shyftApiUrl | ||
); | ||
url.searchParams.append('network', environment.walletNetwork); | ||
url.searchParams.append('wallet', publicKey); | ||
url.searchParams.append('token', environment.mintUSDC); | ||
|
||
return this.http | ||
.get<TokenBalanceResponse>(url.toString(), { | ||
headers: { | ||
'x-api-key': environment.shyftApiKey, | ||
}, | ||
}) | ||
.pipe(map((res) => res.result)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { computed, inject } from '@angular/core'; | ||
import { signalStore, withComputed, withState } from '@ngrx/signals'; | ||
import { WalletStore as WalletAdapterStore } from '@heavy-duty/wallet-adapter'; | ||
|
||
import { ShyftApiService } from './service'; | ||
import { switchMap } from 'rxjs'; | ||
|
||
type WalletState = { | ||
isLoading: boolean; | ||
wallet: WalletAdapterStore; | ||
error?: string; | ||
}; | ||
|
||
export const WalletStore = signalStore( | ||
withState( | ||
() => | ||
<WalletState>{ | ||
wallet: inject(WalletAdapterStore), | ||
} | ||
), | ||
withComputed((store, walletService = inject(ShyftApiService)) => ({ | ||
account: computed(() => { | ||
return store | ||
.wallet() | ||
.publicKey$.pipe( | ||
switchMap((publicKey) => | ||
walletService.getAccount(publicKey?.toBase58()) | ||
) | ||
); | ||
}), | ||
})) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
interface ImportMeta { | ||
readonly env: ImportMetaEnv; | ||
} | ||
|
||
interface ImportMetaEnv { | ||
/** | ||
* Built-in environment variable. | ||
* @see Docs https://github.com/chihab/dotenv-run/packages/angular#node_env. | ||
*/ | ||
readonly NODE_ENV: string; | ||
// Add your environment variables below | ||
readonly NG_APP_SHYFT_API_KEY: string; | ||
[key: string]: unknown; | ||
} | ||
|
||
/* | ||
* Remove all the deprecated code below if you're using import.meta.env (recommended) | ||
*/ | ||
|
||
/****************************** DEPREACTED **************************/ | ||
/** | ||
* @deprecated process.env usage | ||
* prefer using import.meta.env | ||
* */ | ||
// declare var process: { | ||
// env: { | ||
// NODE_ENV: string; | ||
// [key: string]: any; | ||
// }; | ||
// }; | ||
|
||
// If your project references @types/node directly (in you) or indirectly (as in RxJS < 7.6.0), | ||
// you might need to use the following declaration merging. | ||
// declare namespace NodeJS { | ||
// export interface ProcessEnv { | ||
// readonly NODE_ENV: string; | ||
// // Add your environment variables below | ||
// } | ||
// } | ||
|
||
// If you're using Angular Universal and process.env notation, you'll need to add the following to your tsconfig.server.json: | ||
/* In your tsconfig.server.json */ | ||
// { | ||
// "extends": "./tsconfig.app.json", | ||
// ... | ||
// "exclude": [ | ||
// "src/env.d.ts" | ||
// ] | ||
// } | ||
|
||
/*********************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const environment = { | ||
production: import.meta.env.NODE_ENV === 'production', | ||
shyftApiKey: import.meta.env.NG_APP_SHYFT_API_KEY, | ||
shyftApiUrl: 'https://api.shyft.to', | ||
walletNetwork: 'mainnet-beta', | ||
mintUSDC: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const environment = { | ||
production: false, | ||
shyftApiKey: import.meta.env.NG_APP_SHYFT_API_KEY, | ||
shyftApiUrl: 'https://api.shyft.to', | ||
walletNetwork: 'devnet', | ||
mintUSDC: '4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU' | ||
}; |
Oops, something went wrong.