Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: QR isn't recognized #629

Merged
merged 2 commits into from
Dec 5, 2023
Merged
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
55 changes: 12 additions & 43 deletions DashWallet/Sources/UI/Payments/Receive/Models/DWBaseReceiveModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,40 +51,9 @@ static CGSize QRCodeSizeRequestAmount(void) {
}
}

static CGSize HoleSize(BOOL hasAmount) {
if (IS_IPAD) {
return CGSizeMake(84.0, 84.0); // 2 + 80(logo size) + 2
}
else if (IS_IPHONE_5_OR_LESS) {
return CGSizeMake(48.0, 48.0);
}
else {
if (hasAmount) {
return CGSizeMake(58.0, 58.0);
}
else {
return CGSizeMake(84.0, 84.0);
}
}
}

static CGSize const LOGO_SMALL_SIZE = {54.0, 54.0};

static BOOL ShouldResizeLogoToSmall(BOOL hasAmount) {
if (IS_IPAD) {
return NO;
}
if (IS_IPHONE_5_OR_LESS) {
return YES;
}
else {
return hasAmount;
}
}

@interface DWBaseReceiveModel ()

@property (readonly, nonatomic, assign) CGSize holeSize;
@property (readonly, nonatomic, assign) CGSize logoSize;

@end

Expand All @@ -106,7 +75,9 @@ - (instancetype)initWithAmount:(uint64_t)amount {
else {
_qrCodeSize = QRCodeSizeBasic();
}
_holeSize = HoleSize(hasAmount);

CGFloat logoSize = _qrCodeSize.height * 0.22;
_logoSize = CGSizeMake(logoSize, logoSize);
}
return self;
}
Expand All @@ -123,15 +94,13 @@ - (UIImage *)qrCodeImageWithRawQRImage:(UIImage *)rawQRImage hasAmount:(BOOL)has
#endif

const BOOL shouldDrawUser = username != nil;

if (ShouldResizeLogoToSmall(hasAmount)) {
if (shouldDrawUser) {
size = LOGO_SMALL_SIZE;
}
else {
overlayImage = [overlayImage dw_resize:LOGO_SMALL_SIZE
withInterpolationQuality:kCGInterpolationHigh];
}

if (shouldDrawUser) {
size = _logoSize;
}
else {
overlayImage = [overlayImage dw_resize:_logoSize
withInterpolationQuality:kCGInterpolationHigh];
}

if (shouldDrawUser) {
Expand Down Expand Up @@ -181,7 +150,7 @@ - (UIImage *)qrCodeImageWithRawQRImage:(UIImage *)rawQRImage hasAmount:(BOOL)has
}

UIImage *resizedImage = [rawQRImage dw_resize:self.qrCodeSize withInterpolationQuality:kCGInterpolationNone];
resizedImage = [resizedImage dw_imageByCuttingHoleInCenterWithSize:self.holeSize];
resizedImage = [resizedImage dw_imageByCuttingHoleInCenterWithSize:self.logoSize];

UIImage *qrCodeImage = [resizedImage dw_imageByMergingWithImage:overlayImage];

Expand Down
2 changes: 1 addition & 1 deletion Shared/Sources/UIImage+Utils.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ + (instancetype)dw_imageWithQRCodeData:(NSData *)data color:(CIColor *)color {
*filter = colorFilter;

[qrFilter setValue:data forKey:@"inputMessage"];
[qrFilter setValue:@"M" forKey:@"inputCorrectionLevel"];
[qrFilter setValue:@"Q" forKey:@"inputCorrectionLevel"];

if (color.alpha > DBL_EPSILON) {
[invertFilter setValue:qrFilter.outputImage forKey:@"inputImage"];
Expand Down