Skip to content

Commit 134e463

Browse files
feat: remove near-api-js account object dependency from change functions (#38)
* refactor: remove dependency on near-api-js account and connection objects from change functions * test: update tests to use new network initialization * chore: squash * docs: amend docs to use new initailaization * docs: update docs to use the new signer object and fix broken links * build(lint): fix linting errors * chore: squash * refactor: convert signer to account because signer is icky
1 parent 8f6ad43 commit 134e463

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+779
-572
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
<img alt="GitHub Pre-release" src="https://img.shields.io/github/v/release/NEARBuilders/near-social-js?include_prereleases&label=pre-release&logo=github">
1717
</a>
1818
<a href="https://github.com/NEARBuilders/near-social-js/releases">
19-
<img alt="GitHub Pre-release Date - Published At" src="https://img.shields.io/github/release-date-pre/NEARBuilders/near-social-js?label=pre-release%20date&logo=github
20-
">
19+
<img alt="GitHub Pre-release Date - Published At" src="https://img.shields.io/github/release-date-pre/NEARBuilders/near-social-js?label=pre-release%20date&logo=github">
2120
</a>
2221
</p>
2322

docs/advanced/granting-write-permission.mdx

Lines changed: 28 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,17 @@ Accounts can grant write permission to other accounts for a set of keys.
3232
```js
3333
const { Social } = require('@builddao/near-social-js');
3434

35-
const grantee = await nearConnection.account('alice.near');
36-
const granter = await nearConnection.account('bob.near');
37-
const accessKeys = await granter.getAccessKeys();
3835
const social = new Social();
3936
const transaction = await social.grantWritePermission({
40-
blockHash: accessKeys[0].block_hash,
41-
granteeAccountId: grantee.accountId,
37+
account: {
38+
accountID: 'bob.near',
39+
publicKey: 'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW',
40+
},
41+
granteeAccountId: 'alice.near',
4242
keys: [
4343
'alice.near/profile/name',
4444
'alice.near/profile/image/url',
4545
],
46-
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
47-
publicKey: accessKeys[0].public_key,
48-
signer: granter,
4946
});
5047

5148
// ...sign the returned transaction and post to the network
@@ -56,41 +53,22 @@ Accounts can grant write permission to other accounts for a set of keys.
5653
<TabItem value="javascript-via-cdn">
5754

5855
```js
59-
var accessKeys;
60-
var grantee;
61-
var granter;
62-
var social;
63-
64-
nearConnection.account('alice.near')
65-
.then((_granter) => {
66-
granter = _granter;
67-
68-
return nearConnection.account('bob.near');
69-
})
70-
.then((_grantee) => {
71-
grantee = _grantee;
72-
73-
return granter.getAccessKeys();
74-
})
75-
.then((_accessKeys) => {
76-
accessKeys = _accessKeys;
77-
social = new NEARSocialSDK();
78-
79-
return social.grantWritePermission({
80-
blockHash: accessKeys[0].block_hash,
81-
granteeAccountId: grantee.accountId,
82-
keys: [
83-
'alice.near/profile/name',
84-
'alice.near/profile/image/url',
85-
],
86-
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
87-
publicKey: accessKeys[0].public_key,
88-
signer: granter,
89-
});
90-
})
91-
.then((transaction) => {
92-
// ...sign the returned transaction and post to the network
93-
});
56+
var social = new NEARSocialSDK();
57+
58+
social.grantWritePermission({
59+
account: {
60+
accountID: 'bob.near',
61+
publicKey: 'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW',
62+
},
63+
granteeAccountId: 'alice.near',
64+
keys: [
65+
'alice.near/profile/name',
66+
'alice.near/profile/image/url'
67+
]
68+
})
69+
.then((transaction) => {
70+
// ...sign the returned transaction and post to the network
71+
});
9472
```
9573

9674
</TabItem>
@@ -99,20 +77,17 @@ Accounts can grant write permission to other accounts for a set of keys.
9977
```typescript
10078
import { Social } from '@builddao/near-social-js';
10179

102-
const grantee = await nearConnection.account('alice.near');
103-
const granter = await nearConnection.account('bob.near');
104-
const accessKeys = await granter.getAccessKeys();
10580
const social = new Social();
10681
const transaction = await social.grantWritePermission({
107-
blockHash: accessKeys[0].block_hash,
108-
granteeAccountId: grantee.accountId,
82+
account: {
83+
accountID: 'bob.near',
84+
publicKey: 'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW',
85+
},
86+
granteeAccountId: 'alice.near',
10987
keys: [
11088
'alice.near/profile/name',
11189
'alice.near/profile/image/url',
11290
],
113-
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
114-
publicKey: accessKeys[0].public_key,
115-
signer: granter,
11691
});
11792

11893
// ...sign the returned transaction and post to the network
@@ -124,12 +99,12 @@ Accounts can grant write permission to other accounts for a set of keys.
12499

125100
:::caution
126101

127-
If the grantee account ID or the account ID in each key is not a valid account ID then a [`InvalidAccountIdError`](../../api-reference/errors#invalidaccountiderror) is thrown.
102+
If the grantee account ID or the account ID in each key is not a valid account ID then a [`InvalidAccountIdError`](../api-reference/errors#invalidaccountiderror) is thrown.
128103

129104
:::
130105

131106
:::caution
132107

133-
If a key does is not owned by the granter, then a [`KeyNotAllowedError`](../../api-reference/errors#keynotallowederror) is thrown.
108+
If a key does is not owned by the granter, then a [`KeyNotAllowedError`](../api-reference/errors#keynotallowederror) is thrown.
134109

135110
:::

docs/advanced/reading-data.mdx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ Getting specific values, like the example from above, you can use a set of keys:
5656
'alice.near/profile/image/url',
5757
'bob.near/profile/name',
5858
],
59-
rpcURL //rpc url for your network.
6059
});
6160

6261
console.log(result);
@@ -95,7 +94,6 @@ Getting specific values, like the example from above, you can use a set of keys:
9594
'alice.near/profile/image/url',
9695
'bob.near/profile/name',
9796
],
98-
rpcURL //rpc url for your network.
9997
}).then((result) => {
10098
console.log(result);
10199
/*
@@ -135,7 +133,6 @@ Getting specific values, like the example from above, you can use a set of keys:
135133
'alice.near/profile/image/url',
136134
'bob.near/profile/name',
137135
],
138-
rpcURL //rpc url for your network.
139136
});
140137

141138
console.log(result);
@@ -186,7 +183,6 @@ The [`get`](../api-reference/social#getoptions) function also supports wildcard
186183
keys: [
187184
'alice.near/profile/**',
188185
],
189-
rpcURL //rpc url for your network.
190186
});
191187

192188
console.log(result);
@@ -214,7 +210,6 @@ The [`get`](../api-reference/social#getoptions) function also supports wildcard
214210
keys: [
215211
'alice.near/profile/**',
216212
],
217-
rpcURL, //rpc url for your network.
218213
}).then((result) => {
219214
console.log(result);
220215
/*
@@ -243,7 +238,6 @@ The [`get`](../api-reference/social#getoptions) function also supports wildcard
243238
keys: [
244239
'alice.near/profile/**'
245240
],
246-
rpcURL, //rpc url for your network.
247241
});
248242

249243
console.log(result);

0 commit comments

Comments
 (0)