Skip to content

Commit 445c371

Browse files
committedJan 20, 2025
code docs, small refactors
1 parent 4499f69 commit 445c371

File tree

6 files changed

+47
-13
lines changed

6 files changed

+47
-13
lines changed
 

‎packages/sdk/README.md

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Embedded App Wallet
22

3-
Apillon Embedded Wallet JS SDK
3+
Apillon Embedded Wallet JS SDK.
4+
5+
More info can be found [in the Apillon wiki](https://wiki.apillon.io/build/12-embedded-wallets-integration.html).
46

57
## Stack
68

@@ -34,6 +36,11 @@ defaultNetworkId?: number;
3436
* Configuration of available networks. Oasis Sapphire is always included (ids 23294 and 23295)
3537
*/
3638
networks?: Network[];
39+
40+
/**
41+
* Method for authenticating with passkey to make it global.
42+
*/
43+
passkeyAuthMode: 'redirect' | 'popup' | 'tab_process' | 'tab_form' = 'redirect';
3744
```
3845

3946
The class instance is then available on window (`embeddedWallet`) and can be obtained with the `getEmbeddedWallet()` utility.
@@ -85,6 +92,18 @@ wallet.events.on('txSubmitted', tx => {
8592

8693
- `getAccountBalance`
8794

95+
- `getAccountPrivateKey`
96+
97+
### Wallet accounts methods
98+
99+
- `getAccountWallets`
100+
Get all wallets added on user's account. Requires authentication.
101+
102+
- `addAccountWallet`
103+
Add new wallet or import from privateKey.
104+
105+
- `updateAccountWalletTitle`
106+
88107
### Transaction methods
89108

90109
- `signMessage`
@@ -96,13 +115,21 @@ wallet.events.on('txSubmitted', tx => {
96115
Send raw transaction data to network.
97116
If chainId is provided, the transaction is sent to that network (cross-chain).
98117

118+
- `submitTransaction`
119+
Prepare transaction and emit `txSubmitted` event (to show tx in tx history in UI e.g.).
120+
To be used after sending transaction through anything else than `broadcastTransaction`.
121+
Doesn't do anything by itself, just for logging/parsing transactions.
122+
99123
- `signContractWrite`
100124
Get signed tx for making a contract write call.
101125

102126
- `contractRead`
103127
Get result of contract read.
104128
Utility function, this has nothing to do with Oasis.
105129

130+
- `processGaslessMethod`
131+
Call a contract method with a gasless transaction (app owner pays for the transaction fees instead of user).
132+
106133
### mustConfirm
107134

108135
This parameter can be used for wallet actions that require user confirmation. If set to `true`, the event `signatureRequest`/`txApprove` will be emitted with `resolve()` method passed in payload. Once resolve is called, the action continues. This can be used to display tx confirmation UI e.g.

‎packages/sdk/lib/index.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ class EmbeddedWallet {
495495
funcDataTypes = 'tuple(bytes32 hashedUsername, bytes32 digest, bytes data)';
496496
}
497497

498-
const res = await this.gaslessTx({
498+
const res = await this.processGaslessMethod({
499499
label: 'Add new account',
500500
strategy: params.strategy,
501501
authData: params.authData,
@@ -1031,7 +1031,7 @@ class EmbeddedWallet {
10311031
/**
10321032
* Prepare tx and emit `txSubmitted` event (to show tx in tx history in UI e.g.)
10331033
*/
1034-
submitTx(
1034+
submitTransaction(
10351035
txHash: string,
10361036
signedTxData?: ethers.BytesLike,
10371037
chainId?: number,
@@ -1193,7 +1193,17 @@ class EmbeddedWallet {
11931193
}
11941194
}
11951195

1196-
async gaslessTx(params: {
1196+
/**
1197+
* Call an `Account Manager` contract method with a gasless transaction.
1198+
* This means that app owner (clientId) pays for the transaction fees instead of user.
1199+
* These methods must be supported by `generateGaslessTx` method on the contract.
1200+
* Supported methods are defined by `GaslessTxType`.
1201+
* About
1202+
* - get & confirm credentials
1203+
* - calculate and format tx data (according to `funcDataTypes` and `funcDataValuesFormatter` params)
1204+
* - broadcast the tx (marked with `label` from params)
1205+
*/
1206+
async processGaslessMethod(params: {
11971207
strategy: AuthStrategyName;
11981208
authData: AuthData;
11991209
data: any;

‎packages/sdk/lib/types.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ export type Network = {
1414
id: number;
1515
rpcUrl: string;
1616
explorerUrl: string;
17-
imageUrl?: string;
18-
currencySymbol?: string;
19-
currencDecimals?: number;
17+
imageUrl?: string; // Icon of the chain for display in UI
18+
currencySymbol?: string; // Symbol of the native currency (default is 'ETH')
19+
currencyDecimals?: number; // Number of decimals of the native currency (default is 18)
2020
};
2121

2222
export type SignatureCallback = (

‎packages/ui/README.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ This package provides default UI for showing the state of connected account and
44

55
Use `EmbeddedWalletUI()` to initialize SDK and the UI. The UI is done with React and HeadlessUI (tailwind).
66

7-
There are some UI specific options in addition to all SDK options.
7+
There are some UI specific options in addition to all the SDK options.
88

99
```ts
10-
// Supported networks info, for showing names and links to explorer.
11-
networks?: { name: string; id: number; rpcUrl: string; explorerUrl: string }[];
12-
1310
/**
1411
* Automatically broadcast with SDK after confirming a transaction.
1512
*

‎packages/ui/src/contexts/tokens.context.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function TokensProvider({ children }: { children: React.ReactNode }) {
9898
address: '',
9999
name: `${networksById?.[walletState.networkId]?.name} ETH`,
100100
symbol: networksById?.[walletState.networkId]?.currencySymbol || 'ETH',
101-
decimals: networksById?.[walletState.networkId]?.currencDecimals || 18,
101+
decimals: networksById?.[walletState.networkId]?.currencyDecimals || 18,
102102
balance: activeWallet?.balance || '',
103103
}),
104104
[activeWallet?.balance, walletState.networkId]

‎packages/ui/src/contexts/wallet.context.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ function WalletProvider({
403403

404404
function formatNativeBalance(balance: string | bigint | number) {
405405
return (
406-
ethers.formatUnits(balance, networksById?.[state.networkId]?.currencDecimals || 18) +
406+
ethers.formatUnits(balance, networksById?.[state.networkId]?.currencyDecimals || 18) +
407407
` ${networksById?.[state.networkId]?.currencySymbol || 'ETH'}`
408408
);
409409
}

0 commit comments

Comments
 (0)
Please sign in to comment.