Skip to content

Commit a947e43

Browse files
okxwalletvanishcodezhelezkov
authored
Multi-chain Proposal (#12)
* feat: support evm * revert: twitter.tsx * feat: add actionCompatibility parameter * feat: op isCompatible fn parameter * fix: action type * proposal from nick(see latest comment) --------- Co-authored-by: vanishcode <[email protected]> Co-authored-by: Nick Zhelezkov <[email protected]>
1 parent 68eef97 commit a947e43

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

src/api/Action.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@ import type {
88
Parameter,
99
} from './actions-spec';
1010

11+
interface ActionMetadata {
12+
blockchainIds: string[];
13+
}
14+
1115
export class Action {
1216
private readonly _actions: ActionComponent[];
1317

1418
private constructor(
1519
private readonly _url: string,
1620
private readonly _data: ActionsSpecGetResponse,
21+
private readonly _metadata: ActionMetadata,
1722
private _adapter?: ActionAdapter,
1823
) {
1924
// if no links present, fallback to original solana pay spec
@@ -63,6 +68,10 @@ export class Action {
6368
return this._data.error?.message ?? null;
6469
}
6570

71+
public get metadata() {
72+
return this._metadata;
73+
}
74+
6675
public get adapter() {
6776
if (!this._adapter) {
6877
throw new Error('No adapter provided');
@@ -95,7 +104,16 @@ export class Action {
95104

96105
const data = (await response.json()) as ActionsSpecGetResponse;
97106

98-
return new Action(apiUrl, data, adapter);
107+
// for multi-chain x-blockchain-ids
108+
const blockchainIds = (
109+
response?.headers?.get('x-blockchain-ids') || ''
110+
).split(',');
111+
112+
const metadata: ActionMetadata = {
113+
blockchainIds,
114+
};
115+
116+
return new Action(apiUrl, data, metadata, adapter);
99117
}
100118
}
101119

src/api/ActionConfig.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export interface ActionAdapter {
2323
signature: string,
2424
context: ActionContext,
2525
) => Promise<void>;
26+
isSupported?: (
27+
context: Omit<ActionContext, 'triggeredLinkedAction'>,
28+
) => Promise<boolean>;
2629
}
2730

2831
export class ActionConfig implements ActionAdapter {

src/ext/twitter.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,23 @@ async function handleNewNode(
180180
return;
181181
}
182182

183-
const action = await Action.fetch(actionApiUrl, config).catch(() => null);
183+
const action = await Action.fetch(actionApiUrl, config).catch(noop);
184184

185185
if (!action) {
186186
return;
187187
}
188188

189+
if (config.isSupported) {
190+
const supported = await config.isSupported({
191+
originalUrl: actionUrl.toString(),
192+
action,
193+
actionType: state,
194+
});
195+
if (!supported) {
196+
return;
197+
}
198+
}
199+
189200
addMargin(container).replaceChildren(
190201
createAction({
191202
originalUrl: actionUrl,

src/ui/ActionContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ export const ActionContainer = ({
439439
image={action.icon}
440440
error={
441441
executionState.status !== 'success'
442-
? executionState.errorMessage ?? action.error
442+
? (executionState.errorMessage ?? action.error)
443443
: null
444444
}
445445
success={executionState.successMessage}

0 commit comments

Comments
 (0)