Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ Wallet.canAddPasses(added => {
// Handle rest
});

/**
* Check if you have any passes.
* @param callback A callback which will receive an error or the pass serials
*/
Wallet.passes((err, passes) => {
// Handle rest
});

/**
* Show the pass controller for the provided URL.
* The resolving promise will contain a boolean saying if the pass was added or not.
Expand Down
12 changes: 12 additions & 0 deletions ios/RNWalletModule/RNWalletModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ @implementation RNWalletModule
callback(@[@([PKAddPassesViewController canAddPasses])]);
}

RCT_EXPORT_METHOD(
passes:(RCTResponseSenderBlock)callback
) {
self.passLibrary = [[PKPassLibrary alloc] init];
NSArray *passes = [self.passLibrary passes];

NSDictionary *dict = [NSDictionary dictionaryWithObjects:passes forKeys:[passes valueForKey:@"serialNumber"]];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel this is very readable

NSArray*serials=[dict allKeys];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you're trying to reduce an array of passes to an array of serialnumbers?


callback(@[[NSNull null], serials]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use the Node convention of passing null instead on an error in this project.
Either use a callback for a call that always succeeds or us a promise :)

}

RCT_EXPORT_METHOD(
showAddPassControllerFromFile:(NSString *)filepath
resolver:(RCTPromiseResolveBlock)resolve
Expand Down
22 changes: 16 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { NativeModules } from 'react-native';
const { RNWalletModule } = NativeModules;
import { _canAddPasses, _showAddPassControllerFromURL, _showAddPassControllerFromFile } from './platform-specific';
import { NativeModules } from 'react-native'
import {
_canAddPasses,
_showAddPassControllerFromURL,
_showAddPassControllerFromFile,
_passes
} from './platform-specific'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Respecting the print line 🕺

const { RNWalletModule } = NativeModules

/**
* Check if you can add passes.
Expand All @@ -17,7 +22,7 @@ function canAddPasses(callback) {
* @return Promise Passing a boolean
*/
function showAddPassControllerFromURL(passURL) {
return _showAddPassControllerFromURL(RNWalletModule, passURL);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤨
I guess what I want to say is: Don't change someone's code style in a PR?

return _showAddPassControllerFromURL(RNWalletModule, passURL)
}

/**
Expand All @@ -27,11 +32,16 @@ function showAddPassControllerFromURL(passURL) {
* @return Promise Passing a boolean
*/
function showAddPassControllerFromFile(filepath) {
return _showAddPassControllerFromFile(RNWalletModule, filepath);
return _showAddPassControllerFromFile(RNWalletModule, filepath)
}

function passes(callback) {
_passes(RNWalletModule, callback)
}

module.exports = {
canAddPasses,
showAddPassControllerFromURL,
showAddPassControllerFromFile
showAddPassControllerFromFile,
passes
}
11 changes: 8 additions & 3 deletions src/platform-specific.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @param callback A callback which will receive false
*/
function _canAddPasses(Module, callback) {
callback(false);
callback(false)
}

/**
Expand All @@ -12,15 +12,20 @@ function _canAddPasses(Module, callback) {
* @return Promise Always rejecting
*/
function _showAddPassControllerFromURL(Module, passURL) {
return Promise.reject("Android can't add passes");
return Promise.reject("Android can't add passes")
}

function _showAddPassControllerFromFile(Module, filepath) {
return Promise.reject("Android can't add passes");
return Promise.reject("Android can't add passes")
}

function _passes(Module, callback) {
callback("Android can't list passes", null)
}

module.exports = {
_canAddPasses,
_showAddPassControllerFromURL,
_showAddPassControllerFromFile,
_passes
}
11 changes: 8 additions & 3 deletions src/platform-specific.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
function _canAddPasses(Module, callback) {
Module.canAddPasses(result => {
callback(result);
callback(result)
})
}

Expand All @@ -15,15 +15,20 @@ function _canAddPasses(Module, callback) {
* @return Promise Passing a boolean
*/
function _showAddPassControllerFromURL(Module, passURL) {
return Module.showAddPassControllerFromURL(passURL);
return Module.showAddPassControllerFromURL(passURL)
}

function _showAddPassControllerFromFile(Module, filePath) {
return Module.showAddPassControllerFromFile(filePath);
return Module.showAddPassControllerFromFile(filePath)
}

function _passes(Module, callback) {
Module.passes(callback)
}

module.exports = {
_canAddPasses,
_showAddPassControllerFromURL,
_showAddPassControllerFromFile,
_passes
}