Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Blockchain Accounts for provider.getAccounts #439

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thin-squids-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bitski/waas-react-sdk": patch
---

Use Blockchain Accounts for provider.getAccounts
19 changes: 8 additions & 11 deletions packages/waas-react-sdk/src/lib/connectors/bitski.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ProviderNotFoundError,
} from 'wagmi';
import type { BitskiProviderShim } from 'bitski/lib/provider-shim';
import { getBlockchainAccounts } from '../utils/getBlockchainAccounts';

const BitskiIcon = 'https://cdn.bitskistatic.com/docs-web/bitskiWallet.svg';

Expand Down Expand Up @@ -100,10 +101,7 @@ export function bitski(parameters: BitskiParameters) {
const chainId: number = parameters?.chainId ?? (await this.getChainId());

if (status === AuthenticationStatus.Connected) {
const accounts: string[] = (await provider.request({
method: 'eth_accounts',
})) as string[];

const accounts = await this.getAccounts();
return {
accounts,
chainId,
Expand Down Expand Up @@ -147,10 +145,7 @@ export function bitski(parameters: BitskiParameters) {
await bitski.signIn();
}

const accounts: string[] = (await provider.request({
method: 'eth_requestAccounts',
})) as string[];

const accounts = await this.getAccounts();
if (!accounts) {
throw new BaseError('No Accounts found');
}
Expand Down Expand Up @@ -178,9 +173,11 @@ export function bitski(parameters: BitskiParameters) {
await this.connect();
}

const { accounts = [] } = await bitski.getUser();

return accounts as WagmiAccounts;
const token = await bitski.getCurrentAccessToken();
const blockchainAccounts = await getBlockchainAccounts(fetch, token);
return blockchainAccounts.map((account) => {
return account.address;
}) as WagmiAccounts;
},

async getChainId() {
Expand Down
23 changes: 23 additions & 0 deletions packages/waas-react-sdk/src/lib/utils/getBlockchainAccounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export async function getBlockchainAccounts(
fetch: typeof window.fetch,
token: string,
): Promise<BlockchainAccount[]> {
const response = await fetch('https://api.bitski.com/v2/blockchain/accounts', {
method: 'GET',
headers: {
Authorization: `Bearer ${token}`,
},
});
const { accounts } = (await response.json()) as AccountsResponse;
return accounts;
}

interface BlockchainAccount {
id: string;
address: string;
kind: string;
}

interface AccountsResponse {
accounts: BlockchainAccount[];
}
Loading