-
Notifications
You must be signed in to change notification settings - Fork 5
/
Example.tsx
83 lines (77 loc) · 2.08 KB
/
Example.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import {
Blink,
BlockchainIds,
createSignMessageText,
Miniblink,
useAction,
type ActionAdapter,
type SignMessageData,
} from '@dialectlabs/blinks-react-native';
import { PublicKey } from '@solana/web3.js';
import type React from 'react';
import { ActivityIndicator } from 'react-native';
function getWalletAdapter(): ActionAdapter {
return {
connect: async (_context) => {
console.log('connect');
return PublicKey.default.toString();
},
signTransaction: async (_tx, _context) => {
console.log('signTransaction');
return {
signature: 'signature',
};
},
signMessage: async (message: string | SignMessageData, _context) => {
const messageToSign =
typeof message === 'string' ? message : createSignMessageText(message);
console.log('signMessage', messageToSign);
return { signature: 'signature' };
},
confirmTransaction: async (_signature, _context) => {
console.log('confirmTransaction');
},
metadata: { supportedBlockchainIds: [BlockchainIds.SOLANA_MAINNET] },
};
}
export const BlinkExample: React.FC<{
url: string; // could be action api or website url
}> = ({ url }) => {
const adapter = getWalletAdapter();
const { action } = useAction({ url });
if (!action) {
return <ActivityIndicator />;
}
const actionUrl = new URL(url);
return (
<Blink
theme={{
'--blink-button': '#1D9BF0',
'--blink-border-radius-rounded-button': 9999,
'--blink-spacing-input-height': 44,
}}
action={action}
adapter={adapter}
websiteUrl={actionUrl.href}
websiteText={actionUrl.hostname}
/>
);
};
export const MiniblinkExample: React.FC<{
url: string; // could be action api or website url
}> = ({ url }) => {
const adapter = getWalletAdapter();
const { action } = useAction({ url });
if (!action) {
return <ActivityIndicator />;
}
return (
<Miniblink
action={action}
adapter={adapter}
selector={(currentAction) =>
currentAction.actions.find((a) => a.label === 'Donate')!
}
/>
);
};