-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from klever-io/cardano-connect-test
feat: ✨ Cardano base provider
- Loading branch information
Showing
11 changed files
with
125 additions
and
14 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## Task title | ||
|
||
> Description | ||
✨ Features: | ||
- [ ] | ||
|
||
🔨 Improvements: | ||
- [ ] |
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,8 @@ | ||
// TODO: Add klever mobile app source name | ||
export const availableWallets = ['nami'] as const | ||
|
||
export type AvailableWallet = typeof availableWallets[number] | ||
|
||
export enum CardanoWallet { | ||
NAMI = 'nami', | ||
} |
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,30 @@ | ||
import { NotInjectedError } from '@/errors'; | ||
import { NoAvailableAccountsError } from '@/errors/no-accounts-available-error'; | ||
import { NoProviderAvailableError } from '@/errors/no-provider-available-error'; | ||
import { web3Window } from '@/types'; | ||
import { availableWallets } from './available-wallets'; | ||
import type { CardanoUsedAddress } from './types'; | ||
|
||
export async function connect(wallet?: string): Promise<CardanoUsedAddress[]> { | ||
if (!web3Window.cardano) | ||
throw new NotInjectedError() | ||
|
||
let injectedWallet = wallet | ||
if (typeof injectedWallet === 'undefined') { | ||
for (const availableWallet of availableWallets) { | ||
if (web3Window.cardano[availableWallet]) | ||
injectedWallet = availableWallet | ||
} | ||
} | ||
|
||
if (typeof injectedWallet === 'undefined') | ||
throw new NoProviderAvailableError() | ||
|
||
await web3Window.cardano[injectedWallet].enable() | ||
|
||
const usedAddresses: CardanoUsedAddress[] = await web3Window.cardano.getUsedAddresses() | ||
if (usedAddresses.length === 0) | ||
throw new NoAvailableAccountsError() | ||
|
||
return usedAddresses | ||
} |
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,35 @@ | ||
import type { ProviderEntity } from '@/entities/provider-entity'; | ||
import type { Account, Address, Balance } from '@/types'; | ||
import { CardanoWallet } from './available-wallets'; | ||
import { connect } from './connect'; | ||
import type { CardanoProviderProps } from './types'; | ||
|
||
export class CardanoProvider implements ProviderEntity { | ||
wallet?: CardanoWallet | ||
|
||
constructor({ wallet }: CardanoProviderProps) { | ||
if (wallet) | ||
this.wallet = CardanoWallet[wallet.toUpperCase() as keyof typeof CardanoWallet] | ||
} | ||
|
||
async connect(): Promise<Account[]> { | ||
const accounts = await connect(this.wallet) | ||
|
||
return accounts.map((account, index) => ({ | ||
name: `Account #${index}`, | ||
address: account, | ||
})) | ||
} | ||
|
||
async getBalance(address: Address): Promise<Balance> { | ||
throw new Error('Not yet implemented.') | ||
} | ||
|
||
async signMessage(address: Address, message: string): Promise<string> { | ||
throw new Error('Not yet implemented.') | ||
} | ||
|
||
signatureVerify(message: string, signature: string, address: string): boolean { | ||
throw new Error('Not yet implemented.') | ||
} | ||
} |
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 @@ | ||
import type { AvailableWallet } from './available-wallets'; | ||
|
||
export interface CardanoProviderProps { | ||
wallet?: AvailableWallet | ||
} | ||
|
||
export type CardanoUsedAddress = string |
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
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