Skip to content

Commit 47a6686

Browse files
Merge pull request #57 from Web3-Plurality/49-create-profile-component-in-repconnect-widget
49 create profile component in repconnect widget
2 parents 70e423d + 591f8f6 commit 47a6686

10 files changed

Lines changed: 394 additions & 191 deletions

File tree

README.md

Lines changed: 90 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Plurality Social Connect Widget
2-
This repo contains the functionality to load the plurality identity oracle as a popup widget.
1+
# Plurality Social Connect
2+
This repo contains the functionality to load the plurality smart profile wallet as an embedded widget.
33

44
## To run
55
```
@@ -10,108 +10,158 @@ npm install && npm run start
1010

1111
Here is a basic demo how it can be used in any react project
1212
```
13-
import PluralitySocialConnect from 'plurality-social-connect';
13+
import { PluralitySocialConnect } from '@plurality-network/smart-profile-wallet';
1414
1515
const App = () => {
16-
const childRef = useRef(null);
17-
// Handle the data returned from the widget
16+
17+
const options = { cliendId: '', theme: 'light' };
18+
1819
const handleDataReturned = (data) => {
1920
const receivedData = JSON.parse(JSON.stringify(data))
2021
console.log("dapp receives:", receivedData);
21-
alert(JSON.stringify(data));
22-
childRef.current.closeSocialConnectPopup();
23-
// Handle the received data in the external webpage
24-
// ... (perform actions with the received data)
2522
};
2623
2724
return (
2825
<div>
29-
<PluralitySocialConnect
30-
options={{ apps: 'facebook,twitter' }}
26+
<PluralitySocialConnect
27+
options={options}
3128
onDataReturned={handleDataReturned}
32-
// all customization params are optional
33-
// customization={{ height: '200px', width: '500px', initialBackgroundColor: '#E8A123', initialTextColor: '#FFFFFF', flipBackgroundColor: '#12AE83', flipTextColor: '#FFFFFF'}}
34-
ref={childRef}
3529
/>
3630
</div>
3731
);
3832
};
3933
```
40-
## Calling web3 functions through the social connect
4134

42-
Since the Metamask gets connected to the social connect, all web3 calls also need to be done through the social connect.
43-
You can use the following functions to call the blockchain layer:
35+
### Options
36+
There are two fields in the options object.
37+
`clientId` is the id that's specific to your application. If you use an empty clientId, it will pick up the default settings. However, if you want to customize the widget according to your own needs, then refer our [docs](https://docs.plurality.network) to find out the way to get your own clientId.
38+
`theme` can be either light or dark
39+
40+
41+
## Calling web3 functions through the Smart Profile Wallet
42+
43+
Every web3 login solution needs to interact with the blockchain for carrying out various functions. Once the widget is embedded and the user connects their profile and a session is stored in the local storage, then plurality’s wallet solution provides the following standard web3 functions. To call them in your application, use the following code samples
44+
4445

4546
### Get All Connected Accounts
4647
Returns all accounts that have been connected through the social connect
4748
```
48-
PluralitySocialConnect.getAllAccounts()
49+
(await PluralitySocialConnect.getAllAccounts()) as AllAccountsDataType;
4950
Returns: [0x123…, 0x456…]
5051
```
5152

5253
### Get Current Connected Account
5354
Get current account connected to the social connect
5455
```
55-
PluralitySocialConnect.getConnectedAccount()
56+
(await PluralitySocialConnect.getConnectedAccount()) as ConnectedAccountDataType;
5657
Returns: 0x123…
5758
```
5859

5960
### Get Signature
6061
Gets the message signed using the connected account and returns the signature
6162
```
62-
PluralitySocialConnect.getMessageSignature(message: string)
63-
Example:
64-
PluralitySocialConnect.getMessageSignature("Example `personal_sign` message.")
63+
(await PluralitySocialConnect.getMessageSignature(message)) as SignMessageDataType;
6564
```
6665

6766
### Verify Message Signature
6867
Verify if the signature matches the message using the current connected account and returns boolean true or false
6968
```
70-
PluralitySocialConnect.verifyMessageSignature(message: string, signature: string)
71-
Example: PluralitySocialConnect.verifyMessageSignature("Example `personal_sign` message.", "0xa1379711716d214c84c146bbaa9d03d77895526b8620bcae67a76f824be6fd3a43795645a31f758eaed39ee6aa5490a979233711d4e9d6a2e30fa09a5e9c808a1b")
69+
(await PluralitySocialConnect.verifyMessageSignature(message, key)) as VerifySignedMessageDataType;
7270
```
7371
### Get Balance
7472
Returns balance of the current account in wei. You need to convert it to required denomination yourself
7573
```
76-
PluralitySocialConnect.getBalance()
74+
(await PluralitySocialConnect.getBalance(rpc, chainId)) as GetBalanceDataType;
7775
```
7876

7977
### Send Transaction
80-
Send a certain amount (in ethers) to a certain address. Returns the transaction object
78+
Send a certain amount (in ethers) to a certain address. Returns the transaction object.
79+
80+
Please note that since Plurality profiles are chain agnostic, you need to provide the RPC and the chainId to ensure that balance is being read from the current read. You can find the RPC and the chainId of your preferred chain from [here](https://chainlist.org/)
81+
8182
```
82-
PluralitySocialConnect.sendTransaction(sendToAddress: string, value: string)
83-
Example: PluralitySocialConnect.sendTransaction("0xe613B4cd69Fe20E8bd0F0D79a264210886bA1AA2","0.01")
83+
(await PluralitySocialConnect.sendTransaction(rawTx, rpc, chainId)) as SendTransactionDataType;
8484
```
8585

8686
### Get Block Number
87-
Returns the latest block number
87+
Returns the latest block number. Please note that since Plurality profiles are chain agnostic, you need to provide the RPC and the chainId to ensure that balance is being read from the current read. You can find the RPC and the chainId of your preferred chain from [here](https://chainlist.org/)
88+
8889
```
89-
PluralitySocialConnect.getBlockNumber()
90+
(await PluralitySocialConnect.getBlockNumber(rpc, chainId)) as GetBlockNumberDataType;
9091
```
9192

9293
### Get Transaction Count
9394
Returns the transaction count of the given address
9495
```
95-
PluralitySocialConnect.getTransactionCount(address: string)
96-
Example: PluralitySocialConnect.getTransactionCount("0xe613B4cd69Fe20E8bd0F0D79a264210886bA1AA2")
96+
(await PluralitySocialConnect.getTransactionCount(address, rpc, chainId)) as GetTransactionCountDataType;
9797
```
9898

9999
### Read from contract
100100
Returns the response of executing the given get method of the contract with the given parameters
101101
```
102-
PluralitySocialConnect.readFromContract(contractAddress: string, abi: string, methodName: string, methodParams: string[])
103-
Example:
104-
const abi = '[{"inputs":[],"name":"retrieve","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"num","type":"uint256"}],"name":"store","outputs":[],"stateMutability":"nonpayable","type":"function"}]';
105-
PluralitySocialConnect.readFromContract("0x8E26aa0b6c7A396C92237C6a87cCD6271F67f937",abi,"retrieve", [])
102+
(await PluralitySocialConnect.readFromContract(address, abiVal, action, params, rpc, chainId)) as ReadFromContractDataType;
106103
```
107104

108105
### Write to contract
109106
Returns the transaction response of executing the given write method of the contract with the given parameters
110107
```
111-
PluralitySocialConnect.writeToContract(contractAddress: string, abi: string, methodName: string, methodParam: string[])
112-
Example:
113-
const abi = '[{"inputs":[],"name":"retrieve","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"num","type":"uint256"}],"name":"store","outputs":[],"stateMutability":"nonpayable","type":"function"}]';
114-
PluralitySocialConnect.writeToContract("0x8E26aa0b6c7A396C92237C6a87cCD6271F67f937",abi, "store", "5")
108+
(await PluralitySocialConnect.writeToContract(address, abiVal, action, params, rpc, chainId, options)) as WriteToContractDataType;
109+
```
110+
111+
## Calling profile functions through the Smart Profile Wallet
112+
Each wallet created through this embedded widget has a profile attached to it which contains basic user information like name, bio, avatar and description. Moreover, it also has the user's interests & reputation which is analysed from the social accounts connected to that profile.
113+
114+
As an application developer, you can get profile data from the connected wallet.
115+
116+
Every time the user does a successful login, you will get a response in the data handler that’s attached to the embedded widget
117+
118+
```
119+
const handleDataReturned = (data) => {
120+
const receivedData = JSON.parse(JSON.stringify(data))
121+
console.log("dapp receives:", receivedData);
122+
};
123+
124+
<PluralitySocialConnect
125+
options={options}
126+
onDataReturned={handleDataReturned}
127+
/>
128+
```
129+
130+
However, if you want to fetch the smart profile data at any point later, you can use the following function.
131+
132+
### Get Smart Profile Data
133+
```
134+
(await PluralitySocialConnect.getSmartProfileData()) as ConnectedAccountDataType;
135+
```
136+
137+
### Set Public Data
138+
139+
As a decentralized application developer, you might also need to store user’s information in a verifiable, decentralized, but gasless and privacy-preserving way. If you want to store any information about the user derived from their actions on your platform, you can set that information in your user’s profile. Next time when the user logs in to this dApp again, then the application will have access to this data again.
140+
141+
```
142+
(await PluralitySocialConnect.setPublicData("key", "value")) as ConnectedAccountDataType;
143+
```
144+
### Get Public Data
145+
To get previously stored data, the application can get it using the following function
146+
147+
```
148+
(await PluralitySocialConnect.getPublicData("name")) as ConnectedAccountDataType;
149+
```
150+
151+
### Set Private Data
152+
153+
Since user profiles are shared amongst different apps and platforms, if an application wants to ensure that the data you put in your user’s profile cannot be seen by any other application, then the application needs to set it in a private way.
154+
155+
```
156+
(await PluralitySocialConnect.setPrivateData("work", "Plurality")) as ConnectedAccountDataType;
157+
```
158+
159+
### Get Private Data
160+
161+
To get previously stored data, the application can get it using the following function
162+
163+
```
164+
(await PluralitySocialConnect.getPrivateData("work")) as ConnectedAccountDataType;
115165
```
116166

117167
## To publish new version on npm registry

package-lock.json

Lines changed: 25 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
},
6969
"devDependencies": {
7070
"@babel/core": "^7.23.3",
71+
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
7172
"@babel/preset-env": "^7.23.3",
7273
"@babel/preset-react": "^7.23.3",
7374
"@babel/preset-stage-0": "^7.8.3",

public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<meta name="description" content="Web site created using create-react-app" />
1010
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
1111
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Lexend&display=swap">
12+
<meta http-equiv="Permissions-Policy" content="clipboard-write=(self)">
1213
<!--
1314
manifest.json provides metadata used when your web app is installed on a
1415
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/

0 commit comments

Comments
 (0)