Skip to content

Commit

Permalink
add example actions
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmbl committed Apr 11, 2024
1 parent 41ec318 commit 5ec9d40
Showing 1 changed file with 30 additions and 66 deletions.
96 changes: 30 additions & 66 deletions packages/blockchain-sdk-solana/examples/exmple-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,34 @@
// 1. Smart message should encapsulate all possible actions, including link and sign transaction - this is needed to be interoperable in different clients
// 2. Multiple actions should be later supported (e.g. both link and sign transaction), based on mockups e.g. https://www.figma.com/file/YMrtyevM6MlWYDZBO2fLb4/Use-Case-Examples?type=design&node-id=1-820&mode=dev
// 3. Single smart message should be produced if multiple actions exist, we should forbid using multiple tx-services in a context of single actionable notif
import { DappMessageActionType, type SmartMessageAction } from '@dialectlabs/sdk/src';
import { DappMessageActionType, type DappMessageSmartMessageAction } from '@dialectlabs/sdk/src';
import type { TensorNftBuySmartMessage } from '../../sdk-actions-spec';
import type { DappMessages } from '../../sdk/src/';
// @ts-ignore

const dappMessages = (1 as DappMessages);
const buyNftSmartMessage: SmartMessageAction = {
type: DappMessageActionType.SMART_MESSAGE,
smartMessage: {
transactionServiceId: 'tensor-nft-buy',
transactionParams: {
collectionId: 'foo',
mintAddress: 'bar',
owner: 'foo',
price: 'foo',
priceWithFeeAndRoyalty: 'foo',
},
const tensorSmartMessage: TensorNftBuySmartMessage = {
transactionServiceId: 'tensor-nft-buy',
transactionParams: {
collectionId: 'foo',
mintAddress: 'bar',
owner: 'foo',
price: 'foo',
priceWithFeeAndRoyalty: 'foo',
},

};
const tokenTransferSmartMessage: SmartMessageAction = {
const buyNftSmartMessage: DappMessageSmartMessageAction = {
type: DappMessageActionType.SMART_MESSAGE,
smartMessage: {
transactionServiceId: 'tensor-nft-buy',
transactionParams: {
collectionId: 'foo',
mintAddress: 'bar',
owner: 'foo',
price: 'foo',
priceWithFeeAndRoyalty: 'foo',
},
},
smartMessage: tensorSmartMessage,
};
// Examples:
// 1. SENDING SIGN_TRANSACTION ACTIONS, including possible multiple actions
// a) W/O TX_SERVICE_ID NOT ALLOWED
dappMessages.send({
actionsV3: {
actionsV2: {
type: DappMessageActionType.SMART_MESSAGE,
smartMessage: {
transactionServiceId: 'foo',
transactionParams: {
payer: 'foo',
payee: 'bar',
Expand All @@ -53,63 +42,38 @@ dappMessages.send({
},
},
message: 'foo',
recipient: 'dfs',
});
// b) multiple tx services not allowed
// b) SINGLE TX_SERVICE ID ALLOWED
dappMessages.send({
actionsV3: {
serviceId: 'foo',
actions: [
buyNftSmartMessage,
],
},
actionsV2: buyNftSmartMessage,
message: 'foo',
recipient: 'fds',
});
// d) SINGLE TX_SERVICE ID ALLOWED
dappMessages.send({
actionsV3: buyNftSmartMessage,
message: 'foo',
});dappMessages.send({
actionsV3: tokenTransferSmartMessage,
message: 'foo',
});


// 2. SENDING LINK ACTIONS
// a) MULTIPLE W/O TX_SERVICE_ID ARE NOT ALLOWED
dappMessages.send({
actionsV3: {
actions: [{
type: DappMessageActionType.LINK,
label: '',
url: 'd',
actionsV2: {
type: DappMessageActionType.LINK,
links: [{
label: 'foo',
url: 'foo',
}, {
type: DappMessageActionType.LINK,
label: '',
url: 'd',
}],
},
message: 'foo',
});// b) SINGLE link ALLOWED
dappMessages.send({
actionsV3: {
actions: [{
type: DappMessageActionType.LINK,
label: 'foo',
url: 'foo',
}],
},
recipients: ['sfd'],
message: 'foo',
});


// 3. SENDING MIXED ACTIONS
});// b) SINGLE link ALLOWED
dappMessages.send({
actionsV3: {
actions: [{
type: DappMessageActionType.LINK,
actionsV2: {
type: DappMessageActionType.LINK,
links: [{
label: 'foo',
url: 'foo',
}],
},
recipients: ['sfd'],
message: 'foo',
});
});// b) SINGLE link ALLOWED

0 comments on commit 5ec9d40

Please sign in to comment.