Skip to content

Commit e239c42

Browse files
authored
docs: add provider section (#1532)
Co-authored-by: janniks <[email protected]>
1 parent a124807 commit e239c42

File tree

3 files changed

+52
-18
lines changed

3 files changed

+52
-18
lines changed

docs/feature-guides/sign-transactions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,4 +412,4 @@ interface TransactionResponse {
412412
}
413413
```
414414

415-
<StacksProviderSection/>
415+
<StacksProviderSection/>

docs/feature-guides/update-profile.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
---
22
title: Update User Profile
33
---
4+
45
import StacksjsStartersNote from '../includes/\_stacks.js-starters-note.mdx';
56
import StacksProviderSection from '../includes/\_stacks.js-provider-section.mdx';
67

78
<StacksjsStartersNote/>
89

910
This guide explains how to change the universal profile of an authenticated user.
1011

11-
When a user creates a new account with Hiro Wallet a basic profile is created and stored on the user's own storage hub. The basic profile contains
12+
When a user creates a new account with Hiro Wallet a basic profile is created and stored on the user's own storage hub. The basic profile contains
1213
only a public key. It can be extended to contain personal information like an avatar,name and description. It is always cryptographically signed by the user's key, the so-called owner key.
1314

1415
:::info
@@ -20,9 +21,10 @@ like this:
2021

2122
![image](https://user-images.githubusercontent.com/1449049/215344771-455d3345-b890-49d0-9cfa-fd1f92bf5b1e.png)
2223

23-
In order to update the public profile, apps can make request to the Stacks wallet. These requests are reviewed and confirmed by the user in the wallet similar to transaction signing.
24+
In order to update the public profile, apps can make request to the Stacks wallet. These requests are reviewed and confirmed by the user in the wallet similar to transaction signing.
2425

2526
## Install dependency
27+
2628
:::tip
2729
In order to utilize the latest profile updating with the Hiro Wallet, use a version >= 7.1.0 of the `@stacks/connect` NPM package.
2830
:::
@@ -33,7 +35,7 @@ The following dependency must be installed:
3335
npm install @stacks/connect
3436
```
3537

36-
This also installs the NPM package `@stacks/profile`. It contains the data type `PublicPersonProfile` used for the public profile.
38+
This also installs the NPM package `@stacks/profile`. It contains the data type `PublicPersonProfile` used for the public profile.
3739

3840
## Initiate session
3941

@@ -43,17 +45,20 @@ See the [authentication guide](https://docs.hiro.so/build-apps/authentication) b
4345

4446
## Prompt to update the profile
4547

46-
After the user chose the content of the profile, create a `PublicPersonProfile` object from that data and call the `openProfileUpdateRequestPopup` function provided by the `connect` package to trigger the display of the profile update prompt.
48+
After the user chose the content of the profile, create a `PublicPersonProfile` object from that data and call the `openProfileUpdateRequestPopup` function provided by the `connect` package to trigger the display of the profile update prompt.
4749

4850
```tsx
4951
import { openProfileUpdateRequestPopup } from '@stacks/connect';
5052

51-
const profile = {"@type": "Person", "@context": "https://schema.org",
52-
name: "Friedger",
53-
image: [{"@type": "ImageObject",
54-
name: "avatar",
55-
contentUrl: "https://friedger.de/profile.png"}]};
56-
53+
const profile = {
54+
'@type': 'Person',
55+
'@context': 'https://schema.org',
56+
name: 'Friedger',
57+
image: [
58+
{ '@type': 'ImageObject', name: 'avatar', contentUrl: 'https://friedger.de/profile.png' },
59+
],
60+
};
61+
5762
openProfileUpdateRequestPopup({
5863
profile,
5964
appDetails: {
@@ -67,6 +72,7 @@ openProfileUpdateRequestPopup({
6772
```
6873

6974
Several parameters are available for calling `openProfileUpdateRequestPopup`. Here is the exact interface for them:
75+
7076
```tsx
7177
interface ProfileUpdateRequestOptions {
7278
profile: PublicPersonProfile;
@@ -82,7 +88,7 @@ interface ProfileUpdateRequestOptions {
8288
}
8389
```
8490

85-
After the profile was updated, the user can share the profile with other users.
91+
After the profile was updated, the user can share the profile with other users.
8692

8793
## Lookup a Public Profile
8894

@@ -102,18 +108,15 @@ export interface ProfileLookupOptions {
102108
The function returns a promise with the data of the public profile if the data could be retrieved from the BNS name owner's storage and if the retrieved JSON token was sucessfully verified.
103109

104110
The recommended schema for the profile is as follows:
111+
105112
```tsx
106113
export interface PublicPersonProfile extends PublicProfileBase {
107114
'@type': 'Person';
108115
name?: string;
109116
givenName?: string;
110117
familyName?: string;
111118
description?: string;
112-
image?: {'@type': 'ImageObject';
113-
name?: string;
114-
contentUrl?: string;
115-
[k: string]: unknown;
116-
}[];
119+
image?: { '@type': 'ImageObject'; name?: string; contentUrl?: string; [k: string]: unknown }[];
117120
website?: {
118121
'@type'?: string;
119122
url?: string;
@@ -152,6 +155,7 @@ export interface PublicPersonProfile extends PublicProfileBase {
152155
[k: string]: unknown;
153156
}
154157
```
158+
155159
## Usage in React Apps
156160

157161
Import the `useConnect` helper from [`connect-react`](https://github.com/hirosystems/connect) package to update profiles more seamlessly with React apps.
@@ -210,5 +214,4 @@ interface ProfileUpdatePayload {
210214

211215
After the user confirms the update, a `profileUpdateResponse` payload of type `PublicProfile` is sent back to your app. It contains the updated profile as confirmed by the user. Note, that this profile can be different to the requested profile by the app because the user might have modified the profile in the wallet before confirming the changes.
212216

213-
214217
<StacksProviderSection/>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## StacksProvider injected variable
2+
3+
When users have the [Hiro Wallet](https://www.hiro.so/wallet/install-web) extension installed, the extension will inject a global `StacksProvider` variable into the JavaScript context of your web app. This allows your JavaScript code to hook into the extension, and make authentication, transaction and signature requests. `@stacks/connect` automatically detects and uses this global variable for you.
4+
5+
At the moment, only the Hiro Wallet extension and the Xverse built-in browswer includes a `StacksProvider`, however, ideally more wallets (and mobile wallets) will support this format, so that your app can be compatible with any Stacks wallet that has functionality to embed web applications.
6+
7+
In your web application, you can check to see if the user has a compatible wallet installed by checking for the presence of `window.StacksProvider`.
8+
9+
Here is the interface for the `StacksProvider` variable.
10+
11+
```tsx
12+
interface StacksProvider {
13+
transactionRequest(payload: string): Promise<FinishedTxPayload | SponsoredFinishedTxPayload>;
14+
authenticationRequest(payload: string): Promise<string>;
15+
signatureRequest(payload: string): Promise<SignatureData>;
16+
structuredDataSignatureRequest(payload: string): Promise<SignatureData>;
17+
profileUpdateRequest(payload: string): Promise<PublicProfile>;
18+
getProductInfo:
19+
| undefined
20+
| (() => {
21+
version: string;
22+
name: string;
23+
meta?: {
24+
tag?: string;
25+
commit?: string;
26+
[key: string]: any;
27+
};
28+
[key: string]: any;
29+
});
30+
}
31+
```

0 commit comments

Comments
 (0)