@polkahub/read-only 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/provider.js +6 -14
- package/dist/provider.js.map +1 -1
- package/dist/src/index.d.ts +6 -4
- package/package.json +3 -3
package/dist/provider.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { localStorageProvider, persistedState } from '@polkahub/plugin';
|
|
2
2
|
import { withDefault } from '@react-rxjs/core';
|
|
3
|
-
import {
|
|
4
|
-
import { getPolkadotSigner } from 'polkadot-api/signer';
|
|
3
|
+
import { getFakeTxCreator } from 'polkadot-api/tx-creator';
|
|
5
4
|
import { map } from 'rxjs';
|
|
6
5
|
|
|
7
6
|
const readOnlyProviderId = "readonly";
|
|
@@ -18,11 +17,14 @@ const createReadOnlyProvider = (opts) => {
|
|
|
18
17
|
const normalizeInfo = (value) => typeof value === "string" ? {
|
|
19
18
|
address: value
|
|
20
19
|
} : value;
|
|
21
|
-
const getAccount = ({
|
|
20
|
+
const getAccount = ({
|
|
21
|
+
address,
|
|
22
|
+
name
|
|
23
|
+
}) => ({
|
|
22
24
|
name,
|
|
23
25
|
provider: readOnlyProviderId,
|
|
24
26
|
address,
|
|
25
|
-
|
|
27
|
+
txCreator: fakeSigner ? getFakeTxCreator(address) : void 0
|
|
26
28
|
});
|
|
27
29
|
const accounts$ = persistedAccounts$.pipeState(
|
|
28
30
|
map((accounts) => accounts.map(normalizeInfo).map(getAccount)),
|
|
@@ -51,16 +53,6 @@ const createReadOnlyProvider = (opts) => {
|
|
|
51
53
|
})
|
|
52
54
|
};
|
|
53
55
|
};
|
|
54
|
-
const createFakeSigner = (address) => getPolkadotSigner(
|
|
55
|
-
address.startsWith("0x") ? Binary.fromHex(address) : AccountId().enc(address),
|
|
56
|
-
"Sr25519",
|
|
57
|
-
() => {
|
|
58
|
-
const signature = new Uint8Array(64);
|
|
59
|
-
signature.fill(205);
|
|
60
|
-
signature.set([222, 173, 190, 239]);
|
|
61
|
-
return signature;
|
|
62
|
-
}
|
|
63
|
-
);
|
|
64
56
|
|
|
65
57
|
export { createReadOnlyProvider, readOnlyProviderId };
|
|
66
58
|
//# sourceMappingURL=provider.js.map
|
package/dist/provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sources":["../src/provider.ts"],"sourcesContent":["import {\n Account,\n AccountAddress,\n localStorageProvider,\n persistedState,\n PersistenceProvider,\n Plugin,\n} from \"@polkahub/plugin\"\nimport { DefaultedStateObservable, withDefault } from \"@react-rxjs/core\"\nimport {
|
|
1
|
+
{"version":3,"file":"provider.js","sources":["../src/provider.ts"],"sourcesContent":["import {\n Account,\n AccountAddress,\n localStorageProvider,\n persistedState,\n PersistenceProvider,\n Plugin,\n} from \"@polkahub/plugin\"\nimport { DefaultedStateObservable, withDefault } from \"@react-rxjs/core\"\nimport { getFakeTxCreator, RawTxCreator } from \"polkadot-api/tx-creator\"\nimport { map } from \"rxjs\"\n\nexport interface ReadonlyAccountInfo {\n address: AccountAddress\n name?: string\n}\n\nexport const readOnlyProviderId = \"readonly\"\ntype ReadOnlyAccount = Account<RawTxCreator>\nexport interface ReadOnlyProvider extends Plugin<ReadOnlyAccount> {\n id: \"readonly\"\n accounts$: DefaultedStateObservable<ReadOnlyAccount[]>\n setAccounts: (payload: ReadonlyAccountInfo[]) => void\n addAccount: (address: ReadonlyAccountInfo) => ReadOnlyAccount\n removeAccount: (address: AccountAddress) => void\n toAccount: (address: AccountAddress) => ReadOnlyAccount\n}\n\nexport const createReadOnlyProvider = (\n opts?: Partial<{\n fakeSigner: boolean\n persist: PersistenceProvider\n }>,\n): ReadOnlyProvider => {\n const { fakeSigner, persist } = {\n fakeSigner: false,\n persist: localStorageProvider(\"readonly-accounts\"),\n ...opts,\n }\n\n const [persistedAccounts$, setPersistedAccounts] = persistedState(\n persist,\n [] as Array<AccountAddress> | Array<ReadonlyAccountInfo>,\n )\n const normalizeInfo = (\n value: AccountAddress | ReadonlyAccountInfo,\n ): ReadonlyAccountInfo =>\n typeof value === \"string\"\n ? {\n address: value,\n }\n : value\n\n const getAccount = ({\n address,\n name,\n }: ReadonlyAccountInfo): ReadOnlyAccount => ({\n name,\n provider: readOnlyProviderId,\n address,\n txCreator: fakeSigner ? getFakeTxCreator(address) : undefined,\n })\n\n const accounts$ = persistedAccounts$.pipeState(\n map((accounts) => accounts.map(normalizeInfo).map(getAccount)),\n withDefault([]),\n )\n\n return {\n id: readOnlyProviderId,\n deserialize: (acc) => getAccount(acc),\n accounts$,\n setAccounts: setPersistedAccounts,\n addAccount: (acc) => {\n setPersistedAccounts((v) => {\n const map = new Map(\n v.map(normalizeInfo).map((acc) => [acc.address, acc]),\n )\n map.set(acc.address, acc)\n return [...map.values()]\n })\n return getAccount(acc)\n },\n removeAccount: (addr) =>\n setPersistedAccounts(\n (v) =>\n v.filter((acc) => normalizeInfo(acc).address !== addr) as\n | ReadonlyAccountInfo[]\n | AccountAddress[],\n ),\n toAccount: (address) =>\n getAccount({\n address,\n }),\n }\n}\n"],"names":["map","acc"],"mappings":";;;;;AAiBO,MAAM,kBAAA,GAAqB;AAW3B,MAAM,sBAAA,GAAyB,CACpC,IAAA,KAIqB;AACrB,EAAA,MAAM,EAAE,UAAA,EAAY,OAAA,EAAQ,GAAI;AAAA,IAC9B,UAAA,EAAY,KAAA;AAAA,IACZ,OAAA,EAAS,qBAAqB,mBAAmB,CAAA;AAAA,IACjD,GAAG;AAAA,GACL;AAEA,EAAA,MAAM,CAAC,kBAAA,EAAoB,oBAAoB,CAAA,GAAI,cAAA;AAAA,IACjD,OAAA;AAAA,IACA;AAAC,GACH;AACA,EAAA,MAAM,aAAA,GAAgB,CACpB,KAAA,KAEA,OAAO,UAAU,QAAA,GACb;AAAA,IACE,OAAA,EAAS;AAAA,GACX,GACA,KAAA;AAEN,EAAA,MAAM,aAAa,CAAC;AAAA,IAClB,OAAA;AAAA,IACA;AAAA,GACF,MAA6C;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,KACD;AAAA,GACL;AACF;;;;"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
2
|
import { Plugin, Account, AccountAddress, PersistenceProvider } from '@polkahub/plugin';
|
|
3
3
|
import { DefaultedStateObservable } from '@react-rxjs/core';
|
|
4
|
+
import { RawTxCreator } from 'polkadot-api/tx-creator';
|
|
4
5
|
|
|
5
6
|
declare const ManageReadOnly: FC;
|
|
6
7
|
|
|
@@ -9,13 +10,14 @@ interface ReadonlyAccountInfo {
|
|
|
9
10
|
name?: string;
|
|
10
11
|
}
|
|
11
12
|
declare const readOnlyProviderId = "readonly";
|
|
12
|
-
|
|
13
|
+
type ReadOnlyAccount = Account<RawTxCreator>;
|
|
14
|
+
interface ReadOnlyProvider extends Plugin<ReadOnlyAccount> {
|
|
13
15
|
id: "readonly";
|
|
14
|
-
accounts$: DefaultedStateObservable<
|
|
16
|
+
accounts$: DefaultedStateObservable<ReadOnlyAccount[]>;
|
|
15
17
|
setAccounts: (payload: ReadonlyAccountInfo[]) => void;
|
|
16
|
-
addAccount: (address: ReadonlyAccountInfo) =>
|
|
18
|
+
addAccount: (address: ReadonlyAccountInfo) => ReadOnlyAccount;
|
|
17
19
|
removeAccount: (address: AccountAddress) => void;
|
|
18
|
-
toAccount: (address: AccountAddress) =>
|
|
20
|
+
toAccount: (address: AccountAddress) => ReadOnlyAccount;
|
|
19
21
|
}
|
|
20
22
|
declare const createReadOnlyProvider: (opts?: Partial<{
|
|
21
23
|
fakeSigner: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polkahub/read-only",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"author": "Victor Oliva (https://github.com/voliva)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"index.css"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@polkadot-api/substrate-bindings": "
|
|
32
|
+
"@polkadot-api/substrate-bindings": "0.21.0-rc.1",
|
|
33
33
|
"@polkahub/context": "^*",
|
|
34
34
|
"@polkahub/plugin": "^*",
|
|
35
35
|
"@polkahub/select-account": "^*",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@react-rxjs/core": "^0.10.8",
|
|
38
38
|
"@react-rxjs/utils": "^0.9.7",
|
|
39
39
|
"lucide-react": "^1.23.0",
|
|
40
|
-
"polkadot-api": "
|
|
40
|
+
"polkadot-api": "3.0.0-rc.4",
|
|
41
41
|
"rxjs": "^7.8.2"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|