-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π Inject metadata into signer (#3872)
* New package * Update package * Introduce chainInfo into worker * Introduce update metadata button into the settings * Remove update button from settings * Check metadata before transaction * Test fix * Test fix * Keep the ApiRx compatibility * Move type definitions around * Fix some functions `Api` types * Fix the TransactionButton test suite * Minor fixes * Mock `injectweb3-connect` * Update `injectweb3-connect` * Test new `injectweb3-connect` build * Fix "Proxy object could not be cloned." * Fix the `chain-metadata` serialization * Remove `injectweb3-connect` archive * Update `injectweb3-connect` to `2.1.1` * Handle webp files in node_modules --------- Co-authored-by: Theophile Sandoz <theophile.sandoz@gmail.com>
- Loading branch information
Showing
18 changed files
with
171 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { getPolkadotApiChainInfo } from 'injectweb3-connect' | ||
|
||
import { Awaited } from '@/common/types/helpers' | ||
|
||
export type MetadataDef = Awaited<ReturnType<typeof getPolkadotApiChainInfo>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ApiRx } from '@polkadot/api' | ||
import { getPolkadotApiChainInfo } from 'injectweb3-connect' | ||
|
||
import { ProxyApi } from '@/proxyApi' | ||
|
||
import { MetadataDef } from '../types' | ||
|
||
export const getChainMetadata = async (api: ProxyApi | ApiRx): Promise<MetadataDef> => { | ||
if ('_async' in api) { | ||
return await api._async.chainMetadata | ||
} else { | ||
return await getPolkadotApiChainInfo(api) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ export const Settings = () => { | |
window.location.reload() | ||
} | ||
} | ||
|
||
return ( | ||
<Container> | ||
<PageLayout | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { filter, firstValueFrom, map, Observable } from 'rxjs' | ||
|
||
import { MetadataDef } from '@/api/types' | ||
|
||
import { deserializeMessage } from '../models/payload' | ||
import { PostMessage, RawWorkerMessageEvent } from '../types' | ||
|
||
export type ClientAsyncMessage = { | ||
messageType: 'chain-metadata' | ||
payload: undefined | ||
} | ||
|
||
export type WorkerAsyncMessage = { | ||
messageType: 'chain-metadata' | ||
payload: MetadataDef | ||
} | ||
|
||
export interface AsyncProps { | ||
chainMetadata: Promise<MetadataDef> | ||
} | ||
|
||
export const _async = ( | ||
messages: Observable<RawWorkerMessageEvent>, | ||
postMessage: PostMessage<ClientAsyncMessage> | ||
): AsyncProps => { | ||
let chainMetadata: Promise<MetadataDef> | ||
|
||
return { | ||
get chainMetadata(): Promise<MetadataDef> { | ||
if (!chainMetadata) chainMetadata = getAsync('chain-metadata') | ||
return chainMetadata | ||
}, | ||
} | ||
|
||
function getAsync(messageType: ClientAsyncMessage['messageType']): Promise<WorkerAsyncMessage['payload']> { | ||
postMessage({ messageType, payload: undefined }) | ||
return firstValueFrom( | ||
messages.pipe( | ||
filter(({ data }) => data.messageType === 'chain-metadata'), | ||
deserializeMessage<WorkerAsyncMessage>(), | ||
map(({ payload }) => payload) | ||
) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
7c4ffc2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
pioneer-2-storybook β ./
pioneer-2-storybook.vercel.app
pioneer-2-storybook-git-dev-joystream.vercel.app
pioneer-2-storybook-joystream.vercel.app
7c4ffc2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
pioneer-2 β ./
pioneer-2-joystream.vercel.app
pioneer-2.vercel.app
pioneer-2-git-dev-joystream.vercel.app