@worldcoin/minikit-js 1.9.4 → 1.9.6
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/build/{chunk-VOZXVH3R.js → chunk-DKXMTG56.js} +448 -268
- package/build/index.cjs +442 -260
- package/build/index.d.cts +83 -35
- package/build/index.d.ts +83 -35
- package/build/index.js +5 -1
- package/build/minikit-provider.cjs +249 -82
- package/build/minikit-provider.d.cts +1 -1
- package/build/minikit-provider.d.ts +1 -1
- package/build/minikit-provider.js +8 -5
- package/index.ts +1 -1
- package/package.json +1 -1
|
@@ -31,12 +31,120 @@ var import_react = require("react");
|
|
|
31
31
|
var import_idkit_core3 = require("@worldcoin/idkit-core");
|
|
32
32
|
var import_hashing = require("@worldcoin/idkit-core/hashing");
|
|
33
33
|
|
|
34
|
+
// helpers/send-webview-event.ts
|
|
35
|
+
var sendWebviewEvent = (payload) => {
|
|
36
|
+
if (window.webkit) {
|
|
37
|
+
window.webkit?.messageHandlers?.minikit?.postMessage?.(payload);
|
|
38
|
+
} else if (window.Android) {
|
|
39
|
+
window.Android.postMessage?.(JSON.stringify(payload));
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// types/errors.ts
|
|
44
|
+
var import_idkit_core = require("@worldcoin/idkit-core");
|
|
45
|
+
var import_idkit_core2 = require("@worldcoin/idkit-core");
|
|
46
|
+
var VerificationErrorMessage = {
|
|
47
|
+
[import_idkit_core.AppErrorCodes.VerificationRejected]: "You've cancelled the request in World App.",
|
|
48
|
+
[import_idkit_core.AppErrorCodes.MaxVerificationsReached]: "You have already verified the maximum number of times for this action.",
|
|
49
|
+
[import_idkit_core.AppErrorCodes.CredentialUnavailable]: "It seems you do not have the verification level required by this app.",
|
|
50
|
+
[import_idkit_core.AppErrorCodes.MalformedRequest]: "There was a problem with this request. Please try again or contact the app owner.",
|
|
51
|
+
[import_idkit_core.AppErrorCodes.InvalidNetwork]: "Invalid network. If you are the app owner, visit docs.worldcoin.org/test for details.",
|
|
52
|
+
[import_idkit_core.AppErrorCodes.InclusionProofFailed]: "There was an issue fetching your credential. Please try again.",
|
|
53
|
+
[import_idkit_core.AppErrorCodes.InclusionProofPending]: "Your identity is still being registered. Please wait a few minutes and try again.",
|
|
54
|
+
[import_idkit_core.AppErrorCodes.UnexpectedResponse]: "Unexpected response from your wallet. Please try again.",
|
|
55
|
+
[import_idkit_core.AppErrorCodes.FailedByHostApp]: "Verification failed by the app. Please contact the app owner for details.",
|
|
56
|
+
[import_idkit_core.AppErrorCodes.GenericError]: "Something unexpected went wrong. Please try again.",
|
|
57
|
+
[import_idkit_core.AppErrorCodes.ConnectionFailed]: "Connection to your wallet failed. Please try again."
|
|
58
|
+
};
|
|
59
|
+
var MiniKitInstallErrorMessage = {
|
|
60
|
+
["unknown" /* Unknown */]: "Failed to install MiniKit.",
|
|
61
|
+
["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
|
|
62
|
+
["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
|
|
63
|
+
["not_on_client" /* NotOnClient */]: "Window object is not available.",
|
|
64
|
+
["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// helpers/microphone/index.ts
|
|
68
|
+
var microphoneSetupDone = false;
|
|
69
|
+
var setupMicrophone = () => {
|
|
70
|
+
if (microphoneSetupDone) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (typeof navigator !== "undefined" && !navigator.mediaDevices?.getUserMedia)
|
|
74
|
+
return;
|
|
75
|
+
const originalStop = MediaStreamTrack.prototype.stop;
|
|
76
|
+
MediaStreamTrack.prototype.stop = function() {
|
|
77
|
+
originalStop.call(this);
|
|
78
|
+
if (this.readyState === "ended") {
|
|
79
|
+
setTimeout(() => this.dispatchEvent(new Event("ended")), 0);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const realGUM = navigator.mediaDevices.getUserMedia.bind(
|
|
83
|
+
navigator.mediaDevices
|
|
84
|
+
);
|
|
85
|
+
const live = /* @__PURE__ */ new Set();
|
|
86
|
+
async function wrapped(constraints) {
|
|
87
|
+
const stream = await realGUM(constraints);
|
|
88
|
+
sendWebviewEvent({
|
|
89
|
+
command: "microphone-stream-started",
|
|
90
|
+
version: 1,
|
|
91
|
+
payload: {
|
|
92
|
+
streamId: stream.id
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
live.add(stream);
|
|
96
|
+
stream.getTracks().forEach((t) => {
|
|
97
|
+
t.addEventListener("ended", () => {
|
|
98
|
+
sendWebviewEvent({
|
|
99
|
+
command: "microphone-stream-ended",
|
|
100
|
+
version: 1,
|
|
101
|
+
payload: {
|
|
102
|
+
streamId: stream.id
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
live.delete(stream);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
return stream;
|
|
109
|
+
}
|
|
110
|
+
Object.defineProperty(navigator.mediaDevices, "getUserMedia", {
|
|
111
|
+
value: wrapped,
|
|
112
|
+
writable: false,
|
|
113
|
+
configurable: false,
|
|
114
|
+
enumerable: true
|
|
115
|
+
});
|
|
116
|
+
Object.freeze(navigator.mediaDevices);
|
|
117
|
+
const stopAllMiniAppMicrophoneStreams = () => {
|
|
118
|
+
live.forEach((s) => {
|
|
119
|
+
s.getTracks().forEach((t) => {
|
|
120
|
+
t.stop();
|
|
121
|
+
sendWebviewEvent({
|
|
122
|
+
command: "microphone-stream-ended",
|
|
123
|
+
version: 1,
|
|
124
|
+
payload: {
|
|
125
|
+
streamId: s.id
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
live.clear();
|
|
131
|
+
};
|
|
132
|
+
MiniKit.subscribe("miniapp-microphone" /* MiniAppMicrophone */, (payload) => {
|
|
133
|
+
if (payload.status === "error" && (payload.error_code === "mini_app_permission_not_enabled" /* MiniAppPermissionNotEnabled */ || payload.error_code === "world_app_permission_not_enabled" /* WorldAppPermissionNotEnabled */)) {
|
|
134
|
+
console.log("stopping all microphone streams", payload);
|
|
135
|
+
stopAllMiniAppMicrophoneStreams();
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
window.__stopAllMiniAppMicrophoneStreams = stopAllMiniAppMicrophoneStreams;
|
|
139
|
+
microphoneSetupDone = true;
|
|
140
|
+
};
|
|
141
|
+
|
|
34
142
|
// helpers/payment/client.ts
|
|
35
143
|
var validatePaymentPayload = (payload) => {
|
|
36
144
|
if (payload.tokens.some(
|
|
37
|
-
(token) => token.symbol == "USDCE" && parseFloat(token.token_amount) < 0.1
|
|
145
|
+
(token) => token.symbol == "USDCE" /* USDC */ && parseFloat(token.token_amount) < 0.1
|
|
38
146
|
)) {
|
|
39
|
-
console.error("
|
|
147
|
+
console.error("USDC amount should be greater than $0.1");
|
|
40
148
|
return false;
|
|
41
149
|
}
|
|
42
150
|
if (payload.reference.length > 36) {
|
|
@@ -99,6 +207,72 @@ var compressAndPadProof = async (proof, rpcUrl) => {
|
|
|
99
207
|
}
|
|
100
208
|
};
|
|
101
209
|
|
|
210
|
+
// helpers/share/index.ts
|
|
211
|
+
var MAX_FILES = 10;
|
|
212
|
+
var MAX_TOTAL_SIZE_MB = 50;
|
|
213
|
+
var MAX_TOTAL_SIZE_BYTES = MAX_TOTAL_SIZE_MB * 1024 * 1024;
|
|
214
|
+
var processFile = async (file) => {
|
|
215
|
+
const buffer = await file.arrayBuffer();
|
|
216
|
+
const uint8Array = new Uint8Array(buffer);
|
|
217
|
+
let binaryString = "";
|
|
218
|
+
const K_CHUNK_SIZE = 32768;
|
|
219
|
+
for (let i = 0; i < uint8Array.length; i += K_CHUNK_SIZE) {
|
|
220
|
+
const chunk = uint8Array.subarray(
|
|
221
|
+
i,
|
|
222
|
+
Math.min(i + K_CHUNK_SIZE, uint8Array.length)
|
|
223
|
+
);
|
|
224
|
+
binaryString += String.fromCharCode.apply(
|
|
225
|
+
null,
|
|
226
|
+
Array.from(chunk)
|
|
227
|
+
// Convert Uint8Array chunk to number[]
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
const base64Data = btoa(binaryString);
|
|
231
|
+
return {
|
|
232
|
+
name: file.name,
|
|
233
|
+
type: file.type,
|
|
234
|
+
data: base64Data
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
var formatShareInput = async (input) => {
|
|
238
|
+
if (!input.files) {
|
|
239
|
+
return {
|
|
240
|
+
title: input.title,
|
|
241
|
+
text: input.text,
|
|
242
|
+
url: input.url
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
if (!Array.isArray(input.files)) {
|
|
246
|
+
throw new Error('The "files" property must be an array.');
|
|
247
|
+
}
|
|
248
|
+
if (input.files.length === 0) {
|
|
249
|
+
} else {
|
|
250
|
+
if (input.files.length > MAX_FILES) {
|
|
251
|
+
throw new Error(`Cannot share more than ${MAX_FILES} files.`);
|
|
252
|
+
}
|
|
253
|
+
let totalSize = 0;
|
|
254
|
+
for (const file of input.files) {
|
|
255
|
+
if (!(file instanceof File)) {
|
|
256
|
+
throw new Error(
|
|
257
|
+
`Each item in the 'files' array must be a File object. Received: ${typeof file}`
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
totalSize += file.size;
|
|
261
|
+
}
|
|
262
|
+
if (totalSize > MAX_TOTAL_SIZE_BYTES) {
|
|
263
|
+
throw new Error(`Total file size cannot exceed ${MAX_TOTAL_SIZE_MB}MB.`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const fileProcessingPromises = input.files.map((file) => processFile(file));
|
|
267
|
+
const processedFiles = await Promise.all(fileProcessingPromises);
|
|
268
|
+
return {
|
|
269
|
+
files: processedFiles,
|
|
270
|
+
title: input.title,
|
|
271
|
+
text: input.text,
|
|
272
|
+
url: input.url
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
|
|
102
276
|
// helpers/siwe/siwe.ts
|
|
103
277
|
var import_viem2 = require("viem");
|
|
104
278
|
var import_chains2 = require("viem/chains");
|
|
@@ -250,39 +424,6 @@ var getUserProfile = async (address) => {
|
|
|
250
424
|
return usernames?.[0] ?? { username: null, profile_picture_url: null };
|
|
251
425
|
};
|
|
252
426
|
|
|
253
|
-
// types/errors.ts
|
|
254
|
-
var import_idkit_core = require("@worldcoin/idkit-core");
|
|
255
|
-
var import_idkit_core2 = require("@worldcoin/idkit-core");
|
|
256
|
-
var VerificationErrorMessage = {
|
|
257
|
-
[import_idkit_core.AppErrorCodes.VerificationRejected]: "You've cancelled the request in World App.",
|
|
258
|
-
[import_idkit_core.AppErrorCodes.MaxVerificationsReached]: "You have already verified the maximum number of times for this action.",
|
|
259
|
-
[import_idkit_core.AppErrorCodes.CredentialUnavailable]: "It seems you do not have the verification level required by this app.",
|
|
260
|
-
[import_idkit_core.AppErrorCodes.MalformedRequest]: "There was a problem with this request. Please try again or contact the app owner.",
|
|
261
|
-
[import_idkit_core.AppErrorCodes.InvalidNetwork]: "Invalid network. If you are the app owner, visit docs.worldcoin.org/test for details.",
|
|
262
|
-
[import_idkit_core.AppErrorCodes.InclusionProofFailed]: "There was an issue fetching your credential. Please try again.",
|
|
263
|
-
[import_idkit_core.AppErrorCodes.InclusionProofPending]: "Your identity is still being registered. Please wait a few minutes and try again.",
|
|
264
|
-
[import_idkit_core.AppErrorCodes.UnexpectedResponse]: "Unexpected response from your wallet. Please try again.",
|
|
265
|
-
[import_idkit_core.AppErrorCodes.FailedByHostApp]: "Verification failed by the app. Please contact the app owner for details.",
|
|
266
|
-
[import_idkit_core.AppErrorCodes.GenericError]: "Something unexpected went wrong. Please try again.",
|
|
267
|
-
[import_idkit_core.AppErrorCodes.ConnectionFailed]: "Connection to your wallet failed. Please try again."
|
|
268
|
-
};
|
|
269
|
-
var MiniKitInstallErrorMessage = {
|
|
270
|
-
["unknown" /* Unknown */]: "Failed to install MiniKit.",
|
|
271
|
-
["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
|
|
272
|
-
["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
|
|
273
|
-
["not_on_client" /* NotOnClient */]: "Window object is not available.",
|
|
274
|
-
["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
// helpers/send-webview-event.ts
|
|
278
|
-
var sendWebviewEvent = (payload) => {
|
|
279
|
-
if (window.webkit) {
|
|
280
|
-
window.webkit?.messageHandlers?.minikit?.postMessage?.(payload);
|
|
281
|
-
} else if (window.Android) {
|
|
282
|
-
window.Android.postMessage?.(JSON.stringify(payload));
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
|
|
286
427
|
// minikit.ts
|
|
287
428
|
var sendMiniKitEvent = (payload) => {
|
|
288
429
|
sendWebviewEvent(payload);
|
|
@@ -291,7 +432,10 @@ var _MiniKit = class _MiniKit {
|
|
|
291
432
|
static sendInit() {
|
|
292
433
|
sendWebviewEvent({
|
|
293
434
|
command: "init",
|
|
294
|
-
payload: {
|
|
435
|
+
payload: {
|
|
436
|
+
version: this.MINIKIT_VERSION,
|
|
437
|
+
minorVersion: this.MINIKIT_MINOR_VERSION
|
|
438
|
+
}
|
|
295
439
|
});
|
|
296
440
|
}
|
|
297
441
|
static subscribe(event, handler) {
|
|
@@ -406,6 +550,9 @@ var _MiniKit = class _MiniKit {
|
|
|
406
550
|
_MiniKit.user.optedIntoOptionalAnalytics = window.WorldApp.is_optional_analytics;
|
|
407
551
|
_MiniKit.user.deviceOS = window.WorldApp.device_os;
|
|
408
552
|
_MiniKit.user.worldAppVersion = window.WorldApp.world_app_version;
|
|
553
|
+
_MiniKit.deviceProperties.safeAreaInsets = window.WorldApp.safe_area_insets;
|
|
554
|
+
_MiniKit.deviceProperties.deviceOS = window.WorldApp.device_os;
|
|
555
|
+
_MiniKit.deviceProperties.worldAppVersion = window.WorldApp.world_app_version;
|
|
409
556
|
try {
|
|
410
557
|
window.MiniKit = _MiniKit;
|
|
411
558
|
this.sendInit();
|
|
@@ -421,6 +568,7 @@ var _MiniKit = class _MiniKit {
|
|
|
421
568
|
};
|
|
422
569
|
}
|
|
423
570
|
_MiniKit.isReady = true;
|
|
571
|
+
setupMicrophone();
|
|
424
572
|
if (!this.commandsValid(window.WorldApp.supported_commands)) {
|
|
425
573
|
return {
|
|
426
574
|
success: false,
|
|
@@ -441,6 +589,7 @@ var _MiniKit = class _MiniKit {
|
|
|
441
589
|
}
|
|
442
590
|
};
|
|
443
591
|
_MiniKit.MINIKIT_VERSION = 1;
|
|
592
|
+
_MiniKit.MINIKIT_MINOR_VERSION = 96;
|
|
444
593
|
_MiniKit.miniKitCommandVersion = {
|
|
445
594
|
["verify" /* Verify */]: 1,
|
|
446
595
|
["pay" /* Pay */]: 1,
|
|
@@ -451,8 +600,8 @@ _MiniKit.miniKitCommandVersion = {
|
|
|
451
600
|
["share-contacts" /* ShareContacts */]: 1,
|
|
452
601
|
["request-permission" /* RequestPermission */]: 1,
|
|
453
602
|
["get-permissions" /* GetPermissions */]: 1,
|
|
454
|
-
["send-haptic-feedback" /* SendHapticFeedback */]: 1
|
|
455
|
-
|
|
603
|
+
["send-haptic-feedback" /* SendHapticFeedback */]: 1,
|
|
604
|
+
["share" /* Share */]: 1
|
|
456
605
|
};
|
|
457
606
|
_MiniKit.isCommandAvailable = {
|
|
458
607
|
["verify" /* Verify */]: false,
|
|
@@ -464,8 +613,8 @@ _MiniKit.isCommandAvailable = {
|
|
|
464
613
|
["share-contacts" /* ShareContacts */]: false,
|
|
465
614
|
["request-permission" /* RequestPermission */]: false,
|
|
466
615
|
["get-permissions" /* GetPermissions */]: false,
|
|
467
|
-
["send-haptic-feedback" /* SendHapticFeedback */]: false
|
|
468
|
-
|
|
616
|
+
["send-haptic-feedback" /* SendHapticFeedback */]: false,
|
|
617
|
+
["share" /* Share */]: false
|
|
469
618
|
};
|
|
470
619
|
_MiniKit.listeners = {
|
|
471
620
|
["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
|
|
@@ -488,12 +637,15 @@ _MiniKit.listeners = {
|
|
|
488
637
|
},
|
|
489
638
|
["miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */]: () => {
|
|
490
639
|
},
|
|
491
|
-
["miniapp-share
|
|
640
|
+
["miniapp-share" /* MiniAppShare */]: () => {
|
|
641
|
+
},
|
|
642
|
+
["miniapp-microphone" /* MiniAppMicrophone */]: () => {
|
|
492
643
|
}
|
|
493
644
|
};
|
|
494
645
|
_MiniKit.appId = null;
|
|
495
646
|
_MiniKit.user = {};
|
|
496
647
|
_MiniKit.isReady = false;
|
|
648
|
+
_MiniKit.deviceProperties = {};
|
|
497
649
|
_MiniKit.getUserByAddress = async (address) => {
|
|
498
650
|
const userProfile = await getUserProfile(
|
|
499
651
|
address ?? _MiniKit.user.walletAddress
|
|
@@ -659,7 +811,7 @@ _MiniKit.commands = {
|
|
|
659
811
|
return payload;
|
|
660
812
|
},
|
|
661
813
|
shareContacts: (payload) => {
|
|
662
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["
|
|
814
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["share-contacts" /* ShareContacts */]) {
|
|
663
815
|
console.error(
|
|
664
816
|
"'shareContacts' command is unavailable. Check MiniKit.install() or update the app version"
|
|
665
817
|
);
|
|
@@ -715,24 +867,38 @@ _MiniKit.commands = {
|
|
|
715
867
|
payload
|
|
716
868
|
});
|
|
717
869
|
return payload;
|
|
870
|
+
},
|
|
871
|
+
// We return share input here because the payload is formatted asynchronously
|
|
872
|
+
share: (payload) => {
|
|
873
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["share" /* Share */]) {
|
|
874
|
+
console.error(
|
|
875
|
+
"'share' command is unavailable. Check MiniKit.install() or update the app version"
|
|
876
|
+
);
|
|
877
|
+
return null;
|
|
878
|
+
}
|
|
879
|
+
if (_MiniKit.deviceProperties.deviceOS === "ios" && typeof navigator !== "undefined") {
|
|
880
|
+
sendMiniKitEvent({
|
|
881
|
+
command: "share" /* Share */,
|
|
882
|
+
version: _MiniKit.miniKitCommandVersion["share" /* Share */],
|
|
883
|
+
payload
|
|
884
|
+
});
|
|
885
|
+
navigator.share(payload);
|
|
886
|
+
} else {
|
|
887
|
+
formatShareInput(payload).then((formattedResult) => {
|
|
888
|
+
sendMiniKitEvent({
|
|
889
|
+
command: "share" /* Share */,
|
|
890
|
+
version: _MiniKit.miniKitCommandVersion["share" /* Share */],
|
|
891
|
+
payload: formattedResult
|
|
892
|
+
});
|
|
893
|
+
}).catch((error) => {
|
|
894
|
+
console.error("Failed to format share input", error);
|
|
895
|
+
});
|
|
896
|
+
_MiniKit.subscribe("miniapp-share" /* MiniAppShare */, (payload2) => {
|
|
897
|
+
console.log("Share Response", payload2);
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
return payload;
|
|
718
901
|
}
|
|
719
|
-
// shareFiles: (payload: ShareFilesInput): ShareFilesPayload | null => {
|
|
720
|
-
// if (
|
|
721
|
-
// typeof window === 'undefined' ||
|
|
722
|
-
// !this.isCommandAvailable[Command.ShareFiles]
|
|
723
|
-
// ) {
|
|
724
|
-
// console.error(
|
|
725
|
-
// "'shareFiles' command is unavailable. Check MiniKit.install() or update the app version",
|
|
726
|
-
// );
|
|
727
|
-
// return null;
|
|
728
|
-
// }
|
|
729
|
-
// sendMiniKitEvent<WebViewBasePayload>({
|
|
730
|
-
// command: Command.ShareFiles,
|
|
731
|
-
// version: this.miniKitCommandVersion[Command.ShareFiles],
|
|
732
|
-
// payload,
|
|
733
|
-
// });
|
|
734
|
-
// return payload;
|
|
735
|
-
// },
|
|
736
902
|
};
|
|
737
903
|
/**
|
|
738
904
|
* This object contains async versions of all the commands.
|
|
@@ -889,41 +1055,42 @@ _MiniKit.commandsAsync = {
|
|
|
889
1055
|
reject(error);
|
|
890
1056
|
}
|
|
891
1057
|
});
|
|
1058
|
+
},
|
|
1059
|
+
share: async (payload) => {
|
|
1060
|
+
return new Promise(async (resolve, reject) => {
|
|
1061
|
+
try {
|
|
1062
|
+
const response = await _MiniKit.awaitCommand(
|
|
1063
|
+
"miniapp-share" /* MiniAppShare */,
|
|
1064
|
+
"share" /* Share */,
|
|
1065
|
+
() => _MiniKit.commands.share(payload)
|
|
1066
|
+
);
|
|
1067
|
+
resolve({
|
|
1068
|
+
commandPayload: response.commandPayload,
|
|
1069
|
+
finalPayload: response.finalPayload
|
|
1070
|
+
});
|
|
1071
|
+
} catch (error) {
|
|
1072
|
+
reject(error);
|
|
1073
|
+
}
|
|
1074
|
+
});
|
|
892
1075
|
}
|
|
893
|
-
// shareFiles: async (
|
|
894
|
-
// payload: ShareFilesInput,
|
|
895
|
-
// ): AsyncHandlerReturn<
|
|
896
|
-
// ShareFilesPayload | null,
|
|
897
|
-
// MiniAppShareFilesPayload
|
|
898
|
-
// > => {
|
|
899
|
-
// return new Promise(async (resolve, reject) => {
|
|
900
|
-
// try {
|
|
901
|
-
// const response = await MiniKit.awaitCommand(
|
|
902
|
-
// ResponseEvent.MiniAppShareFiles,
|
|
903
|
-
// Command.ShareFiles,
|
|
904
|
-
// () => this.commands.shareFiles(payload),
|
|
905
|
-
// );
|
|
906
|
-
// resolve(response);
|
|
907
|
-
// } catch (error) {
|
|
908
|
-
// reject(error);
|
|
909
|
-
// }
|
|
910
|
-
// });
|
|
911
|
-
// },
|
|
912
1076
|
};
|
|
913
1077
|
var MiniKit = _MiniKit;
|
|
914
1078
|
|
|
915
1079
|
// minikit-provider.tsx
|
|
916
1080
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
917
1081
|
var MiniKitContext = (0, import_react.createContext)({
|
|
918
|
-
isInstalled:
|
|
1082
|
+
isInstalled: void 0
|
|
919
1083
|
});
|
|
920
1084
|
var MiniKitProvider = ({
|
|
921
1085
|
children,
|
|
922
1086
|
props
|
|
923
1087
|
}) => {
|
|
924
|
-
const [isInstalled, setIsInstalled] = (0, import_react.useState)(
|
|
1088
|
+
const [isInstalled, setIsInstalled] = (0, import_react.useState)(
|
|
1089
|
+
void 0
|
|
1090
|
+
);
|
|
925
1091
|
(0, import_react.useEffect)(() => {
|
|
926
|
-
MiniKit.install(props?.appId);
|
|
1092
|
+
const { success } = MiniKit.install(props?.appId);
|
|
1093
|
+
if (!success) return setIsInstalled(false);
|
|
927
1094
|
MiniKit.commandsAsync.getPermissions().then(({ commandPayload: _, finalPayload }) => {
|
|
928
1095
|
if (finalPayload.status === "success") {
|
|
929
1096
|
MiniKit.user.permissions = {
|
|
@@ -932,7 +1099,7 @@ var MiniKitProvider = ({
|
|
|
932
1099
|
};
|
|
933
1100
|
}
|
|
934
1101
|
});
|
|
935
|
-
setIsInstalled(
|
|
1102
|
+
setIsInstalled(success);
|
|
936
1103
|
}, [props?.appId]);
|
|
937
1104
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MiniKitContext.Provider, { value: { isInstalled }, children });
|
|
938
1105
|
};
|
|
@@ -9,7 +9,7 @@ declare const MiniKitProvider: ({ children, props, }: {
|
|
|
9
9
|
props?: MiniKitProps;
|
|
10
10
|
}) => react_jsx_runtime.JSX.Element;
|
|
11
11
|
declare const useMiniKit: () => {
|
|
12
|
-
isInstalled: boolean;
|
|
12
|
+
isInstalled: boolean | undefined;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export { MiniKitProvider, useMiniKit };
|
|
@@ -9,7 +9,7 @@ declare const MiniKitProvider: ({ children, props, }: {
|
|
|
9
9
|
props?: MiniKitProps;
|
|
10
10
|
}) => react_jsx_runtime.JSX.Element;
|
|
11
11
|
declare const useMiniKit: () => {
|
|
12
|
-
isInstalled: boolean;
|
|
12
|
+
isInstalled: boolean | undefined;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export { MiniKitProvider, useMiniKit };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
MiniKit
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-DKXMTG56.js";
|
|
5
5
|
|
|
6
6
|
// minikit-provider.tsx
|
|
7
7
|
import {
|
|
@@ -12,15 +12,18 @@ import {
|
|
|
12
12
|
} from "react";
|
|
13
13
|
import { jsx } from "react/jsx-runtime";
|
|
14
14
|
var MiniKitContext = createContext({
|
|
15
|
-
isInstalled:
|
|
15
|
+
isInstalled: void 0
|
|
16
16
|
});
|
|
17
17
|
var MiniKitProvider = ({
|
|
18
18
|
children,
|
|
19
19
|
props
|
|
20
20
|
}) => {
|
|
21
|
-
const [isInstalled, setIsInstalled] = useState(
|
|
21
|
+
const [isInstalled, setIsInstalled] = useState(
|
|
22
|
+
void 0
|
|
23
|
+
);
|
|
22
24
|
useEffect(() => {
|
|
23
|
-
MiniKit.install(props?.appId);
|
|
25
|
+
const { success } = MiniKit.install(props?.appId);
|
|
26
|
+
if (!success) return setIsInstalled(false);
|
|
24
27
|
MiniKit.commandsAsync.getPermissions().then(({ commandPayload: _, finalPayload }) => {
|
|
25
28
|
if (finalPayload.status === "success") {
|
|
26
29
|
MiniKit.user.permissions = {
|
|
@@ -29,7 +32,7 @@ var MiniKitProvider = ({
|
|
|
29
32
|
};
|
|
30
33
|
}
|
|
31
34
|
});
|
|
32
|
-
setIsInstalled(
|
|
35
|
+
setIsInstalled(success);
|
|
33
36
|
}, [props?.appId]);
|
|
34
37
|
return /* @__PURE__ */ jsx(MiniKitContext.Provider, { value: { isInstalled }, children });
|
|
35
38
|
};
|
package/index.ts
CHANGED
|
@@ -2,9 +2,9 @@ export { MiniKit } from './minikit';
|
|
|
2
2
|
|
|
3
3
|
export * from './types/commands';
|
|
4
4
|
export * from './types/errors';
|
|
5
|
+
export * from './types/init';
|
|
5
6
|
export * from './types/payment';
|
|
6
7
|
export * from './types/responses';
|
|
7
|
-
export * from './types/user';
|
|
8
8
|
export * from './types/wallet-auth';
|
|
9
9
|
|
|
10
10
|
export { tokenToDecimals } from 'helpers/payment/client';
|